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


Groups > comp.lang.forth > #14009

Re: Quotations revisited

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

Show all headers | View raw


Re: Andrew Haley <andrew29@littlepinkcloud.invalid> writes Re: Quotations revisited

> Marcel Hendrix <mhx@iae.nl> wrote:
>> Recently, the subject of quotations popped up again and I remembered 
>> an unfinished project.
[..] 
> My first version of quotations for SwiftForth was much like this.
> Then someone pointed out that RECURSE had to work.  Then somone
> pointed out that locals had to work...

0 value dict     : MY-EXIT -R [ -OPT ] ;
: [: ( -- )      POSTPONE AHEAD  HERE TO dict  -OPT POSTPONE >R ; immediate 
: ;] ( -- xt )   POSTPONE MY-EXIT  POSTPONE THEN  dict POSTPONE LITERAL ; IMMEDIATE
: MYSELF ( -- )  dict POSTPONE LITERAL POSTPONE EXECUTE ; immediate

: test-recursion ( flag -- u )
	#10 SWAP
	   IF  [: ( n1 -- n2 ) DUP 1 > IF  DUP 1-  MYSELF  SWAP 2-  MYSELF +  ENDIF ;] \ fib
	 ELSE  [: ( n1 -- n2 ) DUP     IF  DUP 1-  MYSELF  SWAP *   ELSE  1+  ENDIF ;] \ fac
	ENDIF  EXECUTE . ;

FORTH> true test-recursion 55  ok
FORTH> false test-recursion 3628800  ok

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?

-marcel

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