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

Re: Fun with comma...

From: <MSmith_at_ysi.com>
Date: Tue, 12 Nov 2002 09:21:32 -0500

Jos'h,

A better description of what you are trying to do would help. You may want
to study the linked list tools provided by SF, look up LINKS, >LINK and
<LINK.

I think you may be mistaken about the CREATE DOES> sequence of events.
Think about moving the "0 ," into the create clause like this:

: list: ( | name --) create 0 , does> something ;

This will initialize the first >next to zero and allocate its memory space.
The way you had it, the pointer was not initialized nor space allocated
until the first time name was executed. In fact, every time name is
executed, a 0 is compiled into the dictionary. I don't think this is what
you wanted to do. Watch HERE change as you execute name (paths or path
from below). With this in mind, do you now see what's happening in the u
and v example? Try using hex and dump.

hex ok
here . 46E880 ok
: list: create does> 0 , ; ok
here . 46E8C0 ok
here .s
46E8C0 <-Top ok
list: u ok
here .s
46E8C0 46E8D4 <-Top ok
list: v ok
here .s
46E8C0 46E8D4 46E8F4 <-Top ok
2drop ok
u ? 73697601 ok
v ? 0 ok
here .s
46E8C0 46E8FC <-Top ok
over - dump
  46E8C0 01 75 00 00 00 00 8B F7 FF FF FF 00 01 75 00 E8 .u...........u..
  46E8D0 D5 FF FF FF 01 76 69 73 74 3A 61 74 68 73 00 E8 .....vist:aths..
  46E8E0 C5 FF 00 00 00 00 CA FD FF FF FF 00 01 76 00 E8 .............v..
  46E8F0 B5 FF FF FF 00 00 00 00 00 00 00 00 ............
ok

Does the cell value at 46E8D4 look familiar?

You also need to decide what action you want name to have when it is
executed ( the something). Probably the default behavior like a variable,
that CREATE supplies. In fact, you may just want to use VARIABLE to start
your list.

Keep having fun,

Matt

                      Jos'h Fuller
                      <josh_at_dkp.com> To: "sftalk_at_forth.com" <sftalk_at_forth.com>
                      Sent by: cc:
                      sftalk-bounce_at_for Subject: [sftalk] Fun with comma...
                      th.com

                      11/11/02 05:17 PM
                      Please respond to
                      sftalk

Hi!

I'm setting up a simple linked list and it mostly works, but there seems
to be some problem with my initialization word.

Here's what a typical list might look like:

listheader >next data >next data >next data 0

The '>next' is a cell wide pointer to the next list entry. A zero instead
of a pointer terminates the list (until another value is added). The list
is defined in dictionary space, with the listheader built with create
does>:

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

I comma in '0' at the start for an empty list. However, if I try to create
multiple lists, the zero gets stepped on with a random value. This causes
me great unhappiness... Here's a quick run:

\ This works...
list: paths paths ? _0_
list: path paths ? _0_ path ? _0_
\ This doesn't work!
list: u
list: v
u ? _1936291329_ v ? _0_

This is... bizarre. Does anybody have any good ideas why creating one list
after another should go wierd like that? I've tried align-ing after
creating the list, but it doesn't seem to help. A single list by itself
works great.

Thanks!

Jos'h

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

----------------------------------------------------------------------
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 - 06:20:59 PST

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