Groups | Search | Server Info | Login | Register


Groups > comp.lang.forth > #134171

Re: 0 vs. translate-none

From peter <peter.noreply@tin.it>
Newsgroups comp.lang.forth
Subject Re: 0 vs. translate-none
Date 2025-09-19 19:39 +0200
Organization A noiseless patient Spider
Message-ID <20250919193929.00000ec0@tin.it> (permalink)
References <2025Sep17.185305@mips.complang.tuwien.ac.at> <mj4pa3Fe7v3U1@mid.individual.net> <2025Sep19.174547@mips.complang.tuwien.ac.at>

Show all headers | View raw


On Fri, 19 Sep 2025 15:45:47 GMT
anton@mips.complang.tuwien.ac.at (Anton Ertl) wrote:

> minforth <minforth@gmx.net> writes:
> >Am 17.09.2025 um 18:53 schrieb Anton Ertl:
> > > This posting is a more general reflection about designing types in
> > > Forth; it just uses recognizers as example.
> >
> >My gut feeling is that the standard Forth word zoo is already big
> >enough. Why should one define return types now, after more than half
> >a century of Forth's history? This is beyond me.
> 
> There is a discussion of 0 vs. R:FAIL in at least one of the versions
> of Matthias Trute's proposal, and a less thorough discussion of 0
> vs. NOTFOUND (=R:FAIL) in Bernd Paysan's proposal.  To see an
> advantage of TRANSLATE-NONE (=R:FAIL=NOTFOUND), consider:
> 
> : postpone ( "name" -- ) \ core
>     \g Compiles the compilation semantics of @i{name}.
>     parse-name rec-forth postponing ; immediate
> 
> REC-FORTH is the system recognizer, which produces a translation (a
> representation of the parsed word/number/etc. on the stack).  If the
> recognizer does not recognize "name", it produces TRANSLATE-NONE.
> 
> POSTPONING then performs the postpone action for the translation.  A
> straightforward implementation of translation tokens (the top cell of
> a translation)
> 
> create translate-...
> ' ... , \ interpreting
> ' ... , \ compiling
> ' ... , \ postponing
> 
> For TRANSLATE-NONE that would be:
> 
> : undefined-word #-13 throw ;
> 
> create translate-none
> ' undefined-word ,
> ' undefined-word ,
> ' undefined-word ,
> 
> And POSTPONING can then be implemented as:
> 
> : postponing ( translation -- )
>   2 cells + @ execute ;
> 
> However, if you use 0 instead of TRANSLATE-NONE, you would have to
> special-case that in POSTPONING:
> 
> : postponing ( translation -- )
>   dup 0= if -13 throw then
>   2 cells + @ execute ;
> 
> - anton

On lxf64 each individual recognizer returns 0 when no match was found.
The last recognizer to be tested is REC-ABORT (same as your REC-NONE). 
As a consequence REC-FORTH will never fail!
I organize the recognizers in a linked list. REC-ABORT is hard coded to always be last.

The interpret word thus becomes very simple

M: STATE-TRANSLATING ( trans --  )        \ get the right xt for the current state
    2 state @  + cells+ @ execute ;
    
: INTERPRET2   (  -- )		
	begin parse-name 
	dup while 
		forth-recognize state-translating
	repeat 2drop 
    ?stack ;

BR
Peter

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


Thread

0 vs. translate-none anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2025-09-17 16:53 +0000
  Re: 0 vs. translate-none minforth <minforth@gmx.net> - 2025-09-19 12:24 +0200
    Re: 0 vs. translate-none anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2025-09-19 15:45 +0000
      Re: 0 vs. translate-none peter <peter.noreply@tin.it> - 2025-09-19 19:39 +0200
        Re: 0 vs. translate-none anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2025-09-20 07:25 +0000
          Re: 0 vs. translate-none peter <peter.noreply@tin.it> - 2025-09-20 10:34 +0200
            Re: 0 vs. translate-none anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2025-09-20 16:08 +0000
              Re: 0 vs. translate-none peter <peter.noreply@tin.it> - 2025-09-20 19:08 +0200
                Re: 0 vs. translate-none anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2025-09-20 17:57 +0000
                Re: 0 vs. translate-none peter <peter.noreply@tin.it> - 2025-09-20 20:55 +0200
                Re: 0 vs. translate-none anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2025-09-21 12:33 +0000
                Re: 0 vs. translate-none peter <peter.noreply@tin.it> - 2025-09-21 18:39 +0200
                Re: 0 vs. translate-none anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2025-09-23 17:25 +0000
                Re: 0 vs. translate-none peter <peter.noreply@tin.it> - 2025-09-23 22:25 +0200
                Re: 0 vs. translate-none albert@spenarnc.xs4all.nl - 2025-09-24 01:15 +0200
                Re: 0 vs. translate-none anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2025-09-24 06:26 +0000
            Re: 0 vs. translate-none albert@spenarnc.xs4all.nl - 2025-09-21 10:37 +0200
              Re: 0 vs. translate-none minforth <minforth@gmx.net> - 2025-09-21 13:56 +0200
                Re: 0 vs. translate-none albert@spenarnc.xs4all.nl - 2025-09-21 14:44 +0200
                Re: 0 vs. translate-none minforth <minforth@gmx.net> - 2025-09-21 17:46 +0200
                Re: 0 vs. translate-none anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2025-09-23 17:23 +0000
                Re: 0 vs. translate-none minforth <minforth@gmx.net> - 2025-09-23 22:38 +0200
                Re: 0 vs. translate-none anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2025-09-24 06:38 +0000
                Re: 0 vs. translate-none minforth <minforth@gmx.net> - 2025-09-24 09:39 +0200
                Re: 0 vs. translate-none albert@spenarnc.xs4all.nl - 2025-09-24 10:28 +0200
                Re: 0 vs. translate-none minforth <minforth@gmx.net> - 2025-09-24 10:44 +0200
                Re: 0 vs. translate-none minforth <minforth@gmx.net> - 2025-09-24 10:36 +0200
              Re: 0 vs. translate-none anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2025-09-21 12:50 +0000
                Re: 0 vs. translate-none albert@spenarnc.xs4all.nl - 2025-09-21 21:39 +0200
                Re: 0 vs. translate-none anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2025-09-22 06:56 +0000
                Re: 0 vs. translate-none albert@spenarnc.xs4all.nl - 2025-09-22 10:09 +0200
                Re: 0 vs. translate-none anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2025-09-22 08:39 +0000
                Re: 0 vs. translate-none albert@spenarnc.xs4all.nl - 2025-09-22 23:03 +0200
                Re: 0 vs. translate-none anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2025-09-23 17:00 +0000
                Re: 0 vs. translate-none albert@spenarnc.xs4all.nl - 2025-09-24 00:41 +0200
                Re: 0 vs. translate-none dxf <dxforth@gmail.com> - 2025-09-24 13:57 +1000
                Re: 0 vs. translate-none anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2025-09-24 06:45 +0000
                Re: 0 vs. translate-none dxf <dxforth@gmail.com> - 2025-09-25 15:22 +1000
                Re: 0 vs. translate-none anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2025-09-25 06:36 +0000
                Re: 0 vs. translate-none albert@spenarnc.xs4all.nl - 2025-09-25 13:00 +0200
                Re: 0 vs. translate-none anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2025-09-29 05:54 +0000
                Re: 0 vs. translate-none albert@spenarnc.xs4all.nl - 2025-09-29 11:03 +0200
                Re: 0 vs. translate-none anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2025-09-29 16:27 +0000
                Re: 0 vs. translate-none dxf <dxforth@gmail.com> - 2025-09-26 10:56 +1000
                Re: 0 vs. translate-none Hans Bezemer <the.beez.speaks@gmail.com> - 2025-09-26 17:09 +0200
                Re: 0 vs. translate-none dxf <dxforth@gmail.com> - 2025-09-29 00:42 +1000
                Re: 0 vs. translate-none Hans Bezemer <the.beez.speaks@gmail.com> - 2025-09-30 18:15 +0200
                Re: 0 vs. translate-none dxf <dxforth@gmail.com> - 2025-10-01 14:10 +1000
                Re: 0 vs. translate-none Hans Bezemer <the.beez.speaks@gmail.com> - 2025-10-02 15:48 +0200
  Re: 0 vs. translate-none Ruvim <ruvim.pinka@gmail.com> - 2025-09-26 02:19 +0400
    Re: 0 vs. translate-none Ruvim <ruvim.pinka@gmail.com> - 2025-09-27 13:43 +0400

csiph-web