Skip to content

Instantly share code, notes, and snippets.

@mrrodriguez
Created May 3, 2019 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrrodriguez/dc48281196f99e30ee84c56c0ec6f63a to your computer and use it in GitHub Desktop.
Save mrrodriguez/dc48281196f99e30ee84c56c0ec6f63a to your computer and use it in GitHub Desktop.
Using `clojure.core/eval` at CLJS macroexpansion-time
#error {
:cause "Unable to resolve symbol: bar in this context"
:via
[{:type clojure.lang.ExceptionInfo
:message "failed compiling file:src/example/foo.cljs"
:data {:file #object[java.io.File 0x2766fb87 "src/example/foo.cljs"]}
:at [clojure.core$ex_info invokeStatic "core.clj" 4739]}
{:type clojure.lang.ExceptionInfo
:message "java.lang.RuntimeException: Unable to resolve symbol: bar in this context, compiling:(*thing*:6:9) at line 6 src/example/foo.cljs"
:data {:file "src/example/foo.cljs", :line 6, :column 1, :tag :cljs/analysis-error}
:at [clojure.core$ex_info invokeStatic "core.clj" 4739]}
{:type clojure.lang.Compiler$CompilerException
:message "java.lang.RuntimeException: Unable to resolve symbol: bar in this context, compiling:(*thing*:6:9)"
:at [clojure.lang.Compiler analyze "Compiler.java" 6792]}
{:type java.lang.RuntimeException
:message "Unable to resolve symbol: bar in this context"
:at [clojure.lang.Util runtimeException "Util.java" 221]}]
:trace
[[clojure.lang.Util runtimeException "Util.java" 221]
[clojure.lang.Compiler resolveIn "Compiler.java" 7299]
[clojure.lang.Compiler resolve "Compiler.java" 7243]
[clojure.lang.Compiler analyzeSymbol "Compiler.java" 7204]
[clojure.lang.Compiler analyze "Compiler.java" 6752]
[clojure.lang.Compiler analyze "Compiler.java" 6729]
[clojure.lang.Compiler eval "Compiler.java" 7066]
[clojure.lang.Compiler eval "Compiler.java" 7025]
[clojure.core$eval invokeStatic "core.clj" 3206]
[clojure.core$eval invoke "core.clj" 3202]
[example.macros$doit invokeStatic "macros.clj" 4]
[example.macros$doit invoke "macros.clj" 3]
[clojure.lang.AFn applyToHelper "AFn.java" 165]
[clojure.lang.AFn applyTo "AFn.java" 144]
[clojure.core$apply invokeStatic "core.clj" 661]
[clojure.core$apply invoke "core.clj" 652]
[cljs.analyzer$macroexpand_1_STAR_$fn__2393 invoke "analyzer.cljc" 3328]
[cljs.analyzer$macroexpand_1_STAR_ invokeStatic "analyzer.cljc" 3327]
[cljs.analyzer$macroexpand_1_STAR_ invoke "analyzer.cljc" 3314]
[cljs.analyzer$macroexpand_1 invokeStatic "analyzer.cljc" 3375]
[cljs.analyzer$macroexpand_1 invoke "analyzer.cljc" 3371]
[cljs.analyzer$analyze_seq invokeStatic "analyzer.cljc" 3408]
[cljs.analyzer$analyze_seq invoke "analyzer.cljc" 3388]
[cljs.analyzer$analyze_form invokeStatic "analyzer.cljc" 3578]
[cljs.analyzer$analyze_form invoke "analyzer.cljc" 3574]
[cljs.analyzer$analyze_STAR_ invokeStatic "analyzer.cljc" 3628]
[cljs.analyzer$analyze_STAR_ invoke "analyzer.cljc" 3619]
[cljs.analyzer$analyze invokeStatic "analyzer.cljc" 3649]
[cljs.analyzer$analyze invoke "analyzer.cljc" 3631]
[cljs.compiler$emit_source invokeStatic "compiler.cljc" 1390]
[cljs.compiler$emit_source invoke "compiler.cljc" 1369]
[cljs.compiler$compile_file_STAR_$fn__3696 invoke "compiler.cljc" 1471]
[cljs.compiler$with_core_cljs invokeStatic "compiler.cljc" 1289]
[cljs.compiler$with_core_cljs invoke "compiler.cljc" 1278]
[cljs.compiler$compile_file_STAR_ invokeStatic "compiler.cljc" 1455]
[cljs.compiler$compile_file_STAR_ invoke "compiler.cljc" 1448]
[cljs.compiler$compile_file$fn__3727 invoke "compiler.cljc" 1553]
[cljs.compiler$compile_file invokeStatic "compiler.cljc" 1528]
[cljs.compiler$compile_file invoke "compiler.cljc" 1504]
[cljs.closure$compile_file invokeStatic "closure.clj" 647]
[cljs.closure$compile_file invoke "closure.clj" 625]
[cljs.closure$fn__5175 invokeStatic "closure.clj" 721]
[cljs.closure$fn__5175 invoke "closure.clj" 715]
[cljs.closure$fn__5088$G__5081__5095 invoke "closure.clj" 543]
[cljs.closure$compile_sources$iter__5301__5305$fn__5306 invoke "closure.clj" 1081]
[clojure.lang.LazySeq sval "LazySeq.java" 40]
[clojure.lang.LazySeq seq "LazySeq.java" 49]
[clojure.lang.Cons next "Cons.java" 39]
[clojure.lang.RT next "RT.java" 706]
[clojure.core$next__5108 invokeStatic "core.clj" 64]
[clojure.core$dorun invokeStatic "core.clj" 3134]
[clojure.core$doall invokeStatic "core.clj" 3140]
[clojure.core$doall invoke "core.clj" 3140]
[cljs.closure$compile_sources invokeStatic "closure.clj" 1077]
[cljs.closure$compile_sources invoke "closure.clj" 1066]
[cljs.closure$build invokeStatic "closure.clj" 2930]
[cljs.closure$build invoke "closure.clj" 2838]
[cljs.build.api$build invokeStatic "api.clj" 208]
[cljs.build.api$build invoke "api.clj" 189]
[cljs.build.api$build invokeStatic "api.clj" 195]
[cljs.build.api$build invoke "api.clj" 189]
[user$eval14682 invokeStatic "form-init9009066232044880749.clj" 34]
[user$eval14682 invoke "form-init9009066232044880749.clj" 34]
[clojure.lang.Compiler eval "Compiler.java" 7062]
[clojure.lang.Compiler eval "Compiler.java" 7052]
[clojure.lang.Compiler eval "Compiler.java" 7025]
[clojure.core$eval invokeStatic "core.clj" 3206]
[clojure.core$eval invoke "core.clj" 3202]
[clojure.main$repl$read_eval_print__8572$fn__8575 invoke "main.clj" 243]
[clojure.main$repl$read_eval_print__8572 invoke "main.clj" 243]
[clojure.main$repl$fn__8581 invoke "main.clj" 261]
[clojure.main$repl invokeStatic "main.clj" 261]
[clojure.main$repl doInvoke "main.clj" 177]
;; ...etc...
]}
(ns example.foo
(:require-macros [example.macros :refer [doit]]))
(def bar 10)
(doit x bar)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; Trying it out
#_(do
(require '[cljs.build.api :as bapi])
(bapi/build
"src"
{:main 'example.foo
:output-to "target/compiled.js"
:output-dir "target"
:optimizations :none}))
;; Tested with (I see same in earlier/later versions though:
;; [org.clojure/clojure "1.9.0"]
;; [org.clojure/clojurescript "1.10.339"]
(ns example.macros)
(defmacro doit [n x]
(let [v (eval x)]
`(def ~n ~v)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment