aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2019-03-09 11:33:00 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2019-03-09 11:33:00 +0100
commit1b9e850aec5edfc5608046aad3b9a0def2f80a43 (patch)
tree3b093890d3c65615d2c3b880ad8543757ac61e5b
parentVarious small fixes. (diff)
downloadcalp-1b9e850aec5edfc5608046aad3b9a0def2f80a43.tar.gz
calp-1b9e850aec5edfc5608046aad3b9a0def2f80a43.tar.xz
Extend let* macro with SRFI-71.
-rw-r--r--util.scm22
1 files changed, 16 insertions, 6 deletions
diff --git a/util.scm b/util.scm
index 7456c67f..30b87a2e 100644
--- a/util.scm
+++ b/util.scm
@@ -66,12 +66,13 @@
#t name fields))
;;; Replace let* with a version that can bind from lists.
+;;; Also supports SRFI-71 (extended let-syntax for multiple values)
;;; Example:
-;; (let* ((i 10)
-;; ((a b) (list (+ i 1)
-;; (+ i 2))))
-;; (list i a b))
-;; => (10 11 12)
+;; (let* ([a b (values 1 2)] ; SRFI-71
+;; [(c d) '(3 4)] ; Let-list (mine)
+;; [e 5]) ; Regular
+;; (list e d c b a))
+;; ;; => (5 4 3 2 1)
;;;
(define-syntax let*
@@ -93,4 +94,13 @@
[(_ ((k value) rest ...) body ...)
(let ((k value))
(let* (rest ...)
- body ...))]))
+ body ...))]
+
+ ;; SRFI-71 let-values
+ [(_ ((k k* ... values) rest ...) body ...)
+ (call-with-values (lambda () values)
+ (lambda (k k* ...)
+ (let* (rest ...)
+ body ...)))]
+
+ ))