2012-03-31 2 views
7

질문이 사소한 경우 사과 드리지만 일부 인터넷 검색은 나를 이끌지 않습니다. defmultidefmethod의 일반 구문은 무엇입니까? 간단한 다중 메소드를 작성할 수는 있지만 어디에서 docstring, 사전 및 사후 조건, 메타 데이터 등을 넣을 수 있는지 잘 모르겠습니다.멀티 메소드의 일반적인 구문

실제로 ClojureScript보다 Clojure에 더 관심이 많으므로 둘 사이에 차이가 있다면 알려주십시오.

답변

7

REPL에서는 doc 함수를 사용하여 함수 인수를 얻고 옵션 설명을 얻을 수 있습니다. ClojureScript의 경우이 두 함수는 매크로이므로 컴파일시 확장되고 일반 Clojure에서와 똑같이 동작해야합니다. 즉, ClojureScript가 매크로가 생성하는 코드를 처리 할 수있는 한. Clojuredocs에서

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 
4

: defmulti, defmethod.

충분히 자세한 예제를 찾지 못했다면 자신의 질문을 추가 할 수 있습니다 (모든 질문에 대한 답변을 얻은 후에).