4
(:use function)
을 할 수는 있지만 멀티 메쏘드를 사용하려면 어떻게해야할까요?클로저에서 어떻게 멀티 메소드가 필요합니까?
(:use function)
을 할 수는 있지만 멀티 메쏘드를 사용하려면 어떻게해야할까요?클로저에서 어떻게 멀티 메소드가 필요합니까?
멀티 메소드는 함수와 같은 방식으로 다른 네임 스페이스에서 사용됩니다.
당신은 COM에 다음과 같은 경우/예/foo.clj 파일 COM/예에서
(ns com.example.foo)
(defn f [x]
(* x x))
(defmulti m first)
(defmethod m :a [coll]
(map inc (rest coll)))
/당신은 같은 방법으로 F와 m를 모두 사용할 수 있습니다 bar.clj :
(ns com.example.bar
(:use [com.example.foo :only [f m]]))
(defn g []
(println (f 5)) ; Call the function
(println (m [:a 1 2 3]))) ; Call the multimethod
;; You can also define new cases for the multimethod defined in foo
;; which are then available everywhere m is
(defmethod m :b [coll]
(map dec (rest coll)))
이 질문에 대한 답변을 보내주십시오.