Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #25074

Re: Adding NTs or making XTs the only opaque Forth type

From anton@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups comp.lang.forth
Subject Re: Adding NTs or making XTs the only opaque Forth type
Date 2013-08-08 16:15 +0000
Organization Institut fuer Computersprachen, Technische Universitaet Wien
Message-ID <2013Aug8.181526@mips.complang.tuwien.ac.at> (permalink)
References (7 earlier) <3JGdncgvYYYK45_PnZ2dnUVZ_vOdnZ2d@supernews.com> <ktu0v9$4e0$1@dont-email.me> <W5qdnRb8j7fWFZ_PnZ2dnUVZ_u2dnZ2d@supernews.com> <2013Aug8.154536@mips.complang.tuwien.ac.at> <_pWdnXArIPOiJJ7PnZ2dnUVZ_sednZ2d@supernews.com>

Show all headers | View raw


Andrew Haley <andrew29@littlepinkcloud.invalid> writes:
>Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
>> "Previous"?  I assume you mean "next".
>
>No, I meant previous: the dictionary has always chained backwards in
>memory, and in creation order, in every Forth system I've ever seen.

That's also the case in many other uses of linked lists.  Still, the
pointer in the linked list is usually called the "next" pointer, and
the operation for following this pointer in an iterator is has "next"
in its name, not "previous".  That's probably because it's the next one
in the sequence you get when you walk the linked list.

>What would be far more sensible IMVHO would be an iterator, like this:
>
>   <walk ( wid - adr-of-walker)
>
>   walk> ( adr-of-walker -)
>
>   walk@ ( adr-of-walker - adr-of-prev-word)
>
>used like this:
>
>: count-words ( wid - n)   
>   <walk  0 swap
>   begin  dup walk@ while  swap 1+ swap  repeat
>   walk> ;

Interesting.  What happens if a THROW happens between <WALK and WALK>?

Anyway, if I compare this to the equivalent

: words-count ( x nt -- x' u ) drop 1+ true ;
: count-words ( wid -- n ) 0 ['] words-count rot traverse-wordlist ;

or the more modern

: count-words ( wid ) 0 [: drop 1+ true ;] rot traverse-wordlist ;

I find the TRAVERSE-WORDLIST variant less ugly (and that's not due to
the names).

Also, you argued with the efficiency of having to remove the stuff
from the data stack while performing the xt.  With WALK@ you cannot
keep the stuff on the data stack, either, and (unlike
TRAVERSE-WORDLIST) you cannot keep it on the return stack or in
locals.  It probably is not any more efficient on most systems.

Looking at the experience section of the RfD, a number of systems have
implemented a callback-based way to do such things, and such
interfaces have also been used elsewhere (e.g., in CATCH).

- anton
-- 
M. Anton Ertl  http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
     New standard: http://www.forth200x.org/forth200x.html
   EuroForth 2013: http://www.euroforth.org/ef13/

Back to comp.lang.forth | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Adding NTs or making XTs the only opaque Forth type "Alex McDonald" <blog@rivadpm.com> - 2013-08-05 21:11 +0100
  Re: Adding NTs or making XTs the only opaque Forth type anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-08-06 07:01 +0000
    Re: Adding NTs or making XTs the only opaque Forth type stephenXXX@mpeforth.com (Stephen Pelc) - 2013-08-06 16:10 +0000
      Re: Adding NTs or making XTs the only opaque Forth type Bernd Paysan <bernd.paysan@gmx.de> - 2013-08-06 22:22 +0200
  Re: Adding NTs or making XTs the only opaque Forth type stephenXXX@mpeforth.com (Stephen Pelc) - 2013-08-06 15:54 +0000
    Re: Adding NTs or making XTs the only opaque Forth type albert@spenarnc.xs4all.nl (Albert van der Horst) - 2013-08-06 17:43 +0000
      Re: Adding NTs or making XTs the only opaque Forth type "Elizabeth D. Rather" <erather@forth.com> - 2013-08-06 13:16 -1000
        Re: Adding NTs or making XTs the only opaque Forth type "Elizabeth D. Rather" <erather@forth.com> - 2013-08-06 13:55 -1000
        Re: Adding NTs or making XTs the only opaque Forth type Bernd Paysan <bernd.paysan@gmx.de> - 2013-08-07 02:33 +0200
          Re: Adding NTs or making XTs the only opaque Forth type "Alex McDonald" <blog@rivadpm.com> - 2013-08-07 16:29 +0100
            Re: Adding NTs or making XTs the only opaque Forth type Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-08-07 10:54 -0500
              Re: Adding NTs or making XTs the only opaque Forth type "Alex McDonald" <blog@rivadpm.com> - 2013-08-07 17:10 +0100
                Re: Adding NTs or making XTs the only opaque Forth type Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-08-07 12:06 -0500
                Re: Adding NTs or making XTs the only opaque Forth type "Alex McDonald" <blog@rivadpm.com> - 2013-08-07 18:43 +0100
                Re: Adding NTs or making XTs the only opaque Forth type Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-08-07 12:47 -0500
                Re: Adding NTs or making XTs the only opaque Forth type "Alex McDonald" <blog@rivadpm.com> - 2013-08-07 19:14 +0100
                Re: Adding NTs or making XTs the only opaque Forth type Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-08-07 15:13 -0500
                Re: Adding NTs or making XTs the only opaque Forth type "Alex McDonald" <blog@rivadpm.com> - 2013-08-07 23:09 +0100
                Re: Adding NTs or making XTs the only opaque Forth type anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-08-08 13:45 +0000
                Re: Adding NTs or making XTs the only opaque Forth type "Alex McDonald" <blog@rivadpm.com> - 2013-08-08 15:41 +0100
                Re: Adding NTs or making XTs the only opaque Forth type Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-08-08 10:29 -0500
                Re: Adding NTs or making XTs the only opaque Forth type anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-08-08 16:15 +0000
                Re: Adding NTs or making XTs the only opaque Forth type Bernd Paysan <bernd.paysan@gmx.de> - 2013-08-08 19:25 +0200
                Re: Adding NTs or making XTs the only opaque Forth type Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-08-08 14:05 -0500
                Re: Adding NTs or making XTs the only opaque Forth type anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-08-12 16:28 +0000
                Re: Adding NTs or making XTs the only opaque Forth type Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-08-12 12:44 -0500
                Re: Adding NTs or making XTs the only opaque Forth type anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-08-13 07:08 +0000
                Re: Adding NTs or making XTs the only opaque Forth type Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-08-13 03:40 -0500
                Re: Adding NTs or making XTs the only opaque Forth type anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-08-13 09:47 +0000
                Re: Adding NTs or making XTs the only opaque Forth type Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-08-13 05:55 -0500
                Re: Adding NTs or making XTs the only opaque Forth type anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2013-08-13 12:18 +0000
                Re: Adding NTs or making XTs the only opaque Forth type Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-08-13 10:32 -0500

csiph-web