Annotation of gforth/quotations.fs, revision 1.3

1.1       pazsan      1: \ anonymous definitions in a definition
                      2: 
                      3: :noname  false :noname ;
                      4: :noname  locals-wordlist last @ lastcfa @
1.2       pazsan      5:     postpone AHEAD
1.3     ! anton       6:     locals-list @ locals-list off
        !             7:     postpone SCOPE
        !             8:     true  :noname  ;
1.2       pazsan      9: interpret/compile: [: ( -- quotation-sys )
                     10: \G Starts a quotation
1.1       pazsan     11: 
1.2       pazsan     12: : ;] ( compile-time: quotation-sys -- ; run-time: -- xt )
                     13:     \g ends a quotation
1.1       pazsan     14:     POSTPONE ; >r IF
1.2       pazsan     15:        ]  postpone ENDSCOPE
1.3     ! anton      16:        locals-list !
1.2       pazsan     17:        postpone THEN
1.1       pazsan     18:        lastcfa ! last ! to locals-wordlist
1.2       pazsan     19:        r> postpone ALiteral
1.1       pazsan     20:     ELSE  r>  THEN ( xt ) ; immediate
                     21: 
1.2       pazsan     22: 0 [IF] \ tests
1.1       pazsan     23: : if-else ( ... f xt1 xt2 -- ... )
                     24: \ Postscript-style if-else
                     25:     rot IF
                     26:        drop
                     27:     ELSE
                     28:        nip
                     29:     THEN
                     30:     execute ;
                     31: 
                     32: : test ( f -- )
                     33:     [: ." true" ;]
                     34:     [: ." false" ;]
                     35:     if-else ;
                     36:    
                     37: 1 test cr \ writes "true"
                     38: 0 test cr \ writes "false"
1.2       pazsan     39: 
                     40: \ locals within quotations
                     41: 
                     42: : foo { a b } a b
                     43:     [: { x y } x y + ;] execute . a . b . ;
                     44: 2 3 foo
                     45: [THEN]

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