1 - Forth Interest Group
1 - Forth Interest Group
1 - Forth Interest Group
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Get It Up<br />
I<br />
( Six One-Liners )<br />
( All definitions are in Standard <strong>Forth</strong> CORE and CORE-EXT words. )<br />
: ANEW >IN @ BL WORD FIND IF EXECUTE ELSE DROP THEN >IN ! MARKER ;<br />
: BOUNDS OVER + SWAP ; ( a n -- a+n a )<br />
: HAVING BL WORD FIND NIP O= IF POSTPONE \ THEN ; IMMEDIATE<br />
: LACKING BL WORD FIND NIP IF POSTPONE \ THEN ; IMMEDIATE<br />
.. S" ANEW NONCE : NONCE-DEF " EVALUATE ; IMMEDIATE<br />
. ..<br />
. t r S" ; NONCE-DEF NONCE " EVALUATE ; IMMEDIATE<br />
0 [ IF] COMMENT<br />
ANEW ( "name" -- )<br />
: ANEW ( "nameW -- )<br />
>IN @<br />
( >in)<br />
BL WORD FIND IF ( . exec-token)<br />
EXECUTE<br />
( >in)<br />
ELSE DROP THEN<br />
>IN ! ( 1<br />
MARKER<br />
If name is found, ANEW executes it. name is expected to<br />
have been defined by MARKER. name will forget itself and all<br />
definitions after it.<br />
ANEW then executes: MARKER name.<br />
This defines name again so you can redefine the definitions<br />
following it.<br />
Put ANEW marker-name at the beginning of your source<br />
files.<br />
BOUNDS ( a n -- a+n a )<br />
: BOUNDS OVER + SWAP ; ( a n -- a+n a )<br />
Note that [ IF] [ ELSE] [ THEN] should be kept balanced<br />
or, better, not used between [ IF] and [ THEN] . This restriction<br />
applies within comments and quoted strings as well.<br />
My personal convention is to use 0 [ IF1 or 1 [ IF] to<br />
select alternative code that should work, FALSE [ I FI to comment<br />
out code that doesn't work, and 0 [ IF] COMMENT to<br />
comment out non-code.<br />
I use \ to comment out code temporarily, and for other<br />
comments I don't want in the final source. That's why you<br />
don't see it much in my code.<br />
I use ( for stack state and other comments I want to keep<br />
in the final source.<br />
Adjust the arguments for a DO-loop. HAVING ( "namel' -- )<br />
0 [ IF] COMMENT<br />
Comment out documentationusing[ IF] [ ELSE] [ THEN] .<br />
Used:<br />
0 [ IF] COMMENT<br />
mumble mumble mumble<br />
[ THEN]<br />
: HAVING ( "name" -- )<br />
BL WORD FIND NIP O=<br />
IF POSTPONE \ THEN<br />
; IMMEDIATE<br />
If name is found, interpret the rest of the line; otherwise,<br />
skip the line. This is IMMEDIATE and can be used in a<br />
definition.<br />
26 <strong>Forth</strong> Dimensions XlWl