Yes, this is expected. Similar issue exists with kws with unknown aliases 
in reader conditionals.

user=> #?(:clj 10 :cljs 5)
10
user=> #?(:clj 10 :cljs ::foo/bar)
RuntimeException Invalid token: ::foo/bar  
clojure.lang.Util.runtimeException (Util.java:221)

Autoresolved keywords inherently require knowledge of the environment to do 
the "autoresolve" part during read (and all of these things require read).

There is a way around this though because as of 1.9, the namespace resolver 
in LispReader is pluggable by setting the dynamic var *reader-resolver* to 
an implementation of LispReader$Resolver. If you wanted, you could make 
this tolerant (at the risk of maybe allowing other stuff you shouldn't).

user=> (def resolver (reify clojure.lang.LispReader$Resolver
                (currentNS [_] (.-name *ns*))
                (resolveClass [_ sym] sym)
                (resolveAlias [_ sym] sym) ;; never fail
                (resolveVar [_ sym] sym)))
#'user/resolver
user=> (read-string "[#_::fooo/bar]")
RuntimeException Invalid token: ::fooo/bar  
clojure.lang.Util.runtimeException (Util.java:221)
user=> (binding [*reader-resolver* resolver] (read-string "[#_::fooo/bar]"))
[]        

It's unlikely this is worth the trouble for something like this but it 
helps fill in some gaps.


On Wednesday, August 22, 2018 at 7:32:51 PM UTC-5, Robert P. Levy wrote:
>
> I wouldn't consider this a bug or even an unfortunate behavior 
> necessarily, but potentially surprising and worth mentioning.  The comment 
> reader macro #_ works just fine as long as nothing breaks the reader.  The 
> surprise happens when you don't consider that for namespaced keywords using 
> ns aliases, the namespace resolution happens at reader-macro expansion 
> time, prior to evaluation.  As a logical consequence of this is that 
> seemingly commented out code will fail at read-time if the ns alias or 
> namespace doesn't exist.
>
> Clojure repro:
>
> user=> (println #_(::fooo/bar))
>
> RuntimeException Invalid token: ::fooo/bar  
> clojure.lang.Util.runtimeException (Util.java:221)
> RuntimeException Unmatched delimiter: )  
> clojure.lang.Util.runtimeException (Util.java:221)
> user=> RuntimeException Unmatched delimiter: )  
> clojure.lang.Util.runtimeException (Util.java:221)
>
> ClojureScript repro:
>
> cljs.user=> (println #_(::fooo/bar))
>
> cljs.user=> clojure.lang.ExceptionInfo: [line 1, col 23] Invalid keyword: 
> ::fooo/bar. {:type :reader-exception, :ex-kind :reader-error, :file nil, 
> :line 1, :col 23}
> at clojure.core$ex_info.invokeStatic(core.clj:4739)
> at clojure.core$ex_info.invoke(core.clj:4739)
> at clojure.tools.reader.impl.errors$throw_ex.invokeStatic(errors.clj:34)
> at clojure.tools.reader.impl.errors$throw_ex.doInvoke(errors.clj:24)
> ...
>

-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to