This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-02-18
Channels
- # announcements (2)
- # aws (3)
- # beginners (35)
- # boot (10)
- # cider (33)
- # cljs-dev (22)
- # clojure (58)
- # clojure-belgium (1)
- # clojure-europe (8)
- # clojure-houston (1)
- # clojure-italy (47)
- # clojure-nl (2)
- # clojure-spec (4)
- # clojure-uk (39)
- # clojurescript (12)
- # cursive (18)
- # data-science (1)
- # datomic (2)
- # emacs (24)
- # figwheel-main (29)
- # fulcro (24)
- # hoplon (14)
- # juxt (6)
- # kaocha (3)
- # nrepl (6)
- # off-topic (64)
- # om (1)
- # om-next (1)
- # pathom (21)
- # pedestal (18)
- # planck (40)
- # protorepl (1)
- # re-frame (15)
- # reagent (7)
- # reitit (16)
- # shadow-cljs (184)
- # spacemacs (4)
- # test-check (33)
:statement
is an odd default as the compiled code for it can be elided if it is known to not produce a side effect. For example:
cljs.user=> (cljs.js/compile-str (cljs.js/empty-state) "1" prn)
{:value ""}
but
cljs.user=> (cljs.js/compile-str (cljs.js/empty-state) "1" "foo" {:context :expr} prn)
{:value "(1)"}
I suspect that, when Antiónio added this docstring clarification, he and I were already quite used to :context :expr
, felt comfortable with it being the default, but failed to actually confirm that it is the default.(do
1 ; :statement; can be elided from the generated code
(prn :hi) ; :statement; can't be elided as it has a side effect
3)
Yeah, evidently all the docstrings indicate :expr
is the default, but evidently this is not actually the case.
It seems that :statement
might be of interest to you in some academic fashion, or if you are building something odd. You almost always want :expr
Are there instances where you want to call eval
or compile-str
on a thing but not keep env between invocations? Like, for memory or sandboxing?
Summary: :expr
should be the default, it matches the docstring. We arguably have a defect in that :statement
is really the default. Changing the default from :statement
to :expr
to fix this bug is, strictly speaking, a breaking change. But, pragmatically, speaking, everyone is probably explicitly passing :expr
.
you don't really need :expr
if you treat things like loading files. :expr
is only required if you care about the return value of eval-str
Maybe :expr
would leave around a dirty environment for existing code that expects :statement
behavior?
Yeah, that's a good point. If you are only evaluating for side effects, and you know what you are doing, you could use :statement
for that.
Yeah, the safest thing to do is to change all the docstrings to reflect the actual default.
:statement
is an unfortunate default in that it doesn't align with the "simpler" use case of just using self-hosted to see what a form evaluates to
But what if some individual functions, like eval
when called directly, opted into :expr
behavior? Are there specific fns that'd be more safe to convert?