referring to protocol methods defined in another namespace will not accept fully qualified name

96 views
Skip to first unread message

Jonathan Leonard

unread,
Sep 16, 2015, 12:28:50 AM9/16/15
to ClojureScript
Per the documentation on defprotocol for Clojure itself, such a reference (e.g., in a reify of a protocol defined in a separate file/namespace) does require a fully qualified name (and will not accept unqualified name).

Using the fully qualified name in ClojureScript produces the following error:
Caused by: clojure.lang.ExceptionInfo: set! target must be a field or a symbol naming a var at line 7 test/graphql-tlc/core.cljs {:file "test/graphql-tlc/core.cljs", :line 7, :column 3, :tag :cljs/analysis-error}

Is this a known/expected deviation from Clojure proper?

Thanks!

David Nolen

unread,
Sep 16, 2015, 12:39:30 AM9/16/15
to clojur...@googlegroups.com
Please provide a minimal example of the issue. Thanks!

David


--
Note that posts from new members are moderated - please be patient with your first post.
---
You received this message because you are subscribed to the Google Groups "ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojurescrip...@googlegroups.com.
To post to this group, send email to clojur...@googlegroups.com.
Visit this group at http://groups.google.com/group/clojurescript.

Jonathan Leonard

unread,
Sep 16, 2015, 1:08:54 AM9/16/15
to clojur...@googlegroups.com
src/proj/one.cljs
=======
(ns proj.one)

(defprotocol Proc
   (meth [this]))

src/proj/two.cljs
=======
(def ProcImpl
  (reify one/Proc
    (meth [_] nil)))  ;; works

Replace last line of two.cljs with:
    (one/meth [_] nil)))  ;; does NOT work

—Jonathan



You received this message because you are subscribed to a topic in the Google Groups "ClojureScript" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/clojurescript/Rgnn_KPSY_o/unsubscribe.
To unsubscribe from this group and all its topics, send an email to clojurescrip...@googlegroups.com.

Jonathan Leonard

unread,
Sep 16, 2015, 1:10:29 AM9/16/15
to clojur...@googlegroups.com
Oops, src/proj/two.cljs was  supposed to have (of course):

(ns proj.two)

at the top of the file. [Fixed below].


On Sep 15, 2015, at 10:08 PM, Jonathan Leonard <joha...@gmail.com> wrote:

src/proj/one.cljs
=======
(ns proj.one)

(defprotocol Proc
   (meth [this]))

src/proj/two.cljs
=======
(ns proj.two)

Jonathan Leonard

unread,
Sep 16, 2015, 1:15:35 AM9/16/15
to ClojureScript
Here is also a more complete example:
https://github.com/johanatan/graphql-type-lang-compiler/blob/master/test/graphql-tlc/core.cljs#L10-L13

Just thinking about it: one diff between this project and the minimal repro provided before is that the protocol is defined in 'src' and implemented in 'test' (but that really shouldn't matter if I understand what's going on with cljsbuild).

--Jonathan

David Nolen

unread,
Sep 16, 2015, 8:40:51 AM9/16/15
to clojur...@googlegroups.com
On Wed, Sep 16, 2015 at 12:28 AM, Jonathan Leonard <joha...@gmail.com> wrote:
Per the documentation on defprotocol for Clojure itself, such a reference (e.g., in a reify of a protocol defined in a separate file/namespace) does require a fully qualified name (and will not accept unqualified name).

As far as I know this is not the case. If the documentation says so it is incorrect with respect to the implementation and code in the wild, https://github.com/clojure/core.async/blob/master/src/main/clojure/clojure/core/async/impl/channels.clj#L67
 
Using the fully qualified name in ClojureScript produces the following error:
Caused by: clojure.lang.ExceptionInfo: set! target must be a field or a symbol naming a var at line 7 test/graphql-tlc/core.cljs {:file "test/graphql-tlc/core.cljs", :line 7, :column 3, :tag :cljs/analysis-error}

Is this a known/expected deviation from Clojure proper?

Thanks!

The bug is that qualified protocol methods are not supported in ClojureScript. Please open a minor issue about this in JIRA with your minimal example.

Thanks!
David 

Jonathan Leonard

unread,
Sep 16, 2015, 11:48:15 AM9/16/15
to clojur...@googlegroups.com




On Sep 16, 2015, at 5:40 AM, David Nolen <dnolen...@gmail.com> wrote:

On Wed, Sep 16, 2015 at 12:28 AM, Jonathan Leonard <joha...@gmail.com> wrote:
Per the documentation on defprotocol for Clojure itself, such a reference (e.g., in a reify of a protocol defined in a separate file/namespace) does require a fully qualified name (and will not accept unqualified name).

As far as I know this is not the case. If the documentation says so it is incorrect with respect to the implementation and code in the wild, https://github.com/clojure/core.async/blob/master/src/main/clojure/clojure/core/async/impl/channels.clj#L67

Please note: "All [both the methods and the protocol itself] are
namespace-qualified by the ns enclosing the definition" from:
https://clojuredocs.org/clojure.core/defprotocol
Also, I've gotten compile errors from Clojure itself when the qualification is left out and I've read tutorials which also say that the namespace is required.

 
Using the fully qualified name in ClojureScript produces the following error:
Caused by: clojure.lang.ExceptionInfo: set! target must be a field or a symbol naming a var at line 7 test/graphql-tlc/core.cljs {:file "test/graphql-tlc/core.cljs", :line 7, :column 3, :tag :cljs/analysis-error}

Is this a known/expected deviation from Clojure proper?

Thanks!

The bug is that qualified protocol methods are not supported in ClojureScript. Please open a minor issue about this in JIRA with your minimal example.

Ok, will do. Thanks!



Thanks!
David 

Jonathan Leonard

unread,
Sep 16, 2015, 2:18:52 PM9/16/15
to ClojureScript

David Nolen

unread,
Sep 16, 2015, 2:36:10 PM9/16/15
to clojur...@googlegroups.com
You are misinterpreting the documentation as far as I know. It's just referring to the fact that the protocol fn vars and the protocol var exist in the namespace they were declared.

I have never encountered the issues you have described and as I've already said, you'll find plenty of code in the wild that does correspond to your interpretation.

David

You received this message because you are subscribed to the Google Groups "ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojurescrip...@googlegroups.com.

Jonathan Leonard

unread,
Sep 16, 2015, 2:39:27 PM9/16/15
to clojur...@googlegroups.com
>
> On Sep 16, 2015, at 11:36 AM, David Nolen <dnolen...@gmail.com> wrote:
>
> You are misinterpreting the documentation as far as I know. It's just referring to the fact that the protocol fn vars and the protocol var exist in the namespace they were declared.

But that is exactly my interpretation. Therefore to refer to those vars from another namespace, they need to be qualified (or the namespace ‘used’ or ‘imported' etc).


> I have never encountered the issues you have described and as I've already said, you'll find plenty of code in the wild that does correspond to your interpretation.
>

Have you tried my minimal repro? It happens every time for me (both the expected behavior works in Clojure and doesn’t in ClojureScript).

—Jonathan


David Nolen

unread,
Sep 16, 2015, 3:27:14 PM9/16/15
to clojur...@googlegroups.com
You should re-read what I said :)

Your ticket after I modified it reflects the actual issue.

Thanks,
David

Jonathan Leonard

unread,
Sep 16, 2015, 3:33:00 PM9/16/15
to clojur...@googlegroups.com
Also, are you sure that those examples you cited have not 'used' or 'imported' the vars such that a qualification wouldn't be necessary?

I'm away from my computer right now or I would double check all of this as a sanity check but I'm pretty sure this has consistently been the situation over my last few months of using Clojure full time.

Maybe you or someone else could try playing around with it on your end (in Clojure proper)?

Jonathan Leonard

unread,
Sep 16, 2015, 3:40:39 PM9/16/15
to clojur...@googlegroups.com
As far as I can tell, the ticket as it stands now is just my original ticket with some fluff removed. From my perspective, yes, what remains is the actual issue (and has always been the issue). :)

Although regarding your summary change:

I do think that under the skin what's happening here is that the vars associated with the methods inside the declared protocol are being defined on the global namespace (which is fine in JavaScript since everything ends up in the same file most likely anyway). I doubt that this bug would even be possible in Clojure proper since it compiles things into Java namespaces and classes.

--Jonathan


You received this message because you are subscribed to a topic in the Google Groups "ClojureScript" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/clojurescript/Rgnn_KPSY_o/unsubscribe.
To unsubscribe from this group and all its topics, send an email to clojurescrip...@googlegroups.com.

Jonathan Leonard

unread,
Sep 16, 2015, 3:47:17 PM9/16/15
to clojur...@googlegroups.com
Also, my apologies if my communications were worded confusingly. I'm still learning Clojure jargon so some of my wordings do in fact feel tortured (even from my end). ;)


David Nolen

unread,
Sep 16, 2015, 3:58:30 PM9/16/15
to clojur...@googlegroups.com
On Wed, Sep 16, 2015 at 3:40 PM, Jonathan Leonard <joha...@gmail.com> wrote:

I do think that under the skin what's happening here is that the vars associated with the methods inside the declared protocol are being defined on the global namespace (which is fine in JavaScript since everything ends up in the same file most likely anyway). I doubt that this bug would even be possible in Clojure proper since it compiles things into Java namespaces and classes.

--Jonathan

There are no global names involved here with respect to ClojureScript semantics. Even if you do not qualify the method names, they will be correctly resolved because you already qualified the protocol - no more information is necessary as they have to come from the same namespace anyhow. The bug is purely a syntactical one - if you do decide to qualify the method names, it should _also_ work!

David

Jonathan Leonard

unread,
Sep 16, 2015, 4:32:15 PM9/16/15
to ClojureScript
Doh! You are right. I just wrote a simple test program and it turns out that my mistake in recollection was confusing the *impl site* (i.e., inside a 'reify') with the *call site*. The qualification is of course required at the call site but as you pointed out, optional within the reify.

Sorry for the confusion!

Reply all
Reply to author
Forward
0 new messages