This commit is contained in:
sforman 2023-08-11 20:45:25 -07:00
parent ae7d854330
commit c3e6c1be90
1 changed files with 4 additions and 1 deletions

View File

@ -54,6 +54,7 @@
((is-it? "stack") (values (cons stack stack) expression dict)) ((is-it? "stack") (values (cons stack stack) expression dict))
((is-it? "swaack") (values (cons (cdr stack) (car stack)) expression dict)) ((is-it? "swaack") (values (cons (cdr stack) (car stack)) expression dict))
((is-it? "swap") (values (cons (cadr stack) (cons (car stack) (cddr stack))) expression dict)) ((is-it? "swap") (values (cons (cadr stack) (cons (car stack) (cddr stack))) expression dict))
((is-it? "i") (joy-i stack expression dict))
((hash-table-exists? dict symbol) ((hash-table-exists? dict symbol)
(values stack (append (hash-table-ref dict symbol) expression) dict)) (values stack (append (hash-table-ref dict symbol) expression) dict))
(else (error "Unknown word.")))) (else (error "Unknown word."))))
@ -62,6 +63,8 @@
(define (joy-sub stack) (cons (- (cadr stack) (car stack)) (cddr stack))) (define (joy-sub stack) (cons (- (cadr stack) (car stack)) (cddr stack)))
(define (joy-mul stack) (cons (* (cadr stack) (car stack)) (cddr stack))) (define (joy-mul stack) (cons (* (cadr stack) (car stack)) (cddr stack)))
(define (joy-i stack expression dict)
(values (cdr stack) (append (car stack) expression) dict))
(define (string-replace str from to) (define (string-replace str from to)
@ -136,6 +139,6 @@
(hash-table-set! dict (car def_list) (cdr def_list)))) (hash-table-set! dict (car def_list) (cdr def_list))))
(display (doit "1 2 3 [4 5 6] swaack pop swap stack")) (display (doit "1 2 3 [4 5 6] i pop swap stack"))
(newline) (newline)