在 Clojure 中,如何在不使用特殊点符号的情况下调用对象的方法?

In Clojure, how can I call a method on an object without using special dot notations?

在 Clojure 中,我总是使用 .符号即

(.methCall obj args)

但是有没有一种方法可以在没有点符号的情况下调用该方法?例如。当我转

时相当于“应用”之类的东西
(f x y) 

进入

(apply f x y)

?

我想这样做是为了编写一个可以将方法名称作为参数之一并在对象上调用它的宏。

dot special form

例如

user=> (. (bigint 42) toString)
"42"

您使用的表格在member access下,是一个快捷方式:

user=> (macroexpand '(.toString (bigint 42)))
(. (bigint 42) toString)

以上文档说明了以下扩展:

(.instanceMember instance args*) ==> (. instance instanceMember args*)
(.instanceMember Classname args*) ==> (. (identity Classname) instanceMember args*)
(.-instanceField instance) ==> (. instance -instanceField)
(Classname/staticMethod args*) ==> (. Classname staticMethod args*)
Classname/staticField ==> (. Classname staticField)