This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-10-29
Channels
- # 100-days-of-code (2)
- # bangalore-clj (1)
- # beginners (141)
- # cider (33)
- # cljs-dev (13)
- # cljsjs (7)
- # cljsrn (1)
- # clojure (88)
- # clojure-conj (3)
- # clojure-dev (24)
- # clojure-italy (11)
- # clojure-nl (4)
- # clojure-russia (1)
- # clojure-sanfrancisco (1)
- # clojure-spec (4)
- # clojure-uk (53)
- # clojurescript (65)
- # core-logic (2)
- # cursive (28)
- # datomic (33)
- # duct (2)
- # emacs (3)
- # figwheel-main (9)
- # fulcro (44)
- # hoplon (6)
- # leiningen (144)
- # mount (1)
- # nrepl (21)
- # off-topic (102)
- # onyx (2)
- # other-languages (5)
- # pathom (6)
- # planck (3)
- # portkey (1)
- # re-frame (7)
- # reagent (5)
- # reitit (17)
- # shadow-cljs (24)
- # spacemacs (16)
- # tools-deps (64)
- # uncomplicate (2)
- # vim (22)
Could someone verify if this is a bug before I post it to JIRA? https://gist.github.com/borkdude/a7c38295f19a0dd2a68a7da21d634661
@borkdude Unfortunately, instrument
and unstrument
are side-effecting macros, and their behavior in the example above depends on when they are expanded. ClojureScript currently analyzes a finally
block prior to the try
body. Looking at Clojure's behavior for side-effecting macros, you can see that it expands macros in the try
body prior to any in a finally
block. ClojureScript could be revised to do things in that order, and, if such a revision were made, then the code above would work.
Is this a bug? I suppose it depends on whether the Clojure language has anything to say about the ordering of macro expansion. If it does, it would probably make sense to have ClojureScript follow that where reasonable.
But just looking at the example, I’d say it’s a bug. It works with normal Clojure spec. Is there a way not using side effects in macros for cljs spec?
Even if ClojureScript analyzed the forms in the other order, wouldn't it do the unstrument side effect before executing the code, and still not work as desired? If so, it seems like this is a fundamental difference between ClojureScript and Clojure/Java in how instrument/unstrument are implemented between the two (functions in Clojure/Java, macros in ClojureScript).
clarification - macros with compile-time side effects in ClojureScript.
Andy: there seems to be a macro + runtime part to instrument/unstrument. When I avoid finally my code works as intended.
Note that instrument
is used in a finally block somewhere in the .cljc
code of spec cljs ( check-1
).
Yeah, @andy.fingerhut it is interesting the way it works. The (i|u)nstrumentation itself doesn't actually occur in the side effect, but some bookkeeping does, which causes the generated code to differ based on that bookkeeping. The generated code is what actually performs the (i|u)nstrumentation at runtime.
yeah and it seems that the bookkeeping can go out of sync with performing generated code
Independent of the semantics or lack thereof of this, the analysis order has the odd effects you might expect:
cljs.user=> (try
#_=> x
#_=> (catch :default _ y)
#_=> (finally z))
^
WARNING: Use of undeclared Var cljs.user/z at line 4
WARNING: Use of undeclared Var cljs.user/y at line 3
WARNING: Use of undeclared Var cljs.user/x at line 2
(Note the decreasing line numbers.)