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, 9 months ago) by pazsan
Branches: MAIN
CVS tags: HEAD
Added quotations

    1: \ anonymous definitions in a definition
    2: 
    3: :noname  false :noname ;
    4: :noname  locals-wordlist last @ lastcfa @
    5:     postpone SCOPE postpone AHEAD  true  :noname ;
    6: interpret/compile: [:
    7: 
    8: : ;] ( compile-time: orig colon-sys -- ; run-time: -- xt )
    9:     POSTPONE ; >r IF
   10: 	]  postpone THEN  r> postpone ALiteral  postpone ENDSCOPE
   11: 	lastcfa ! last ! to locals-wordlist
   12:     ELSE  r>  THEN ( xt ) ; immediate
   13: 
   14: \\\
   15: : if-else ( ... f xt1 xt2 -- ... )
   16: \ Postscript-style if-else
   17:     rot IF
   18:        drop
   19:     ELSE
   20:        nip
   21:     THEN
   22:     execute ;
   23: 
   24: : test ( f -- )
   25:     [: ." true" ;]
   26:     [: ." false" ;]
   27:     if-else ;
   28:    
   29: 1 test cr \ writes "true"
   30: 0 test cr \ writes "false"

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