This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-06-22
Channels
- # babashka (36)
- # beginners (42)
- # calva (6)
- # chlorine-clover (25)
- # cider (31)
- # clara (5)
- # clj-kondo (55)
- # cljdoc (3)
- # cljs-dev (7)
- # cljsrn (3)
- # clojure (73)
- # clojure-brasil (6)
- # clojure-europe (8)
- # clojure-italy (2)
- # clojure-nl (3)
- # clojure-norway (1)
- # clojure-spec (3)
- # clojure-sweden (4)
- # clojure-switzerland (2)
- # clojure-uk (29)
- # clojurescript (93)
- # conjure (21)
- # data-science (14)
- # datomic (19)
- # emacs (4)
- # exercism (3)
- # figwheel-main (38)
- # fulcro (38)
- # graalvm (42)
- # graphql (5)
- # jackdaw (3)
- # jobs (1)
- # joker (2)
- # lambdaisland (1)
- # leiningen (31)
- # malli (8)
- # meander (5)
- # off-topic (27)
- # pathom (2)
- # pedestal (28)
- # re-frame (25)
- # reagent (2)
- # reitit (11)
- # releases (3)
- # remote-jobs (1)
- # rum (1)
- # shadow-cljs (63)
- # spacemacs (17)
- # sql (1)
just trying to get an environment up where i can test things. using cursive in cljs.compiler.api
and wanting to see emitted code. I expect that i could do something like
(println (emit (ana-api/analyze (ana-api/empty-env) '(and 1 2))))
to see the emitted js code. it's close but not quite there. i'm seeing the following output which only has the first test and not the second:
var and__9016__auto___16490 = (1);
if(cljs.core.truth_(and__9016__auto___16490)){
} else {
}
anyone know off hand how to get a fast feedback loop up in cursive? (open to bare clj in a terminal if that's easier)@dpsutton In terms of the output you are seeing above, it is a consequence of the default :context
being :statement
and the fact that numbers have no side effects so are elided as an optimization. If instead you set :context
to be :expr
you'll get what you are expecting. In other words try
(println (emit (ana-api/analyze (assoc (ana-api/empty-env) :context :expr) '(and 1 2))))
(If the :statement
/ :expr
stuff doesn't make sense, consider the code generated for (do (and 1 2) nil)
)
You can see that optimization here https://github.com/clojure/clojurescript/blob/master/src/main/clojure/cljs/compiler.cljc#L608-L611 It is really only applied to constants IIRC.