To view this discussion on the web visit https://groups.google.com/d/msgid/clojure/CAGokn9%2B1ZiFHBzuS_bwSyrx0DsM_ocu7dk844DnU-h5D3b9fzA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/clojure/CAGokn9%2BPgbiZxq-n7L%3DgLhqNB2z-OdCaTOx7uJA5zG2NavJLiQ%40mail.gmail.com.
I don't fully follow, I'm afraid...
I am applying a regular fn (e.g. `b/chash`) to a list of args
which can be 1-2 or 2-3 for (depending on which multi-method we're
talking about). The regular functions being applied, all provide
two arities for the respective invocations, so everything is
covered. I can literally copy/paste the apply expression into the
corresponding impl namespace and it works fine on the REPL.
As I understand it, protocol extensions are namespace-specific.
Otherwise, you couldn't extend the same protocol over the same
type in two different namespaces. So the only way to have
protocol extensions be useful outside the namespace they were
defined in, is to provide wrapper functions that delegate to the
protocol invocations in that ns, and call those instead.
Well, that's what I've done...it shouldn't matter where the
protocol is defined, right?
I've never encountered a "no such method" error so I'm not sure
how this could be playing a role here...
Hi Carlo thanks for you reply...
Quoted from clojure.org/reference/protocols:
Avoid the 'expression problem' by allowing independent extension of the set of types, protocols, and implementations of protocols on types, by different parties.
What you said about protocol extensions being global directly contradicts the above. You can definitely extend the same protocol on the same type in multiple namespaces (i.e. independent extension by different parties). If extensions were global that would be no different than monkey-patching, right?
Now, you ask why I need the protocol in the first place. That's
to provide polymorphism for bytes/chars/String input. The
multi-method is there to provide polymorphism for all the
different hashing implementations (bcrypt/scrypt/pbkdf2/argon2).
These two are completely separate and shouldn't interfere.
Ok, you might be right after all :(...
I called :impls on the protocol and it returns a map from Class
=> impls-map. So my understanding was not not quite
right...Yes, you can extend the same protocol in multiple
namespaces, but for distinct types only! So basically in
my case, i need to copy/paste the protocol in each impl namespace
separately.
Many thanks for your insight Carlo :)