gforth
[Top][All Lists]
Advanced

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

Re: [gforth] words backwards


From: J. David Boyd
Subject: Re: [gforth] words backwards
Date: Fri, 19 May 2017 12:55:00 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (cygwin)

Bernd Paysan <address@hidden> writes:

> 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.


I'll have to brush up on my forth to figure out what this does.  Been too many
years since I did anything non-trivial with it.

Thanks for the code!




reply via email to

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