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


Groups > comp.lang.forth > #14013

Re: Quotations revisited

From mhx@iae.nl (Marcel Hendrix)
Subject Re: Quotations revisited
Newsgroups comp.lang.forth
Message-ID <91951988968435@frunobulax.edu> (permalink)
Date 2012-07-15 16:08 +0200
References <86839188968435@frunobulax.edu>
Organization Wanadoo

Show all headers | View raw


mhx@iae.nl (Marcel Hendrix) wrote Re: Quotations revisited
[..]
> When [: and ;] switch to some private wordlist, EXIT and RECURSE can be used instead of 
> MY-EXIT and MYSELF. LOCALs are possible with a little extra effort. Was there anything else
> people wanted?

Although a private set of locals doesn't work, accessing outer locals
may work sufficiently close to what is intended:

: test-local ( -- )
	11 1 2 LOCALS| c b a |  
	CR a . b . c . 
	[: -1 TO a  CR a . b . c . ;] EXECUTE
	CR a b + c + . ;

FORTH> test-local
11 1 2
-1 1 2
2  ok

However, Knuth's Man-or-Boy test fails for calldepths > 3. (At that point 
the locals stack is empty, so apparently the recursion is supposed to make 
copies?)

-marcel

-- -------------------------------
DEFER A 
0 VALUE B  
:NONAME  0 ; =: F0
:NONAME  1 ; =: F1
:NONAME -1 ; =: Fn1

:NONAME ( k x1 x2 x3 x4 x5 -- n )
	LOCALS| x5 x4 x3 x2 x1  k |
	[: -1 +TO k   k B x1 x2 x3 x4  A ;] TO B
	k 0<= IF  x4 EXECUTE x5 EXECUTE +  ELSE  B EXECUTE  ENDIF ; IS A

1 value calldepth \ 0, 1, 2 .. 3 works, higher crash!
: ManOrBoy  CR calldepth ( #10 ) F1 Fn1 Fn1 F1 F0  A ;

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


Thread

Re: Auotations revisited Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-07-15 03:45 -0500
  Re: Quotations revisited mhx@iae.nl (Marcel Hendrix) - 2012-07-15 12:52 +0200
    Re: Quotations revisited mhx@iae.nl (Marcel Hendrix) - 2012-07-15 16:08 +0200
      Re: Quotations revisited Bernd Paysan <bernd.paysan@gmx.de> - 2012-07-15 17:08 +0200

csiph-web