ELSE
DROP
THEN
- AGAIN ;
+ AGAIN ; ( Yay! We now have comments! )
: UNTIL IMMEDIATE
' 0BRANCH ,
: MOD /MOD SWAP DROP ;
: NEG 0 SWAP - ;
-: FIB ( n -- Fn )
- 0 1 ( n a b )
- 0 ( n a b i )
- BEGIN
- ROT ( n i a b )
- DUP ROT + ( n i b a+b )
- ROT ROT ( n b a+b i )
-
- 1 + ( n b a+b i+1 )
- DUP 4 PICK = UNTIL
- DROP SWAP DROP SWAP DROP ; ( a+b )
-
: C,
HERE @ C!
HERE @ 1 +
: OVER ( a b -- a b a ) SWAP DUP ROT ;
+( An alternative comment syntax. Reads until the end of the line. )
+: \ IMMEDIATE
+ BEGIN
+ KEY
+ 10 = UNTIL ;
+
+\ So far, S" has only worked in immediate mode, which is backwards -- actually,
+\ the main use-case of this is as a compile-time word. Let's fix that.
+: S" IMMEDIATE
+ ' LITSTRING ,
+ HERE @ 0 C, \ We will put the length here
+ 0
+ BEGIN
+ 1 +
+ KEY DUP C,
+ 34 = UNTIL
+ \ Remove final "
+ HERE @ 1 - HERE !
+ 1 -
+ SWAP C! ;
+
( Compile the given string into the current word directly. )
: STORE-STRING ( str len -- )
BEGIN
1 - DUP 0 = UNTIL
DROP DROP ;
-S" HELLO-ADDR" CREATE
-S" Hello!" DUP ROT
-STORE-STRING
-: HELLO
- ' HELLO-ADDR LIT, TELL NEWLINE ;
+: NEWLINE 10 EMIT ;
+: SPACE 32 EMIT ;
-HELLO
+( Read a number from standard input. )
+: READ-NUMBER READ-WORD PARSE-NUMBER ;
-S" 10 FIB = " TELL
-10 FIB .U
-S" (Expected: 59)" TELL NEWLINE
+: RESTART S" Ready." TELL NEWLINE ;
+RESTART
-TERMINATE