开发者

Can I use Clojure multimethods only on Java classes?

I am a bit confused about whether I can only use clojure multimethods on clojure structures represented by Java classes, or can I base mu开发者_JAVA技巧ltimethods to dispatch on structs or other properties?


It is very common to build multimethods that dispatch on the class of the first or only argument. In this case the "class" may be a Java class, a record (defrecord generates a Java class), or even an internal Clojure type like ISeq.

You can also dispatch on an arbitrary function of the args passed to the function. For example, you could compute a function and dispatch on a keyword if you wanted.


You can dispatch multimethods on an arbitrary function of the arguments (that function gets passed in as the second argument to defmulti. http://clojure.org/multimethods provides more details.


You can make your multimethods dispatch on any function you choose.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜