A start on simple functions.

I'm sure there's a cooler way to do this, but it works.  (This is my
first Scheme code.)
This commit is contained in:
sforman 2023-08-04 10:38:52 -07:00
parent 8cc15a745f
commit 7c9663594b
1 changed files with 9 additions and 2 deletions

View File

@ -10,7 +10,14 @@
(joy (cons (car expression) stack) (cdr expression) dict)))) (joy (cons (car expression) stack) (cdr expression) dict))))
(define (joy-eval symbol stack expression dict) (define (joy-eval symbol stack expression dict)
(values (cons symbol stack) expression dict)) (define (is-it? name) (string=? symbol name))
(cond
((is-it? "+") (values (joy-add stack) expression dict))
((is-it? "-") (values (joy-sub stack) expression dict))
(else (values (cons symbol stack) expression dict))))
(define (joy-add stack) (cons (+ (cadr stack) (car stack)) (cddr stack)))
(define (joy-sub stack) (cons (- (cadr stack) (car stack)) (cddr stack)))
(define (string-replace str from to) (define (string-replace str from to)
@ -72,6 +79,6 @@
(joy '() (text-to-expression text) '()) (joy '() (text-to-expression text) '())
(joy-expression-to-string stack))) (joy-expression-to-string stack)))
(display (doit "ab cd [[ ]] 234 [true] false")) (display (doit "ab cd [[ ]] 23 4 - [true] false"))
(newline) (newline)