General multimethod syntax

I apologize if the question is trivial, but some search engine does not lead me anywhere. What is the general syntax of defmulti and defmethod ? I can write simple multimethods, but I'm not sure where I can put docstring, before and after conditions, metadata, etc.

I'm really interested in ClojureScript more than in Clojure, so if there are differences between them, please tell me.

+7
source share
2 answers

In REPL, you can use the doc function to get function arguments and (most of the time) an explanation of the parameters. As for ClojureScript, these two functions are macros, which means that they expand at compile time and should behave just like normal Clojure. That is, while ClojureScript can process the code generated by the macro.

 user=> (doc defmulti) ------------------------- clojure.core/defmulti ([name docstring? attr-map? dispatch-fn & options]) Macro Creates a new multimethod with the associated dispatch function. The docstring and attribute-map are optional. Options are key-value pairs and may be one of: :default the default dispatch value, defaults to :default :hierarchy the isa? hierarchy to use for dispatching defaults to the global hierarchy nil user=> (doc defmethod) ------------------------- clojure.core/defmethod ([multifn dispatch-val & fn-tail]) Macro Creates and installs a new method of multimethod associated with dispatch-value. nil 
+7
source

In Clojuredocs : defmulti , defmethod .

If you do not find the examples detailed enough, you might consider adding your own (as soon as you get all your questions answered).

+4
source

All Articles