This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-09-04
Channels
- # announcements (5)
- # beginners (124)
- # boot (43)
- # braveandtrue (8)
- # calva (1)
- # cider (44)
- # cljs-dev (1)
- # clojure (188)
- # clojure-canada (3)
- # clojure-germany (1)
- # clojure-italy (5)
- # clojure-nl (13)
- # clojure-russia (1)
- # clojure-spec (14)
- # clojure-uk (42)
- # clojurescript (94)
- # core-async (5)
- # cursive (5)
- # datomic (45)
- # duct (3)
- # emacs (6)
- # figwheel-main (93)
- # fulcro (22)
- # graphql (3)
- # hyperfiddle (1)
- # leiningen (3)
- # off-topic (1)
- # pedestal (1)
- # play-clj (1)
- # portkey (1)
- # re-frame (17)
- # reagent (71)
- # remote-jobs (2)
- # rum (3)
- # shadow-cljs (45)
- # spacemacs (17)
- # specter (18)
- # tools-deps (27)
- # unrepl (1)
- # vim (3)
Say I want to include a spec from a clj-only library can I do this in cljc:
#?(:clj (s/def ::my-spec ::clj-only-lib/the-spec)
:cljs (s/def ::my-spec any?))
currently we are seeing this exception:
Caused by: clojure.lang.ExceptionInfo: Invalid keyword: ::clj-time.s/local-date. {:type :reader-exception, :ex-kind :reader-error, :file "/x/spec.cljc", :line 16, :col 54}
Autoresolved keywords use the current env at read-time to resolve the ns
And this is reading, which happens regardless of the chosen branch
A workaround is to use the full keyword with namespace
It’s read before it’s ignored
and so it gets to the auto-resolved keywords and if the clj-only ns isn't in the env at that point you get an exception
Yes, the expressions are read and auto-resolving keywords is part of that, prior to the conditional being applied. Then the result of reading is compiled.
So reader conditionals can only select between syntactically valid expressions that can be read in -- :some-ns/some-thing
is read "as-is" but ::some-alias/some-thing
has some-alias
expanded as part of the reading process.
(I hope I explained that accurately!)