File:  [gforth] / gforth / quotations.fs
Revision 1.1: download - view: text, annotated - select for diffs
Fri Dec 16 21:18:01 2011 UTC (9 years, 7 months ago) by pazsan
Branches: MAIN
CVS tags: HEAD
Added quotations

\ anonymous definitions in a definition

:noname  false :noname ;
:noname  locals-wordlist last @ lastcfa @
    postpone SCOPE postpone AHEAD  true  :noname ;
interpret/compile: [:

: ;] ( compile-time: orig colon-sys -- ; run-time: -- xt )
    POSTPONE ; >r IF
	]  postpone THEN  r> postpone ALiteral  postpone ENDSCOPE
	lastcfa ! last ! to locals-wordlist
    ELSE  r>  THEN ( xt ) ; immediate

\\\
: if-else ( ... f xt1 xt2 -- ... )
\ Postscript-style if-else
    rot IF
       drop
    ELSE
       nip
    THEN
    execute ;

: test ( f -- )
    [: ." true" ;]
    [: ." false" ;]
    if-else ;
   
1 test cr \ writes "true"
0 test cr \ writes "false"

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>