e9910edd311c

Add `multiple-value-bind*`
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Wed, 14 Dec 2016 17:44:19 -0500
parents fd8c40ec26ee
children 6f1c9878ddbe
branches/tags (none)
files DOCUMENTATION.markdown losh.lisp package.lisp

Changes

--- a/DOCUMENTATION.markdown	Wed Dec 14 12:16:13 2016 -0500
+++ b/DOCUMENTATION.markdown	Wed Dec 14 17:44:19 2016 -0500
@@ -184,6 +184,27 @@
 
   
 
+### `MULTIPLE-VALUE-BIND*` (macro)
+
+    (MULTIPLE-VALUE-BIND* BINDINGS
+      &BODY
+      BODY)
+
+Bind each pair in `bindings` with `multiple-value-bind` sequentially.
+
+  Example:
+
+    (multiple-value-bind*
+        (((a b) (values 0 1))
+         ((c) (values (1+ b)))
+      (list a b c))
+    ; =>
+    ; (0 1 2)
+
+  From https://github.com/phoe/m-m-v-b
+
+  
+
 ### `RECURSIVELY` (macro)
 
     (RECURSIVELY BINDINGS
--- a/losh.lisp	Wed Dec 14 12:16:13 2016 -0500
+++ b/losh.lisp	Wed Dec 14 17:44:19 2016 -0500
@@ -471,6 +471,27 @@
          (when ,symbol
            (when-let* ,remaining-bindings ,@body))))))
 
+(defmacro multiple-value-bind* (bindings &body body)
+  "Bind each pair in `bindings` with `multiple-value-bind` sequentially.
+
+  Example:
+
+    (multiple-value-bind*
+        (((a b) (values 0 1))
+         ((c) (values (1+ b)))
+      (list a b c))
+    ; =>
+    ; (0 1 2)
+
+  From https://github.com/phoe/m-m-v-b
+
+  "
+  (if (null bindings)
+    `(progn ,@body)
+    (destructuring-bind ((vars form) &rest bindings) bindings
+      `(multiple-value-bind ,vars ,form
+         (multiple-value-bind* ,bindings ,@body)))))
+
 
 ;;;; Mutation -----------------------------------------------------------------
 (defun build-zap (place expr env)
--- a/package.lisp	Wed Dec 14 12:16:13 2016 -0500
+++ b/package.lisp	Wed Dec 14 17:44:19 2016 -0500
@@ -76,7 +76,8 @@
     :if-found
     :gathering
     :gather
-    :when-let*))
+    :when-let*
+    :multiple-value-bind*))
 
 (defpackage :losh.mutation
   (:documentation "Utilities for mutating places in-place.")