From 4d6d66e391b4c1ac0d06d347556025c8014f11cd Mon Sep 17 00:00:00 2001 From: sforman Date: Fri, 11 Aug 2023 20:47:53 -0700 Subject: [PATCH] dip --- implementations/scheme-chicken/joy.scm | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/implementations/scheme-chicken/joy.scm b/implementations/scheme-chicken/joy.scm index 6142462..a9bdbf2 100644 --- a/implementations/scheme-chicken/joy.scm +++ b/implementations/scheme-chicken/joy.scm @@ -55,6 +55,7 @@ ((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? "i") (joy-i stack expression dict)) + ((is-it? "dip") (joy-dip stack expression dict)) ((hash-table-exists? dict symbol) (values stack (append (hash-table-ref dict symbol) expression) dict)) (else (error "Unknown word.")))) @@ -66,6 +67,11 @@ (define (joy-i 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) (string-intersperse (string-split str from #t) to)) @@ -139,6 +145,6 @@ (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) -- 2.11.0