-
-
Save ruv/8999398a106a362579586b464b13ce98 to your computer and use it in GitHub Desktop.
Dual-semantics words via the immediacy mechanism
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\ 2019-09-24 ruv | |
\ 2019-10-09 | |
\ Implementation of some dual-semantics words | |
\ as STATE-dependent immediate words. | |
\ The following dual-semantics words are implemented here: | |
\ S" TO IS ACTION-OF | |
\ and the counterparts they depend on: | |
\ VALUE DEFER DEFER@ DEFER! | |
\ NB: this "TO" cannot be applied to the local variables | |
\ NB: 2VALUE and FVALUE can be easy implemeted too, | |
\ with a bit modification of TO and VALUE | |
\ see-also: An implementation of POSPONE via FIND -- https://git.io/J30D6 | |
\ Some well known but yet non standard words | |
[undefined] lit, [if] : lit, postpone literal ; [then] | |
[undefined] slit, [if] : slit, postpone sliteral ; [then] | |
: xt, compile, ; \ ensure default interpretation semantics | |
\ Token translators | |
: tt-xt ( i*x xt -- j*x ) state @ if xt, else execute then ; | |
: tt-lit ( x -- x| ) state @ if lit, then ; | |
: tt-slit ( c-addr u -- | c-addr u -- c-addr2 u ) state @ if slit, then ; | |
\ Note: separate buffering of the string literal in interpretation state | |
\ is absent for the sake of this example simplicity. | |
\ An initial action for a deferred word | |
: error-np ( -- ) -21 throw ; \ Not Provided, "unsupported operation" | |
\ Implementing of: 'to', 'is', 'action-of', 's"' | |
: value create , does> @ ; | |
: defer create ['] error-np , does> @ execute ; | |
: defer@ >body @ ; | |
: defer! >body ! ; | |
: is ' >body tt-lit ['] ! tt-xt ; immediate | |
: to [ ' is xt, ] ; immediate \ synonym; don't use postpone | |
: action-of ' >body tt-lit ['] @ tt-xt ; immediate | |
: s" [char] " parse tt-slit ; immediate | |
\ end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A short URL: https://git.io/Jsnb8
See-also:
POSPONE
viaFIND
: https://git.io/J30D6