From 596a7a21ebf4151e89a3d50025b698cb7d00c313 Mon Sep 17 00:00:00 2001 From: sforman Date: Sat, 12 Aug 2023 13:03:42 -0700 Subject: [PATCH] A crude main loop. I know there are better ways to do this, but I don't know what they are yet. Maybe a "do" loop? Anyway, this works, although it doesn't catch errors yet. --- implementations/scheme-chicken/joy.scm | 29 +++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/implementations/scheme-chicken/joy.scm b/implementations/scheme-chicken/joy.scm index 26cf920..f6804f3 100644 --- a/implementations/scheme-chicken/joy.scm +++ b/implementations/scheme-chicken/joy.scm @@ -171,11 +171,6 @@ (define (joy-expression->string expr) (string-intersperse (map joy-term->string expr) " ")) -(define (doit text) - (receive (stack _dict) - (joy '() (text->expression text) (initialize)) - (joy-expression->string stack))) - (define (initialize) (load-defs (make-hash-table string=? string-hash))) @@ -188,9 +183,29 @@ (let ((def_list (text->expression def))) (hash-table-set! dict (car def_list) (cdr def_list)))) -(display (doit "5 [] cons [4] concat first")) +(define (prompt) (display "joy? ") (read-line)) + +(define DICTIONARY (initialize)) +(define STACK '()) + +(define (doit text) + (receive (stack dict) (joy STACK (text->expression text) DICTIONARY) + (set! DICTIONARY dict) + (set! STACK stack) + (joy-expression->string (reverse stack)))) + +(define (main-loop) + (let ((text (prompt))) + (if (not (string=? text "")) + ((print (doit text)) (main-loop)) + (else)))) + +(main-loop) + + +;(display (doit "5 [] cons [4] concat first")) ;(display (doit "5 down_to_zero")) ;(display (doit "1 2 true [4 5 false] loop <")) -(newline) +;(newline)