Remove global stack, dict.
Pass them through the recursive loop instead.
This commit is contained in:
parent
937f6bfce5
commit
4df31667b6
|
|
@ -248,26 +248,18 @@
|
||||||
|
|
||||||
(define (prompt) (display "joy? ") (read-line))
|
(define (prompt) (display "joy? ") (read-line))
|
||||||
|
|
||||||
(define DICTIONARY (initialize))
|
(define (main-loop stack0 dict0)
|
||||||
(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)))
|
(let ((text (prompt)))
|
||||||
(if (not (string=? text ""))
|
(if (not (eof-object? text))
|
||||||
((print (doit text)) (main-loop))
|
(receive (stack dict) (joy stack0 (text->expression text) dict0)
|
||||||
(else))))
|
(print (joy-expression->string (reverse stack)))
|
||||||
|
(main-loop stack dict))
|
||||||
|
(print))))
|
||||||
|
|
||||||
(define (joy-trace stack expression)
|
(define (joy-trace stack expression)
|
||||||
(print (conc (joy-expression->string (reverse stack)) " . " (joy-expression->string expression))))
|
(print (conc (joy-expression->string (reverse stack)) " . " (joy-expression->string expression))))
|
||||||
|
|
||||||
(main-loop)
|
(main-loop '() (initialize))
|
||||||
|
|
||||||
|
|
||||||
;(display (doit "5 [] cons [4] concat first"))
|
;(display (doit "5 [] cons [4] concat first"))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue