tags:

views:

79

answers:

3

In one namespace say "shapes" I have the following,

(derive ::rect ::shape)
(derive ::square ::rect)

now in shapes ns when I do,

(isa? ::square ::shape)

returns true,but in the namespace where I actually implement multimethods for drawing when I do,

(isa? ::square ::shape)

it returns false so even though I have correct multi method dispaches in place I get an error that says no dispatch function found.

Am I missing something? Implementing all types of shapes in one giant namespace seems pointless to me.

+1  A: 

Turns out, :: uses the current namespace so in order to use types from other namespaces you need to use fully qualified names such as :shapes/square.

Hamza Yerlikaya
A: 

You are correct, in your self-answer, that the :: operator locates something in the current namespace.

One interesting point is that the keywords can be namespaced in any namespace you like, even one which isn't declared in any file. So if your namespace tree is complicated, and you prefer :geometry/square, :geometry/circle, and the like, you can just use that.

Also, don't forget that derive, underive (don't use underive right now), isa? and related functions all let you use an independent hierarchy if you want. See http://stackoverflow.com/questions/3012088/when-and-how-should-custom-hierarchies-be-used-in-clojure

Rob Lachlan
A: 

You can use :: also with namespace aliases.

(ns some.other.package
  (:require [some.terr.ibly.long.package.name :as short]))

Now: ::short/abc will refer be the same as :some.terr.ibly.long.package.name/abc

kotarak