2016-07-12 4 views
2

멀티 메소드와 구현을 별도의 파일로 정의하려고합니다.다른 이름 공간에있는 별도의 파일로 멀티 메소드 구현

(ns thing.a.e 
    (:require thing.a.b :as test)) 
. 
. 
. 
(test/foo "hello") 
: 나는 이런 식으로 뭔가를 정의 1

(ns thing.a.b) 
(defn dispatch-fn [x] x) 
(defmulti foo dispatch-fn) 

내가 메서드를 호출하고 때 파일이

(ns thing.a.b.c 
    (:require [thing.a.b :refer [foo]]) 
(defmethod foo "hello" [s] s) 
(defmethod foo "goodbye" [s] "TATA") 

과 주요 파일에 파일에서 : 그것은 이런 식입니다

내가 이것을 할 때 나는 예외를 말하는 것을 얻는다 "No method in multimethod 'foo'for dispatch value: hello

내가 뭘 잘못 했니? 또는 멀티 메소드의 구현을 별도의 파일로 정의 할 수 없습니까?

답변

4

가능합니다. 문제는 thing.a.b.c 네임 스페이스가로드되어 있지 않기 때문입니다. 사용하기 전에로드해야합니다.

이 올바른 예입니다

(ns thing.a.e 
    (:require 
    [thing.a.b.c] ; Here all your defmethods loaded 
    [thing.a.b :as test])) 

(test/foo "hello")