Marcin Borkowski <[email protected]> writes:
> Why?
Macro-expand the defun to get:
(defalias 'print-answer
#'(lambda nil
(message
"The answer is %s."
(forty-two))))
`lambda' is a macro that /quotes/ its body. Therefore, the body of
`defun' is not evaluated or expanded when it's defined.
You probably wanted something like this instead:
(macroexpand-all
'(lambda nil
(message
"The answer is %s."
(forty-two))))
;; =>
;; (function
;; (lambda nil
;; (message
;; "The answer is %s."
;; 42)))
Which could be wrapped in a new macro:
(defmacro defun-1 (name arglist &optional docstring &rest body)
(unless (stringp docstring)
(setq body
(if body
(cons docstring body)
docstring))
(setq docstring nil))
(list 'defun name arglist docstring (macroexpand-all body)))
The above seems to work, at least superficially:
(symbol-function
(defun-1 print-answer ()
(message "The answer is %s." (forty-two))))
;; =>
;; (lambda nil
;; (message
;; "The answer is %s."
;; 42))
By the way, it might be more appropriate to ask similar questions on
[email protected].
Oleh