[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [gforth] words backwards

From: David Boyd CW
Subject: Re: [gforth] words backwards
Date: Fri, 19 May 2017 16:47:52 +0000

-----Original Message-----
From: Bernd Paysan [mailto:address@hidden 
Sent: Friday, May 19, 2017 12:24 PM
To: address@hidden
Cc: Dennis Ruffer <address@hidden>; David Boyd CW <address@hidden>
Subject: [EXTERNAL] Re: [gforth] words backwards

Am Freitag, 19. Mai 2017, 18:09:30 CEST schrieb Dennis Ruffer:
> Since Forth dictionaries are typically, singly linked lists, it would 
> take memory and time to reverse the order.

Yes, but on a desktop system, we actually have that memory. And time is even 
less important.  This does it, by converting the list into an array and then 
stepping backwards through that array:

Variable words[]

: words ( -- )
    [: words[] dup $[]# swap $[] ! true ;] context @ traverse-wordlist
    source nip 1+ words[] $@ bounds cell- swap cell- U-DO
        I @ .word
    cell -LOOP drop
    words[] $free ;

Works in the current development system.

Bernd Paysan
"If you want it done right, you have to do it yourself"
net2o ID: kQusJzA;address@hidden(dQ*

Thanks so much, exactly what I was looking for.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]