From 8df8634e39282e9bb6e12104a1be93486644a40f Mon Sep 17 00:00:00 2001 From: sforman Date: Fri, 11 Aug 2023 21:27:41 -0700 Subject: [PATCH] loop --- implementations/scheme-chicken/joy.scm | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/implementations/scheme-chicken/joy.scm b/implementations/scheme-chicken/joy.scm index 85b5402..065f66a 100644 --- a/implementations/scheme-chicken/joy.scm +++ b/implementations/scheme-chicken/joy.scm @@ -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)) @@ -86,6 +87,13 @@ (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)) @@ -159,6 +167,6 @@ (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)