<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Clojure Q&amp;A - Recent questions tagged eval</title>
<link>https://ask.clojure.org/index.php/tag/eval</link>
<description></description>
<item>
<title>`eval` using functions with metadata</title>
<link>https://ask.clojure.org/index.php/15115/eval-using-functions-with-metadata</link>
<description>&lt;p&gt;TIL:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(eval (list + 1 2)) ; works
(eval (list (var-get #'+) 1 2)) ; works
(eval (list (fn [a b] (+ a b)) 1 2)) ; works

(defmacro m [] `(~(fn [a b] (+ a b)) 1 2))
(m) ; also works

;; however, if the function has any metadata:
(eval (list (with-meta + {}) 1 2))
;; ^ fails, No matching ctor found for class clojure.lang.AFunction$1
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This was unintuitive to discover.&lt;/p&gt;
&lt;p&gt;I solved it locally with a little helper:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(defn val-&amp;gt;expr [v]
  (if (symbol? v)
    `'~v
    (cond-&amp;gt; v
      (and (fn? v) (not (nil? (meta v))))
      (-&amp;gt; (with-meta nil)
          (list (-&amp;gt; v meta (update-vals val-&amp;gt;expr)))
          (conj `with-meta)))))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;But this takes special handling. I wonder if something similar would not be possible on a &quot;matching ctor&quot;-level, possibly also for &lt;code&gt;comp&lt;/code&gt;, &lt;code&gt;every-pred?&lt;/code&gt;, etc. It would be fairly trivial even in userland to have versions of these functions which carry metadata sufficient to recreate expressions, e.g. &lt;code&gt;comp&lt;/code&gt; storing the list of functions, and then &lt;code&gt;eval&lt;/code&gt;, on encountering &lt;code&gt;No matching ctor found for class clojure.core$comp$fn__5921&lt;/code&gt;, can instead pull out the list of functions from that value and evaluate &lt;code&gt;(list* comp (:composed-fns (meta v)))&lt;/code&gt; (or some such) instead.&lt;/p&gt;
&lt;p&gt;I think this would be great to have in the core lib, at least for metadata and core libs functions like &lt;code&gt;comp&lt;/code&gt;, &lt;code&gt;some-fn&lt;/code&gt;, &lt;code&gt;every-pred?&lt;/code&gt;, and &lt;code&gt;complement&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Note, I'm not talking about adding or changing ctors for these necessarily. A hook for taking unconstructable values and making a constructable value out of them would serve just as well, maybe even a multifn.&lt;/p&gt;
&lt;p&gt;Strictly in userland and without core lib support, I suppose the cleanest way to do something like this is a custom protocol and probably monkeypatch some core libs functions (maybe &lt;code&gt;eval&lt;/code&gt;?)&lt;/p&gt;
&lt;p&gt;So I suppose my questions are:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Is this something you agree would be good to have in general? Or is this by design for some reason I can't see?&lt;/li&gt;
&lt;li&gt;Would this be good and practical to have in the corelib? Oughtn't be a breaking change at least&lt;/li&gt;
&lt;li&gt;If no, is there currently any sane way to apply my solution in a more systemic way than wrapping every relevant value with a &lt;code&gt;val-&amp;gt;expr&lt;/code&gt; call?&lt;/li&gt;
&lt;/ol&gt;
</description>
<category>Syntax and reader</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/15115/eval-using-functions-with-metadata</guid>
<pubDate>Mon, 01 Jun 2026 14:33:00 +0000</pubDate>
</item>
<item>
<title>Evaluating forms using eval can create a valid undesirable recursion point</title>
<link>https://ask.clojure.org/index.php/14991/evaluating-forms-using-create-valid-undesirable-recursion</link>
<description>&lt;p&gt;When the &lt;code&gt;eval&lt;/code&gt; function in Clojure is called with an argument that is an instance of &lt;code&gt;IPersistentCollection&lt;/code&gt; which likely isn't a special def-like form (the first element isn't a symbol at all or it does not start with &lt;code&gt;&quot;def&quot;&lt;/code&gt;), the form is first wrapped in an anonymous function which then gets compiled and invoked, which indirectly evaluates the original form.&lt;/p&gt;
&lt;p&gt;There aren't any extra checks performed and it makes forms like these 2 valid, which should normally be rejected and a compiler exception should be thrown:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(recur)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;or&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(let []
  (print &quot;Hello&quot;)
  (Thread/sleep 1000)
  (recur))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;where the 2nd form keeps printing &quot;Hello&quot; and loops infinitely over the outer wrapper function.&lt;/p&gt;
</description>
<category>Clojure</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14991/evaluating-forms-using-create-valid-undesirable-recursion</guid>
<pubDate>Mon, 16 Mar 2026 23:17:54 +0000</pubDate>
</item>
<item>
<title>How can I make Calva use a relative path when loading a file in cljs?</title>
<link>https://ask.clojure.org/index.php/14129/how-can-make-calva-use-relative-path-when-loading-file-in-cljs</link>
<description>&lt;p&gt;Is there a way to make &lt;code&gt;Calva: Load/Evaluate Current File and its Requires/Dependencies&lt;/code&gt; use a relative path for ClojureScript instead of an absolute path?&lt;/p&gt;
&lt;p&gt;I'm connecting to a docker container repl for development and the app is running at &lt;code&gt;/app&lt;/code&gt; inside the container. Loading the current file in Clojure works as expected and evaluating things that have already been loaded in ClojureScript works as expected. Loading the current file in ClojureScript fails because it uses the host machine's full path. I get the following error:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;; ------ REPL Error while processing ---------------------------------------------
; (cljs.core/load-file &quot;/home/bmaddy/.../model/user.cljc&quot;)
; FileNotFoundException: /home/bmaddy/.../model/user.cljc (No such file or directory)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The following all work in the cljs repl as expected:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;;; absolute path inside the container
(cljs.core/load-file &quot;/app/src/.../model/user.cljc&quot;)
[]
;; relative path from project folder
(cljs.core/load-file &quot;./src/.../model/user.cljc&quot;)
[]
(cljs.core/load-file &quot;src/.../model/user.cljc&quot;)
[]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I see there are &lt;code&gt;JACK_IN_PROJECT_ROOT_PATH&lt;/code&gt; and &lt;code&gt;calva.replConnectSequences.projectRootPath&lt;/code&gt; settings, but they don't seem to affect this.&lt;/p&gt;
&lt;p&gt;Some version info:&lt;br&gt;
Calva version used: &lt;code&gt;v2.0.474&lt;/code&gt;&lt;br&gt;
clojure-lsp version used: &lt;code&gt;2024.08.05-18.16.00&lt;/code&gt;&lt;br&gt;
VSCode Version: &lt;code&gt;1.93.1&lt;/code&gt;&lt;br&gt;
OS: Linux&lt;/p&gt;
</description>
<category>Calva</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14129/how-can-make-calva-use-relative-path-when-loading-file-in-cljs</guid>
<pubDate>Mon, 23 Sep 2024 18:35:32 +0000</pubDate>
</item>
<item>
<title>cljs.js/eval: def not working when using :simple optimization (works with :none/:whitespace)</title>
<link>https://ask.clojure.org/index.php/12512/cljs-eval-working-using-simple-optimization-works-whitespace</link>
<description>&lt;p&gt;as the title suggests, def appears to pass through without doing anything.&lt;/p&gt;
&lt;p&gt;i.e. &quot;(def x)&quot; succeeds&lt;br&gt;
but &quot;(def x 10)&quot; fails because&lt;br&gt;
&quot;Cannot read properties of undefined (reading 'x')&quot;&lt;/p&gt;
&lt;p&gt;article here: &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojurescript.org/guides/self-hosting&quot;&gt;https://clojurescript.org/guides/self-hosting&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;suggests :simple optimization should work&lt;/p&gt;
&lt;p&gt;to reproduce: &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/sstraust/ClojureDefRepro&quot;&gt;https://github.com/sstraust/ClojureDefRepro&lt;/a&gt; (see comments for instructions)&lt;/p&gt;
</description>
<category>ClojureScript</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/12512/cljs-eval-working-using-simple-optimization-works-whitespace</guid>
<pubDate>Wed, 28 Dec 2022 15:51:59 +0000</pubDate>
</item>
<item>
<title>Calva: Is there a way to evaluate a whole file?</title>
<link>https://ask.clojure.org/index.php/11892/calva-is-there-a-way-to-evaluate-a-whole-file</link>
<description>&lt;p&gt;Beside selecting the whole file and then evaluating the selection, can I evaluate the whole file in a more convenient way?&lt;/p&gt;
&lt;p&gt;Adapted from questions asked in the &lt;code&gt;#calva&lt;/code&gt; channel at &lt;a rel=&quot;nofollow&quot; href=&quot;http://clojurians.net/&quot;&gt;Clojurians Slack&lt;/a&gt;.&lt;/p&gt;
</description>
<category>Calva</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/11892/calva-is-there-a-way-to-evaluate-a-whole-file</guid>
<pubDate>Tue, 17 May 2022 14:33:43 +0000</pubDate>
</item>
<item>
<title>Why does evaluating an eduction cause the reader to fail?</title>
<link>https://ask.clojure.org/index.php/10576/why-does-evaluating-an-eduction-cause-the-reader-to-fail</link>
<description>&lt;p&gt;Providing an eduction to the repl will print the result in list format:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;=&amp;gt; (eduction (map identity) [#'+ 2 3])
(#'clojure.core/+ 2 3)&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;This should not eval to 5, because an eduction is not a seq. However, when I try, then I expect to get the eduction returned, but instead I get an unexpected error from the reader in the REPL:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;=&amp;gt; (eval (eduction (map identity) [#'+ 2 3]))
Execution error (IllegalArgumentException) at user$eval183/&amp;lt;clinit&amp;gt; (REPL:1).
No matching ctor found for class clojure.core$map$fn__5880&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;The stack trace for this seems to show that the error occurs in the reader:&lt;br&gt;
&lt;code&gt;`&lt;/code&gt;&lt;br&gt;
java.lang.ExceptionInInitializerError&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at clojure.lang.Compiler$ObjExpr.eval(Compiler.java:5000)
at clojure.lang.Compiler.eval(Compiler.java:7180)
at clojure.lang.Compiler.eval(Compiler.java:7136)
at clojure.core$eval.invokeStatic(core.clj:3202)
at clojure.core$eval.invoke(core.clj:3198)
at user$eval181.invokeStatic(NO_SOURCE_FILE:1)
at user$eval181.invoke(NO_SOURCE_FILE:1)
at clojure.lang.Compiler.eval(Compiler.java:7181)
at clojure.lang.Compiler.eval(Compiler.java:7136)
at clojure.core$eval.invokeStatic(core.clj:3202)
at clojure.core$eval.invoke(core.clj:3198)
at clojure.main$repl$read_eval_print__9110$fn__9113.invoke(main.clj:437)
at clojure.main$repl$read_eval_print__9110.invoke(main.clj:437)
at clojure.main$repl$fn__9119.invoke(main.clj:458)
at clojure.main$repl.invokeStatic(main.clj:458)
at clojure.main$repl_opt.invokeStatic(main.clj:522)
at clojure.main$main.invokeStatic(main.clj:667)
at clojure.main$main.doInvoke(main.clj:616)
at clojure.lang.RestFn.invoke(RestFn.java:397)
at clojure.lang.AFn.applyToHelper(AFn.java:152)
at clojure.lang.RestFn.applyTo(RestFn.java:132)
at clojure.lang.Var.applyTo(Var.java:705)
at clojure.main.main(main.java:40)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Caused by: java.lang.IllegalArgumentException: No matching ctor found for class clojure.core$map$fn__5880&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;at clojure.lang.Reflector.invokeConstructor(Reflector.java:288)
at clojure.lang.LispReader$EvalReader.invoke(LispReader.java:1317)
at clojure.lang.LispReader$DispatchReader.invoke(LispReader.java:853)
at clojure.lang.LispReader.read(LispReader.java:285)
at clojure.lang.LispReader.read(LispReader.java:216)
at clojure.lang.LispReader.read(LispReader.java:205)
at clojure.lang.RT.readString(RT.java:1879)
at clojure.lang.RT.readString(RT.java:1874)
at user$eval183.&amp;lt;clinit&amp;gt;(NO_SOURCE_FILE:1)
... 27 more
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;`&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;The source code at &lt;code&gt;clojure.lang.LispReader$EvalReader.invoke(LispReader.java:1317)&lt;/code&gt; suggests that it's processing a list form where the first element ends with a dot character. This is unexpected&lt;/p&gt;
</description>
<category>REPL</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/10576/why-does-evaluating-an-eduction-cause-the-reader-to-fail</guid>
<pubDate>Tue, 11 May 2021 01:37:14 +0000</pubDate>
</item>
<item>
<title>Namespace.java: addAlias exception could be more informative</title>
<link>https://ask.clojure.org/index.php/8705/namespace-java-addalias-exception-could-more-informative</link>
<description>&lt;p&gt;In &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/clojure/clojure/blob/653b8465845a78ef7543e0a250078eea2d56b659/src/jvm/clojure/lang/Namespace.java#L224-L225&quot;&gt;https://github.com/clojure/clojure/blob/653b8465845a78ef7543e0a250078eea2d56b659/src/jvm/clojure/lang/Namespace.java#L224-L225&lt;/a&gt;, the &lt;code&gt;ns&lt;/code&gt; argument is not included in the exception message.&lt;/p&gt;
&lt;p&gt;This hinders debuggabiliity, especially when the &lt;code&gt;.addAlias&lt;/code&gt; call didn't originate from intentful aliasing, but rather, as a result of re-evaluating a namespace (which is the AST-building strategy that tools such as &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/jonase/eastwood&quot;&gt;https://github.com/jonase/eastwood&lt;/a&gt; use).&lt;/p&gt;
&lt;p&gt;Have you considered improving the message?&lt;/p&gt;
</description>
<category>Errors</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/8705/namespace-java-addalias-exception-could-more-informative</guid>
<pubDate>Thu, 10 Oct 2019 15:55:01 +0000</pubDate>
</item>
</channel>
</rss>