Fixed >scaled in example.
[forth.jl.git] / src / lib.4th
index 51f0b97..ea4e7de 100644 (file)
@@ -1,6 +1,6 @@
 : / /MOD SWAP DROP ;
 : MOD /MOD DROP ;
-: */ * / ;
+: */ -ROT * SWAP / ;
 
 : NEGATE 0 SWAP - ;
 
 
 : I RSP@ 3 - @ ;
 
-: LEAVE? IMMEDIATE
+: J RSP@ 6 - @ ;
+
+: ?LEAVE IMMEDIATE
         ' 0BRANCH , 13 ,
         ' R> , ' RDROP , ' RDROP ,
         ' LIT ,  HERE @ 7 + , ' DUP , ' -ROT , ' - , ' SWAP , ' ! ,
 
 : LEAVE IMMEDIATE
         ' LIT , -1 ,
-        [COMPILE] LEAVE?
+        [COMPILE] ?LEAVE
 ;
 
-: LOOP+ IMMEDIATE
+: +LOOP IMMEDIATE
         ' R> , ' SWAP , ' R> , ' SWAP , ' R> , ' SWAP , ' + , ' 2DUP , ' - ,
         ' SWAP , ' >R , ' SWAP , ' >R , ' SWAP , ' >R ,
         ' 0<= , ' 0BRANCH ,
 
 : LOOP IMMEDIATE
         ' LIT , 1 ,
-        [COMPILE] LOOP+
+        [COMPILE] +LOOP
 ;
 
 \ COMMENTS ----------------------------------------------------------------------
         @               ( and fetch )
 ;
 
-
 ( With the looping constructs, we can now write SPACES, which writes n spaces to stdout. )
 : SPACES        ( n -- )
-        BEGIN
-                DUP 0>          ( while n > 0 )
-        WHILE
-                SPACE           ( print a space )
-                1-              ( until we count down to 0 )
-        REPEAT
-        DROP
+        0 DO
+            SPACE
+        LOOP
 ;
 
 ( Standard words for manipulating BASE. )
         THEN
 ;
 
+: ROLL ( x_u x_u-1... x_0 u -- x_u-1 ... x_0 x_u )
+        1+ DUP PICK SWAP    ( x_u x_u-1 ... x_0 x_u u+1 )
+        PSP@ 1- SWAP - PSP@ 2- SWAP
+        DO
+            i 1+ @ i !
+        LOOP
+        SWAP DROP
+;
+
+include ../examples/mandelbrot.4th