aha!!! Protocols produce namespaced functions!!! I don't need to import
anything to core...I just need to call the functions with core/f since
the protocol exists in core...so simple!
sorry to bother you with something so trivial on a Sunday!
Jim
On 17/06/12 14:27, Jim - FooBar(); wrote:
Yes, importing the 2 records I have so far into the core namespace
where the protocols live solves the problem but I have to use dot
notation to call the methods even from within the definition of the
record. That is not what worries me the most though...
the real problem now is the fact that anyone else satisfying my
protocols will have to go into core and manually import his records.
This is not good at all...the core namespace has functions that will
work with any record that satisfies my 2 protocols...the consumer
simply should not touch it!
is there any way to add imports to a namespace after it has been
compiled? I'm at a loss now...help please!!!
Jim
On 17/06/12 14:08, Jim - FooBar(); wrote:
Hi guys,
everyone suggested that I don't need to use '.' when calling methods
from a record and in fact doing this gets rid of
reflection...However, now that I moved my records in different
namespaces than the protocols they satisfy it seems that I can no
longer do that! example follows:
(ns place1)
(defprotocol p1
method1
method2
......)
(defprotocol p2
method1
method2
......)
(ns place2)
(defrecord rec1
place1/p1
method1 [this] (.....)
method2 [this] (.....)
place1/p2
method1 [this] (.....)
method2 [this] (.....)
)
If all of the above are in the same namespace everything works just
fine - I don't need (.method1 rec1). If I put them in separate
namespaces (as shown above) I cannot do (method1 rec1) and even
though it will compile if I do (.method1 rec1) I will get an error
at runtime (field cannot be resolved or something)...
any ideas? I'm suspecting I need to :import all records (rec1 rec2
rec3) to place1 but it is not obvious why (at least to me!)...since
the protocol is there what is the problem dispatching to the
appropriate concrete class? Maybe because the actual concrete classes
(records) are in a different package from Java's perspective? But
then, if that is true, how can I let the consumer create his own
records which satisfy p1 and that can be used inside place1 without
touching it...
any pointers are greatly appreciated... :-)
Jim
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en