From 1b9e850aec5edfc5608046aad3b9a0def2f80a43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Sat, 9 Mar 2019 11:33:00 +0100 Subject: Extend let* macro with SRFI-71. --- util.scm | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'util.scm') 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 ...)))] + + )) -- cgit v1.2.3