Adding random dalek generation
[lambdamundo.git] / utils.lisp
blob7d363e82ef534d6890536f16688abc549a149354
2 (in-package :lambdamundo)
4 (defmacro with-gensyms ((&rest names) &body body)
5 `(let ,(loop for n in names collect `(,n (gensym)))
6 ,@body))
8 (defmacro once-only ((&rest names) &body body)
9 (let ((gensyms (loop for n in names collect (gensym))))
10 `(let (,@(loop for g in gensyms collect `(,g (gensym))))
11 `(let (,,@(loop for g in gensyms for n in names collect ``(,,g ,,n)))
12 ,(let (,@(loop for n in names for g in gensyms collect `(,n ,g)))
13 ,@body)))))
15 (defmacro when-funcall (x &rest parameters)
16 "If the first argument is not NIL, assume it's a function and call
17 it with the supplied parameters."
18 (with-gensyms (fun)
19 `(let ((,fun ,x))
20 (when ,fun
21 (funcall ,fun ,@parameters)))))