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.
This commit is contained in:
sforman 2023-08-12 13:03:42 -07:00
parent eafa3d45ac
commit 596a7a21eb
1 changed files with 22 additions and 7 deletions

View File

@ -171,11 +171,6 @@
(define (joy-expression->string expr) (define (joy-expression->string expr)
(string-intersperse (map joy-term->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) (define (initialize)
(load-defs (make-hash-table string=? string-hash))) (load-defs (make-hash-table string=? string-hash)))
@ -188,9 +183,29 @@
(let ((def_list (text->expression def))) (let ((def_list (text->expression def)))
(hash-table-set! dict (car def_list) (cdr def_list)))) (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 "5 down_to_zero"))
;(display (doit "1 2 true [4 5 false] loop <")) ;(display (doit "1 2 true [4 5 false] loop <"))
(newline) ;(newline)