[parenscript-devel] Extended DESTRUCTURING-BIND to allow NIL bindings

Daniel Gackle danielgackle at gmail.com
Sat May 9 05:05:57 UTC 2009


I extended DESTRUCTURING-BIND to allow NIL bindings to indicate a place
should be ignored, the way that CL LOOP does. The fact that CL's
DESTRUCTURING-BIND doesn't do that, but instead forces the user to make up a
name and declare it ignored, is a perennial annoyance. Patch is below.

Daniel


>From 5d8b60256a70788c0930724e9d3501551a5e1559 Mon Sep 17 00:00:00 2001
From: Daniel Gackle <danielgackle at gmail.com>
Date: Fri, 8 May 2009 14:59:05 -0600
Subject: [PATCH 1/2] Extended DESTRUCTURING-BIND to allow NIL bindings to
indicate a place should be ignored, the way that CL LOOP does.

---
 src/lib/ps-macro-lib.lisp |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/lib/ps-macro-lib.lisp b/src/lib/ps-macro-lib.lisp
index e6c32be..85a55ea 100644
--- a/src/lib/ps-macro-lib.lisp
+++ b/src/lib/ps-macro-lib.lisp
@@ -137,10 +137,13 @@
     `((@ ,fn :apply) this ,arglist)))

 (defpsmacro destructuring-bind (vars expr &body body)
-  ;; a simple implementation that for now only supports flat lists
+  ;; a simple implementation that for now only supports flat lists,
+  ;; but does allow NIL bindings to indicate ignore (a la LOOP)
   (let* ((arr (if (complex-js-expr? expr) (ps-gensym) expr))
          (n -1)
          (bindings
           (append (unless (equal arr expr) `((,arr ,expr)))
-                  (mapcar (lambda (var) `(,var (aref ,arr ,(incf n))))
vars))))
+                  (mapcan (lambda (var)
+                            (incf n)
+                            (when var `((,var (aref ,arr ,n))))) vars))))
     `(let ,bindings , at body)))
-- 
1.6.1
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/parenscript-devel/attachments/20090508/8bd39347/attachment.html>


More information about the parenscript-devel mailing list