Extended DESTRUCTURING-BIND to allow NIL bindings to indicate a place should be ignor...
authorDaniel Gackle <danielgackle@gmail.com>
Fri, 8 May 2009 20:59:05 +0000 (14:59 -0600)
committerVladimir Sedach <vsedach@gmail.com>
Sat, 9 May 2009 23:34:53 +0000 (17:34 -0600)
src/lib/ps-macro-lib.lisp

index e3341e0..cb413cf 100644 (file)
     `((@ ,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 ,@body)))