更新时间:2023-02-18 18:48:52
警告:仅适用于文字序列!(参见 Mihał 的评论)
Warning: works only for literal sequables! (see Mihał's comment)
试试这个宏:
(defmacro instantiate [klass values]
`(new ~klass ~@values))
如果你扩展它:
(macroexpand '(实例化用户 ["John" "john@example.com" "Dreamland"]))
你会得到这个:
(新用户John"john@example.com"Dreamland")
这基本上就是您所需要的.
which is basically what you need.
您可以使用它来实例化其他记录类型或 Java 类.基本上,这只是一个类构造函数,它接受一个参数序列而不是多个参数.
And you can use it for instantiating other record types, or Java classes. Basically, this is just a class constructor that takes a one sequence of parameters instead of many parameters.