Exported 'loop' from Parenscript package, moved utility functions to src/utils.lisp.
[clinton/parenscript.git] / src / utils.lisp
index 4e2066a..6d04137 100644 (file)
@@ -104,3 +104,14 @@ SOMEGLOBAL."
   (cond ((null x) acc)
         ((atom x) (cons x acc))
         (t (flatten (car x) (flatten (cdr x) acc)))))
+
+(defmacro aif (test-form then-form &optional else-form)
+  `(let ((it ,test-form))
+     (if it ,then-form ,else-form)))
+
+(defmacro once-only ((&rest names) &body body) ;; the version from PCL
+  (let ((gensyms (loop for nil in names collect (gensym))))
+    `(let (,@(loop for g in gensyms collect `(,g (gensym))))
+       `(let (,,@(loop for g in gensyms for n in names collect ``(,,g ,,n)))
+          ,(let (,@(loop for n in names for g in gensyms collect `(,n ,g)))
+                ,@body)))))