From 54097ac074e07da98d38f85c15edd53d01289b82 Mon Sep 17 00:00:00 2001 From: Nathan Braswell Date: Wed, 23 Feb 2022 00:56:46 -0500 Subject: [PATCH] Port the let+ macro from http://www.phyast.pitt.edu/~micheles/scheme/scheme15.html over mostly, and it works in both Chez and Chicken! Will massage some more to get it to be the same as our previous dlet, but it is working! --- partial_eval.scm | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/partial_eval.scm b/partial_eval.scm index 9161dee..d230bb5 100644 --- a/partial_eval.scm +++ b/partial_eval.scm @@ -31,6 +31,21 @@ ((_ name params body) (rec name (lambda params body))))) +; Based off of http://www.phyast.pitt.edu/~micheles/scheme/scheme15.html +; many thanks! +(define-syntax dlet + (syntax-rules () + ((_ expr) expr) + ((_ (() lst) expr) expr) + ((_ ((arg1 arg2 ...) lst) expr) + (let ((ls lst)) + (dlet (arg1 (car ls)) + (dlet ((arg2 ...) (cdr ls)) expr)))) + ((_ (name value) expr) (let ((name value)) expr)) + ((_ (name value) (n v) ... expr) (dlet (name value) (dlet (n v) ... expr))) +)) + + (let* ( ; In Chez scheme it's (arithmetic-shift bitwise-arithmetic-shift) @@ -133,6 +148,14 @@ (print (str 1 2 3 (array 1 23 4) "a" "B")) ;(print (dlet ( (x 2) ((a b) '(1 2)) (((i i2) i3) '((5 6) 7)) ) (+ x a b i i2 i3))) + (print (dlet 1)) + (print (dlet (x 1) x)) + (print "first destructure test") + (print (dlet ((x) '(1)) x)) + (print (dlet ((x y) (list 1 2)) x)) + (print (dlet ((x y) (list 1 2)) y)) + (print (dlet ((x y) (list 1 2)) (+ x y))) + (print (dlet ((x y) (list 1 2)) ((e f g) (list 4 5 6)) (+ x y e f g))) (print (array 1 2 3)) (print (command-line-arguments))