OSDN Git Service

loop
authorsforman <sforman@hushmail.com>
Sat, 12 Aug 2023 04:27:41 +0000 (21:27 -0700)
committersforman <sforman@hushmail.com>
Sat, 12 Aug 2023 04:27:41 +0000 (21:27 -0700)
implementations/scheme-chicken/joy.scm

index 85b5402..065f66a 100644 (file)
@@ -59,6 +59,7 @@
     ((is-it? "i") (joy-i stack expression dict))
     ((is-it? "dip") (joy-dip stack expression dict))
     ((is-it? "branch") (joy-branch stack expression dict))
+    ((is-it? "loop") (joy-loop stack expression dict))
 
     ((hash-table-exists? dict symbol)
       (values stack (append (hash-table-ref dict symbol) expression) dict))
             (append (if flag true_body false_body) expression)
             dict)))
 
+(define (joy-loop stack expression dict)
+  (let ((flag (cadr stack))
+        (body (car stack)))
+    (values (cddr stack)
+            (if flag (append body (cons body (cons "loop" expression))) expression)
+            dict)))
+
 
 (define (string-replace str from to)
   (string-intersperse (string-split str from #t) to))
     (hash-table-set! dict (car def_list) (cdr def_list))))
 
 
-(display (doit "true [4] [5] branch false  [4] [5] branch + sqr"))
+(display (doit "1 2 true [4 5 false] loop"))
 (newline)