This commit is contained in:
sforman 2023-08-11 20:47:53 -07:00
parent c3e6c1be90
commit 4d6d66e391
1 changed files with 7 additions and 1 deletions

View File

@ -55,6 +55,7 @@
((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)) ((is-it? "i") (joy-i stack expression dict))
((is-it? "dip") (joy-dip 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."))))
@ -66,6 +67,11 @@
(define (joy-i stack expression dict) (define (joy-i stack expression dict)
(values (cdr stack) (append (car stack) expression) dict)) (values (cdr stack) (append (car stack) expression) dict))
(define (joy-dip stack expression dict)
(values (cddr stack)
(append (car stack) (cons (cadr stack) expression))
dict))
(define (string-replace str from to) (define (string-replace str from to)
(string-intersperse (string-split str from #t) to)) (string-intersperse (string-split str from #t) to))
@ -139,6 +145,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] i pop swap stack")) (display (doit "1 2 3 [4 5 6] dip"))
(newline) (newline)