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


Groups > comp.lang.forth > #9734

Re: RfD: TRAVERSE-WORDLIST v4

From anton@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups comp.lang.forth
Subject Re: RfD: TRAVERSE-WORDLIST v4
Date 2012-02-28 17:18 +0000
Organization Institut fuer Computersprachen, Technische Universitaet Wien
Message-ID <2012Feb28.181840@mips.complang.tuwien.ac.at> (permalink)
References <3a561970-391e-4f30-8dc8-049d5942f159@gi10g2000vbb.googlegroups.com>

Show all headers | View raw


Alex McDonald <blog@rivadpm.com> writes:
>RfD: traverse-wordlist

Looks mostly fine to me.  Here are some comments on some details.

>x*i is zero or more stack parameters that are agreed on by the caller
>of TRAVERSE-WORDLIST and xt-node. xt-node is free to modify them but
>must return the same number of parameters on the stack.

Leave this restriction away.  While it is usually a good idea to
program this way, there are exceptions to this rule.  On the
implementation side, I don't see any benefit from this restriction
(i.e., I expect all implementations to work even for unbalanced stack
effects of xt-node.

>  : WORDS-COUNT ( x nt -- x' u ) DROP 1+ TRUE ;
>  0 ' WORDS-COUNT WID TRAVERSE-WORDLIST  . ( count of nodes visited)
>
>returns x', where x' is a count of the total number of nodes in the
>wordlist WID.

This example actually prints the number instead of returning it.

>NT>STRING    ( nt -- addr count ) "name-to-string"
>NT>SEMANTICS ( nt -- xte xtc )    "name-to-semantics"
>
>NT>STRING returns the string addr count, the definition name of the
>word represented by nt. Case is dependent on the case-sensitivity of
>the Forth system (see /DPANS 3.3.1.2 Definition names/).

You should specify the life time of the string, unless you want it to
have unlimited life.

Why?  If all systems have the string in that form in the word header,
NT>STRING can just return that.  But I am worried that there are still
descendents of fig-Forth, which set the top bit in the last character;
such a system (or any other with a funny string representation) would
have to construct the proper string in a buffer, and that buffer would
have a limited life time.  So, are there any systems that store the
name in a way that requires NT>STRING to construct the string in a
buffer?

>NT>SEMANTICS returns two xts (execution tokens) as discussed in
>/DPANS 3.4.3 Semantics/. xte represents the execution semantics of
>the definition; xtc represents the compilation semantics. Where a
>definition has no execution semantics (for example, IF), xte may be 0
>(zero); the same is true for xtc if there are no compilation
>semantics.

This will be pretty expensive to implement in Gforth: we would need to
construct another word representing the compilation semantics for all
words with default compilation semantics (i.e., most words).

Also, what about interpretation semantics?  E.g., S" has no execution
semantics, but the FILE wordset version has interpretation semantics.

>"Invisible" or non-FINDable words can also be created by using the
>non-standard and system specific words such as HIDE or SMUDGE, or can
>be created but not FINDable until they are REVEALed. Whether these
>nodes are visited or not is undefined.

That follows anyway from the fact that the standard says nothing about
non-standard code.

>3. Experience
>-------------
>
>The wordlist traversal functionality is available through very
>similar words in
>
>  Win32Forth    VOC-ITERATE
>  VFX           WalkWordList
>  iForth        doWORDS
>  ciForth       FOR-WORDS
>  lxf/ntf       WALK-WORDLIST
>
>System specific words that mimic the functionality of NT>STRING and
>NT>SEMANTICS are available on a number of these systems;
>
>  Win32Forth   NT>STRING is >NAME

Gforth has:

|`name>int'       nt - xt         gforth       "name-to-int"
|   xt represents the interpretation semantics of the word nt. If nt has
|no interpretation semantics (i.e. is `compile-only'), xt is the
|execution token for `ticking-compile-only-error', which performs `-2048
|throw'.
|
|`name?int'       nt - xt         gforth       "name-question-int"
|   Like `name>int', but perform `-2048 throw' if nt has no
|interpretation semantics.
|
|`name>comp'       nt - w xt         gforth       "name-to-comp"
|   w xt is the compilation token for the word nt.
|
|`name>string'       nt - addr count         gforth       "name-to-string"
|   addr count is the name of the word represented by nt.

- 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 2011: http://www.euroforth.org/ef11/

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


Thread

RfD: TRAVERSE-WORDLIST v4 Alex McDonald <blog@rivadpm.com> - 2012-02-28 05:14 -0800
  Re: RfD: TRAVERSE-WORDLIST v4 anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-02-28 17:18 +0000
    Re: RfD: TRAVERSE-WORDLIST v4 Alex McDonald <blog@rivadpm.com> - 2012-02-28 13:54 -0800
      Re: RfD: TRAVERSE-WORDLIST v4 "Elizabeth D. Rather" <erather@forth.com> - 2012-02-28 12:16 -1000
        Re: RfD: TRAVERSE-WORDLIST v4 anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-02-29 15:42 +0000
          Re: RfD: TRAVERSE-WORDLIST v4 "Elizabeth D. Rather" <erather@forth.com> - 2012-02-29 06:49 -1000
          Re: RfD: TRAVERSE-WORDLIST v4 "Peter Knaggs" <pjk@bcs.org.uk> - 2012-02-29 20:05 +0000
      Re: RfD: TRAVERSE-WORDLIST v4 BruceMcF <agila61@netscape.net> - 2012-02-28 14:40 -0800
        Re: RfD: TRAVERSE-WORDLIST v4 anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-02-29 15:47 +0000
          Re: RfD: TRAVERSE-WORDLIST v4 BruceMcF <agila61@netscape.net> - 2012-02-29 08:13 -0800
    Re: RfD: TRAVERSE-WORDLIST v4 "Peter Knaggs" <pjk@bcs.org.uk> - 2012-02-29 20:07 +0000
  Re: RfD: TRAVERSE-WORDLIST v4 Albert van der Horst <albert@spenarnc.xs4all.nl> - 2012-02-29 11:27 +0000
  Re: RfD: TRAVERSE-WORDLIST v4 "Peter Knaggs" <pjk@bcs.org.uk> - 2012-02-29 20:20 +0000
    Re: RfD: TRAVERSE-WORDLIST v4 BruceMcF <agila61@netscape.net> - 2012-02-29 16:44 -0800
      Re: RfD: TRAVERSE-WORDLIST v4 "Peter Knaggs" <pjk@bcs.org.uk> - 2012-03-01 08:45 +0000
        Re: RfD: TRAVERSE-WORDLIST v4 BruceMcF <agila61@netscape.net> - 2012-03-01 16:15 -0800
          Re: RfD: TRAVERSE-WORDLIST v4 "Peter Knaggs" <pjk@bcs.org.uk> - 2012-03-02 09:58 +0000
            Re: RfD: TRAVERSE-WORDLIST v4 BruceMcF <agila61@netscape.net> - 2012-03-02 22:37 -0800
  Re: RfD: TRAVERSE-WORDLIST v4 Alex McDonald <blog@rivadpm.com> - 2012-03-04 14:03 -0800
    Re: RfD: TRAVERSE-WORDLIST v4 "Peter Knaggs" <pjk@bcs.org.uk> - 2012-03-05 13:20 +0000
    Re: RfD: TRAVERSE-WORDLIST v4 anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-03-05 14:18 +0000
  Re: RfD: TRAVERSE-WORDLIST v4 Alex McDonald <blog@rivadpm.com> - 2012-03-27 15:23 -0700

csiph-web