programming tools for Windows applications development
  Home  |   SwiftForth Archive  |   SwiftX Archive  |

Let me try that one again...

From: Jos'h Fuller <josh_at_dkp.com>
Date: Tue, 12 Nov 2002 11:53:55 -0500 (EST)

Oh boy, do I feel _silly_! Let me try that one again...

The proper way to do it (or at least a way that worked(!)) is:

: list: ( | name --) create 0 , 0 , ;

I realized sometime after that I sent the post that 'does>' does its thing
as the new word is invoked, not as it was created... Not to mention that
'create' would do what I needed.

So that's sorted. For your consideration (and amusement!) I include a
short demo below...

Thanks!

Jos'h

-------------------------snip!---------------------------------

\ ll.f
\ Linked list demo
 \ Use 'grep ^\\\\ ll.f' to generate documentation.
\ jrlf 2002-11-11
\
\ This is a simple linked list data structure. It uses two cells per link,
\ the first points to the next link, the second to the link payload data.
\ The next pointer is zero if it's the last link in the chain. The links
\ are held in the dictionary. Anything you can get an address for can be
\ linked -- including another linked list! See below for an example.
\
empty

\ list: ( | name --) Create a new linked list.
: list: create 0 , 0 , ;

\ end ( list -- a) Find the end of the linked list.
: end begin dup @ 0 <> while @ repeat ;

\ >info ( list -- a) Return the address of the link payload data.
: >info cell+ @ ;

\ add ( a list --) Add a new entry to the list.
: add end dup here swap ! cell+ ! 0 , 0 , ;

\ add" ( list | text" --) Add a string to the list. For convenience only...
: add" here ," swap add ;

\ len ( list -- n) Return the length of the list.
: len
   0 begin over @ 0 <> while
   1+ swap @ swap repeat swap drop ;

\
\ Example:
\ Here is a list of lists of various Forth logos. Silly, but you get the idea.

list: logos
   list: accepted accepted logos add
      accepted add" San-serif Capitals"
      accepted add" Stylized 4"
      accepted add" Bird in Flight"
   list: rejected rejected logos add
      rejected add" Anime Ninja Warrior Girl"
      rejected add" ForthMan"

\ list? ( list --) Enumerate list contents.
: list? begin dup @ 0 <> while dup >info count type ." , " @ repeat drop ;

cr cr
.( Proposed Totemic Graphics for the Forth Language) cr cr
3 spaces .( Accepted:) cr 6 spaces logos >info list? cr
3 spaces .( Rejected:) cr 6 spaces logos @ >info list? cr

----------------------------------------------------------------------
sftalk_at_forth.com The SwiftForth programming discussion email list
To unsubscribe, send subject "unsubscribe sftalk" to listar_at_forth.com
For help with listar commands, send subject "help" to listar_at_forth.com
Archives are located at http://www.forth.com/sftalk -- check them out!
Search the archives! Visit http://www.forth.com/search for details.
Received on Tue Nov 12 2002 - 08:53:20 PST

This archive was generated by hypermail 2.2.0 : Fri Nov 21 2008 - 03:04:25 PST