;;; Lisp apprentice's wet dream: funcallable macros.
;;; Probable newbie usage example: (reduce #`and '(t t t nil t t))
;;; Two implementations are provided: one trivial using eval, and one ;;; that memoizes compiled functions.
(defun funcallable-macro (name) (lambda (&rest args) (eval (cons name args))))
(defun funcallable-macro (name) (let ((table (make-hash-table :test #'eql))) (lambda (&rest args) (let ((n (length args))) (apply (or (gethash n table) (setf (gethash n table) (make-funcallable-macro-function name n))) args)))))
(defun make-funcallable-macro-function (name n) (let ((args nil)) (dotimes (i n) (push (gensym) args)) (compile nil `(lambda ,args ,(macroexpand `(,name ,@args))))))
(set-dispatch-macro-character ## #` (lambda (s c n) `(funcallable-macro ',(read s t nil t))))