# 帶有可選參數的宏，用於檢查是否定義了可選參數？

(defmacro iλ (x)
(lambda() (interactive) ,x))

(defmacro iλd (x y)
(lambda() ,x (interactive) ,y))

(global-set-key (kbd "") (iλ (message "hello lambdas")))
(global-set-key (kbd "") (iλd "Func Docu" (message "hello lambda with docus")))


 (defmacro iλ (x &optional y)   ;y is optional parameter:
if x & y are defined:
(lambda() ,x (interactive) ,y))
else if only x is defined:
(lambda() (interactive) ,y)
)


[edit solution] As per Malabarba's answer below, I now use the clever bit of code:

(defmacro iλ (x &rest y)
(if (and (stringp x) y)
(lambda() ,x (interactive) ,@y)
(lambda() (interactive) ,x ,@y)))
;Example usage:
(global-set-key (kbd "") (iλ "A message that prints a hello" (message "hello 2")))
(global-set-key (kbd "") (iλ  (message "hello 1")))


## 最佳答案

(defmacro iλ (x &optional y)
(if (and (stringp x) y)
(lambda() ,x (interactive) ,y))
(lambda() (interactive) ,x ,y)))


(defmacro iλ (x &rest y)
(if (and (stringp x) y)
(lambda() ,x (interactive) ,@y)
(lambda() (interactive) ,x ,@y)))


(defmacro iλ (&rest body)
(let ((x (macroexp-parse-body body)))
(lambda() ,@(car x) (interactive)
,@(cdr x))))
`