如何在带有 N 个参数的 LISP 中定义宏?

Kev*_*vin 0 lisp common-lisp

我正在尝试在 LISP 中定义一个宏,例如在不同文件中的这个调用函数

(set_name name My name is Timmy)

(set_name occupation I am a doctor )

(defmacro set_name (list)
   (print list)
)
Run Code Online (Sandbox Code Playgroud)

Bar*_*mar 6

就像在普通函数中一样,用于&rest将所有剩余的参数收集到一个列表中。

(defmacro set_name (name &rest list) 
  `(setq ,name ',list))
(set_name occupation I am a doctor)
(print occupation)
Run Code Online (Sandbox Code Playgroud)

这将打印 (I AM A DOCTOR)

您需要,list在扩展中引用,这样它就不会尝试将所有符号评估为变量。