[Top][All Lists]

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

Re: [gforth] words backwards

From: Bernd Paysan
Subject: Re: [gforth] words backwards
Date: Fri, 19 May 2017 18:24:13 +0200

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*

reply via email to

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