(defmacro fbind (bindings &body body) "Binds the function objects in the function namespace." (loop for (name function) in bindings for let-gensym = (gensym) for arg-gensym = (gensym) collect `(,let-gensym ,function) into let-bindings collect `(,name (&rest ,arg-gensym) (apply ,let-gensym ,arg-gensym)) into flet-bindings finally (return `(let ,let-bindings (flet ,flet-bindings ,@body))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defparameter *global* 0) (fbind ((foo (progn (incf *global*) #'print)) (bar #'1+)) (foo (bar 42)) (foo (bar 42)) (foo (bar 42))) (LET ((#:G1204591 (PROGN (INCF *GLOBAL*) #'PRINT)) (#:G1204593 #'1+)) (FLET ((FOO (&REST #:G1204592) (APPLY #:G1204591 #:G1204592)) (BAR (&REST #:G1204594) (APPLY #:G1204593 #:G1204594))) (FOO (BAR 42)) (FOO (BAR 42)) (FOO (BAR 42)))) *global* ;=> 1