<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Clojure Q&amp;A - Recent questions tagged clojure</title>
<link>https://ask.clojure.org/index.php/tag/clojure</link>
<description></description>
<item>
<title>&quot;Nested&quot; vs &quot;lateral&quot; exception causes</title>
<link>https://ask.clojure.org/index.php/15031/nested-vs-lateral-exception-causes</link>
<description>&lt;p&gt;Currently, &lt;code&gt;clojure.core/ex-info&lt;/code&gt; must take a &lt;code&gt;msg&lt;/code&gt; and data &lt;code&gt;map&lt;/code&gt;, and may take a &lt;code&gt;cause&lt;/code&gt;, which must be another &lt;code&gt;Throwable&lt;/code&gt;, which may have its own &lt;code&gt;cause&lt;/code&gt;, etc. etc..&lt;/p&gt;
&lt;p&gt;This supports the case of &quot;nested&quot; exceptions quite well, e.g. in the case of compilation exceptions being caused by macroexpansion exceptions, potentially with their own cause, and works well for fail-on-first-problem situations.&lt;/p&gt;
&lt;p&gt;There's also the situation of &quot;lateral&quot; exceptions, e.g. in the case of test runners or static analysers, which is not supported. In this case, if we take &lt;code&gt;lazytest&lt;/code&gt; as a concrete example, the test runner throws an exception if any of the test cases it runs throws an exception, but the overall cause of the overall exception, conceptually, is &lt;em&gt;all&lt;/em&gt; the individual exceptions.&lt;/p&gt;
&lt;p&gt;Currently, the only to do this is to make some bespoke thing in the data &lt;code&gt;map&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;I propose changing &lt;code&gt;clojure.core/ex-info&lt;/code&gt; to take &lt;code&gt;[msg map &amp;amp; causes]&lt;/code&gt;, which would be a non-breaking change (or, while we're at it, make the &lt;code&gt;map&lt;/code&gt; arg optional as well and default it to &lt;code&gt;{}&lt;/code&gt;, but that's a separate topic).&lt;/p&gt;
&lt;p&gt;That leaves the question of how to handle &lt;code&gt;ex-cause&lt;/code&gt;. To my understanding, to change it to return the cause or the list of causes, would maybe be a breaking change for general exception handling libraries or something, but would not imo pose any significant problem. Alternatively, we might have &lt;code&gt;ex-causes&lt;/code&gt; to always return a list, and change &lt;code&gt;ex-cause&lt;/code&gt; to &lt;code&gt;(comp first ex-causes)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Any thoughts? I don't trust myself to spearhead a PR alone on this but I'd love to contribute, certainly the pure-clojure side of things seems straightforward enough (and I'd love to patch this into &lt;code&gt;lazytest&lt;/code&gt;, but that's again a different topic).&lt;/p&gt;
</description>
<category>Errors</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/15031/nested-vs-lateral-exception-causes</guid>
<pubDate>Sun, 05 Apr 2026 14:18:26 +0000</pubDate>
</item>
<item>
<title>Optimize `eduction`</title>
<link>https://ask.clojure.org/index.php/15027/optimize-eduction</link>
<description>&lt;h2&gt;Problem statement&lt;/h2&gt;
&lt;p&gt;Eduction is useful part of the transducer ecosystem, which has a benefit/aim of improved performance. However, the function &lt;code&gt;eduction&lt;/code&gt; only has a single varargs arity, which adds multiple function calls and and &lt;code&gt;seq&lt;/code&gt; traversal allocations.&lt;/p&gt;
&lt;p&gt;As seen in &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/clj-kondo/clj-kondo/pull/2801&quot;&gt;this PR&lt;/a&gt; to clj-kondo, manually passing in an xform directly can improve both overall performance and lower allocations.&lt;/p&gt;
&lt;h2&gt;Proposal&lt;/h2&gt;
&lt;p&gt;Adding arities to &lt;code&gt;eduction&lt;/code&gt; can sidestep those allocations and seq traversals, improving baseline performance of all &lt;code&gt;eduction&lt;/code&gt; invocations.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(defn eduction2
  {:arglists '([xform* coll])
   :added &quot;1.7&quot;}
  ([coll] (-&amp;gt;Eduction identity coll))
  ([f1 coll] (-&amp;gt;Eduction f1 coll))
  ([f1 f2 coll] (-&amp;gt;Eduction (comp f1 f2) coll))
  ([f1 f2 f3 coll] (-&amp;gt;Eduction (comp f1 f2 f3) coll))
  ([f1 f2 f3 f4 &amp;amp; args]
   (-&amp;gt;Eduction (apply comp f1 f2 f3 f4 (butlast args)) (last args))))
&lt;/code&gt;&lt;/pre&gt;
</description>
<category>Transducers</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/15027/optimize-eduction</guid>
<pubDate>Fri, 03 Apr 2026 14:25:17 +0000</pubDate>
</item>
<item>
<title>Missing protocol error will hang on infinite `(range)` input in ClojureScript but not Clojure</title>
<link>https://ask.clojure.org/index.php/15026/missing-protocol-error-infinite-range-clojurescript-clojure</link>
<description>&lt;p&gt;functions like &lt;code&gt;transient&lt;/code&gt;, &lt;code&gt;assoc&lt;/code&gt;, etc  will throw helpful missing-protocol error when receiving invalid input but it will hang if it receives infinite &lt;code&gt;(range)&lt;/code&gt;.&lt;br&gt;
this is related to issue below&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://ask.clojure.org/index.php/14578/even-range-hangs?show=14578#q14578&quot;&gt;https://ask.clojure.org/index.php/14578/even-range-hangs?show=14578#q14578&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;however, missing-protocol only hang in clojurescript but not clojure so I am wondering if this difference is intended.&lt;/p&gt;
&lt;p&gt;example calls that should throws&lt;br&gt;
- &lt;code&gt;(transient (range))&lt;/code&gt;&lt;br&gt;
- &lt;code&gt;(assoc (range) :a 1)&lt;/code&gt;&lt;/p&gt;
</description>
<category>ClojureScript</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/15026/missing-protocol-error-infinite-range-clojurescript-clojure</guid>
<pubDate>Fri, 03 Apr 2026 11:16:47 +0000</pubDate>
</item>
<item>
<title>Does Clojure have an anti LLM code contributions policy? Would it make sense for Clojure to adopt one?</title>
<link>https://ask.clojure.org/index.php/15004/clojure-contributions-policy-would-make-sense-clojure-adopt</link>
<description>&lt;p&gt;LLM use appears to have a bunch of ethical and practical problems, the most pressing one seems to be the plagiarism that seems to be pretty excessive even for code and even when not baited:&lt;/p&gt;
&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/mastodon/mastodon/issues/38072#issuecomment-4105681567&quot;&gt;Video clip of apparently a lawyer live demoing what seems to be Co-Pilot plagiasm&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I don't know anything about law, but the lawyer at one point says: &quot;This is a copyright infringement.&quot; I've also found this: &lt;a rel=&quot;nofollow&quot; href=&quot;https://www.twobirds.com/en/insights/2025/landmark-ruling-of-the-munich-regional-court-(gema-v-openai)-on-copyright-and-ai-training&quot;&gt;https://www.twobirds.com/en/insights/2025/landmark-ruling-of-the-munich-regional-court-(gema-v-openai)-on-copyright-and-ai-training&lt;/a&gt; It seems to talk about &quot;fair use&quot; of AI model training.&lt;/p&gt;
&lt;p&gt;Also see this high-profile incident: &lt;a rel=&quot;nofollow&quot; href=&quot;https://www.pcgamer.com/software/ai/microsoft-uses-plagiarized-ai-slop-flowchart-to-explain-how-github-works-removes-it-after-original-creator-calls-it-out-careless-blatantly-amateuristic-and-lacking-any-ambition-to-put-it-gently/&quot;&gt;https://www.pcgamer.com/software/ai/microsoft-uses-plagiarized-ai-slop-flowchart-to-explain-how-github-works-removes-it-after-original-creator-calls-it-out-careless-blatantly-amateuristic-and-lacking-any-ambition-to-put-it-gently/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Also this field study that appears to be putting the plagiarism rate at seemingly at least 2-5%: &lt;a rel=&quot;nofollow&quot; href=&quot;https://dl.acm.org/doi/10.1145/3543507.3583199&quot;&gt;https://dl.acm.org/doi/10.1145/3543507.3583199&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;This article mentions a study that apparently puts the plagiarism rate at 8–15% as a minimum for the easily detectable kind: &lt;a rel=&quot;nofollow&quot; href=&quot;https://www.theatlantic.com/technology/2026/01/ai-memorization-research/685552/&quot;&gt;https://www.theatlantic.com/technology/2026/01/ai-memorization-research/685552/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I don't know what this means legally, but at least morally and ethically this seems sad.&lt;/p&gt;
&lt;p&gt;Apparently, some people in the Clojure space already spoke out against LLMs, but I wasn't able to find any anti LLM policy. If there was such a policy, I would expect it to be mentioned in the following places:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://clojure.org/dev/developing_patches&quot;&gt;https://clojure.org/dev/developing_patches&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://clojure.org/community/contributing&quot;&gt;https://clojure.org/community/contributing&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;I simply wanted to suggest that perhaps the project may want to adopt such a policy.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Here are some other projects that have already done so: &lt;a rel=&quot;nofollow&quot; href=&quot;https://asahilinux.org/docs/project/policies/slop/&quot;&gt;Asahi Linux&lt;/a&gt;, &lt;a rel=&quot;nofollow&quot; href=&quot;https://docs.elementary.io/contributor-guide/development/generative-ai-policy&quot;&gt;elementaryOS&lt;/a&gt;, &lt;a rel=&quot;nofollow&quot; href=&quot;https://codeberg.org/forgejo/governance/src/commit/19ef60442456b92156a242ad1bbc1bcda98bef3b/AIAgreement.md#agreement&quot;&gt;Forgejo&lt;/a&gt;, &lt;a rel=&quot;nofollow&quot; href=&quot;https://gitlab.gnome.org/World/gedit/gedit/-/blob/master/docs/guidelines/no-llm-tools.md?ref_type=heads&quot;&gt;Gedit&lt;/a&gt;,  &lt;a rel=&quot;nofollow&quot; href=&quot;https://wiki.gentoo.org/wiki/Project:Council/AI_policy&quot;&gt;Gentoo&lt;/a&gt;, &lt;a rel=&quot;nofollow&quot; href=&quot;https://gitlab.gnome.org/GNOME/gimp/-/blob/master/.gitlab/merge_request_templates/default.md?plain=1#L11-12&quot;&gt;GIMP&lt;/a&gt;, &lt;a rel=&quot;nofollow&quot; href=&quot;https://codeberg.org/superseriousbusiness/gotosocial/src/branch/main/CODE_OF_CONDUCT.md#code-of-conduct&quot;&gt;GoToSocial&lt;/a&gt;, &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/love2d/love/commit/147d39251c2618852c026f8cadf95f0ffd6a746f&quot;&gt;Löve2D&lt;/a&gt;, &lt;a rel=&quot;nofollow&quot; href=&quot;https://discourse.gnome.org/t/loupe-no-longer-allows-generative-ai-contributions/27327&quot;&gt;Loupe&lt;/a&gt;, &lt;a rel=&quot;nofollow&quot; href=&quot;https://www.netbsd.org/developers/commit-guidelines.html&quot;&gt;NetBSD&lt;/a&gt;, &lt;a rel=&quot;nofollow&quot; href=&quot;https://docs.postmarketos.org/policies-and-processes/development/contributing-and-ai.html&quot;&gt;postmarketOS&lt;/a&gt;, &lt;a rel=&quot;nofollow&quot; href=&quot;https://www.qemu.org/docs/master/devel/code-provenance.html#use-of-ai-generated-content&quot;&gt;Qemu&lt;/a&gt;, &lt;a rel=&quot;nofollow&quot; href=&quot;https://gitlab.redox-os.org/redox-os/redox/-/blob/master/CONTRIBUTING.md#ai-policy&quot;&gt;RedoxOS&lt;/a&gt;, &lt;a rel=&quot;nofollow&quot; href=&quot;https://book.servo.org/contributing/getting-started.html#ai-contributions&quot;&gt;Servo&lt;/a&gt;, &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/nothings/stb/blob/master/CONTRIBUTING.md#ai-and-llm-are-forbidden&quot;&gt;stb libraries&lt;/a&gt;, &lt;a rel=&quot;nofollow&quot; href=&quot;https://ziglang.org/code-of-conduct/#strict-no-llm-no-ai-policy&quot;&gt;Zig&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;My deepest apologies if there already is such a policy, or if I'm asking in the wrong space.&lt;/p&gt;
</description>
<category>Meta</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/15004/clojure-contributions-policy-would-make-sense-clojure-adopt</guid>
<pubDate>Sun, 29 Mar 2026 13:14:25 +0000</pubDate>
</item>
<item>
<title>Why doesn't defn also implicitly name the anonymous function it defines for recursion?</title>
<link>https://ask.clojure.org/index.php/15000/doesnt-defn-implicitly-anonymous-function-defines-recursion</link>
<description>&lt;p&gt;Why doesn't &lt;code&gt;defn&lt;/code&gt; implicitly name the function to create a named recursion point?&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(clojure.walk/macroexpand-all
  '(defn foo [x]
     (foo x)))
; =&amp;gt;
(def foo
  (fn*
    ([x]
     (foo x))))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This could instead expand to&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(def foo
  (fn* foo ; note the foo here
    ([x]
     (foo x))))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;How it works right now, &lt;code&gt;foo&lt;/code&gt; resolves to a global var &lt;code&gt;#'foo&lt;/code&gt;, which is created when the &lt;code&gt;(def ...)&lt;/code&gt; form is analyzed. In the second case, it resolves directly to the function object. Thus, it should save us a var dereference at runtime in this case.&lt;/p&gt;
&lt;p&gt;EDIT: Found out, this is exactly what &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojure.org/reference/compilation#directlinking&quot;&gt;direct linking&lt;/a&gt; is used for.&lt;/p&gt;
</description>
<category>Macros</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/15000/doesnt-defn-implicitly-anonymous-function-defines-recursion</guid>
<pubDate>Sat, 21 Mar 2026 13:49:43 +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>bit-count in cljs but not clj</title>
<link>https://ask.clojure.org/index.php/14917/bit-count-in-cljs-but-not-clj</link>
<description>&lt;p&gt;The &lt;code&gt;bit-count&lt;/code&gt; function ships as part of CLJS but not CLJ, which means I end up using a reader conditional to use &lt;code&gt;Long/bitCount&lt;/code&gt; on the JVM side when I write cljc files. It would be nice if I could just use &lt;code&gt;bit-count&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;(I chose &quot;compiler&quot; for category because there's no option for &quot;standard library&quot;) &lt;/p&gt;
</description>
<category>Compiler</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14917/bit-count-in-cljs-but-not-clj</guid>
<pubDate>Fri, 30 Jan 2026 09:21:40 +0000</pubDate>
</item>
<item>
<title>How to force clojure.spec generator to skip a field</title>
<link>https://ask.clojure.org/index.php/14893/how-to-force-clojure-spec-generator-to-skip-a-field</link>
<description>&lt;pre&gt;&lt;code&gt;(gen/let [x (s/gen (s/keys :opt [::a]))
          y (s/gen (s/keys :opt [::a]) {::a ???})])
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If &lt;code&gt;x&lt;/code&gt; generates without &lt;code&gt;::a&lt;/code&gt;, I'd also like to generate &lt;code&gt;y&lt;/code&gt; without &lt;code&gt;::a&lt;/code&gt;.  I can't presently see a way to express that.&lt;/p&gt;
</description>
<category>Spec</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14893/how-to-force-clojure-spec-generator-to-skip-a-field</guid>
<pubDate>Thu, 15 Jan 2026 07:58:46 +0000</pubDate>
</item>
<item>
<title>clojure.core/subs should use type hints of ^CharSequence, NOT ^String</title>
<link>https://ask.clojure.org/index.php/14889/clojure-core-subs-should-use-type-hints-charsequence-string</link>
<description>&lt;p&gt;This is related to &lt;a rel=&quot;nofollow&quot; href=&quot;https://ask.clojure.org/index.php/4616/clojure-interfaces-specify-charsequence-instead-possible&quot;&gt;this ancient ask&lt;/a&gt;, but it would be ideal if &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojuredocs.org/clojure.core/subs&quot;&gt;&lt;code&gt;clojure.core/subs&lt;/code&gt;&lt;/a&gt; was type hinted with &lt;code&gt;^CharSequence&lt;/code&gt; rather than &lt;code&gt;^String&lt;/code&gt;, and used the &lt;code&gt;subSequence()&lt;/code&gt; method instead of &lt;code&gt;substring()&lt;/code&gt; (since the latter doesn't exist in &lt;code&gt;CharSequence&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;The single parameter version of &lt;code&gt;subs&lt;/code&gt; would need to call &lt;code&gt;s.length()&lt;/code&gt; as the second argument in the call to &lt;code&gt;subSequence()&lt;/code&gt; (there is no single-arg version of that method, unlike &lt;code&gt;substring()&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;More generally, there are substantial benefits in using &lt;code&gt;CharSequence&lt;/code&gt; instead of &lt;code&gt;String&lt;/code&gt; throughout Clojure core, not only in the context of Java interop, but also when using custom String-like data structures (e.g. &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/IGJoshua/ropes&quot;&gt;ropes&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;[edit] @alexmiller mentioned this in another forum (and I'm capturing it here for posterity), but this might also require that the result be &lt;code&gt;str&lt;/code&gt;ed, to ensure the return type remains unchanged (&lt;code&gt;subSequence()&lt;/code&gt; returns a &lt;code&gt;CharSequence&lt;/code&gt;, unlike &lt;code&gt;substring&lt;/code&gt;, which might break callers).  There may be performance implications of adding that call for types other than &lt;code&gt;String&lt;/code&gt; (but existing callers should be unaffected, since &lt;code&gt;String.toString()&lt;/code&gt; is identity).&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14889/clojure-core-subs-should-use-type-hints-charsequence-string</guid>
<pubDate>Tue, 13 Jan 2026 18:10:48 +0000</pubDate>
</item>
<item>
<title>Literals for Unicode code points (and perhaps also sequences thereof)</title>
<link>https://ask.clojure.org/index.php/14875/literals-unicode-code-points-perhaps-also-sequences-thereof</link>
<description>&lt;p&gt;&lt;strong&gt;Context&lt;/strong&gt;&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.oracle.com/technical-resources/articles/javase/supplementary.html&quot;&gt;For historical reasons&lt;/a&gt; the JVM type system's support for Unicode code points is poor, and while this is usually invisible to the developer it becomes a hassle when String literals containing non-Latin1 code points are used in code.  It also becomes particularly problematic when cross-platform (cljc) code is attempting to do this, since other platforms may not share this historical oddity so solutions that &quot;work&quot; in ClojureJVM may break in other dialects.&lt;/p&gt;
&lt;p&gt;For example, the &lt;a rel=&quot;nofollow&quot; href=&quot;https://emojipedia.org/transgender-flag#technical&quot;&gt;transgender flag emoji&lt;/a&gt; (a single grapheme cluster that happens to be defined by 5 Unicode code points) cannot easily be constructed at the REPL or in a source file without detailed knowledge of the JVM's history (and associated knowledge of UTF-16, an increasingly obsolete character encoding).&lt;/p&gt;
&lt;p&gt;Using the documented code points for this grapheme cluster with the JVM's Unicode escaping mechanism does &lt;em&gt;not&lt;/em&gt; give the expected outcome:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://i.ibb.co/gM2XsWBG/Screenshot-2026-01-12-at-11-13-38-AM.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;The correct, but unintuitive solution is to remember that the JVM does not directly support Unicode code points in the supplemental planes, and then to translate the supplemental code point &lt;code&gt;U+1F3F3&lt;/code&gt; into its UTF-16 code unit / surrogate pair representation:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://i.ibb.co/60b1ZLXh/Screenshot-2026-01-12-at-11-15-56-AM.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Note: I had to use screenshots for this, since ask.clojure doesn't appear to support Unicode supplemental code points properly either...&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Question/request/proposal&lt;/strong&gt;&lt;br&gt;
Clojure can sidestep this issue in a purely accretive manner, providing better consistency across the JVM and other runtimes, by adding direct support for Unicode literals.&lt;/p&gt;
&lt;p&gt;This would involve adding a new literal syntax that represents a single Unicode code point, and perhaps also a new literal syntax that represents a sequence of Unicode code points (perhaps supporting not only the novel Unicode code point literal, but also the existing Character and String literals).  Both of these new literals would produce a standard JVM (or JavaScript, or ...) String object, in whatever native encoding those objects employ on their respective platforms - after such literals are read, it's all just the extant String data type - there is no runtime impact.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;An &lt;em&gt;example&lt;/em&gt; literal syntax&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;While I am not proposing a specific syntax for these new literals here (though such a task is a necessary step), for illustrative purposes here is an example of what these literals &lt;em&gt;might&lt;/em&gt; approximately look like:&lt;/p&gt;
&lt;p&gt;Single Unicode code point literals:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;#U+0061&lt;/code&gt;: produces a String containing the Latin letter a: &lt;code&gt;&quot;a&quot;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;#U+1F921&lt;/code&gt;: produces a String containing &lt;a rel=&quot;nofollow&quot; href=&quot;https://www.compart.com/en/unicode/U+1F921&quot;&gt;the clown emoji&lt;/a&gt; (which ask.clojure cannot display)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Sequences of Unicode code point literals:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;#U+[U+0061 U+0020 U+1F921]&lt;/code&gt;: produces the 3 grapheme cluster String: &lt;code&gt;&quot;a &amp;lt;clown emoji&amp;gt;&quot;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;#U+[&quot;a &quot; U+1F921]&lt;/code&gt;: produces the same String, but demonstrates why it may be useful to support a mix of literals within the sequence (for readability)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;#U+[\a \space U+1F921]&lt;/code&gt;: ditto&lt;/li&gt;
&lt;li&gt;&lt;code&gt;#U+[U+1F3F3 U+FE0F U+200D U+26A7 U+FE0F]&lt;/code&gt;: produces a String containing a single grapheme cluster (the transgender flag emoji)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This final example is an ideal test case, since the transgender flag emoji is a single Unicode grapheme cluster, defined by 5 Unicode code points, but on the JVM (for the historical reason listed originally) is made up of &lt;em&gt;6&lt;/em&gt; Characters.&lt;/p&gt;
&lt;p&gt;Note that the sequence literal may not be necessary, since &lt;code&gt;str&lt;/code&gt; could be used with the single code point literal syntax; e.g. &lt;code&gt;(str #U+1F3F3 #U+FE0F #U+200D #U+26A7 #U+FE0F)&lt;/code&gt;.  Whether shifting the cost of string concatenation from read-time to runtime matters or not is another topic worthy of deeper consideration.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Other notes&lt;/strong&gt;&lt;br&gt;
Orthogonal to this proposal (at least from a Clojure core perspective; from a user perspective they're closely related), it would also be useful if Clojure core (perhaps in the &lt;code&gt;clojure.string&lt;/code&gt; namespace) had functions to turn Strings into sequences of code points (as integers) and vice versa.  Both the JVM and JavaScript provide native APIs for doing this (and presumably other platforms do too), but providing these as standard functions in Clojure core (similar to what was done with &lt;code&gt;parse-long&lt;/code&gt;, &lt;code&gt;parse-double&lt;/code&gt;, and &lt;code&gt;parse-boolean&lt;/code&gt; in Clojure v1.11) has value and is also purely accretive.&lt;/p&gt;
</description>
<category>Syntax and reader</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14875/literals-unicode-code-points-perhaps-also-sequences-thereof</guid>
<pubDate>Mon, 12 Jan 2026 20:02:41 +0000</pubDate>
</item>
<item>
<title>Why does the REPL incorrectly display my command after I press enter?</title>
<link>https://ask.clojure.org/index.php/14848/why-does-repl-incorrectly-display-command-after-press-enter</link>
<description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;I'm having a small bug with the Clojure REPL - when I enter a command, after pressing the enter key, the command gets displayed incorrectly - basically the beginning of the text of the command that I entered is displayed for the first few characters, and then everything after that is overwritten with the same text of the command displayed with an indentation.&lt;/p&gt;
&lt;p&gt;Not sure if that's very clear, so I've added a pair of screenshots, &quot;before and after&quot;, to illustrate.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://arielche.net/clojurereplbugbefore.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://arielche.net/clojurereplbugafter.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;This issue seems similar to &lt;a rel=&quot;nofollow&quot; href=&quot;https://ask.clojure.org/index.php/10025/have-prompts-previous-lines-command-started-disappearing&quot;&gt;this older question&lt;/a&gt;, although in that case the issue was with the &lt;code&gt;rlwrap&lt;/code&gt; library, which was patched afterwards.&lt;/p&gt;
&lt;p&gt;Is there a way to fix this?&lt;/p&gt;
</description>
<category>REPL</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14848/why-does-repl-incorrectly-display-command-after-press-enter</guid>
<pubDate>Mon, 22 Dec 2025 15:01:06 +0000</pubDate>
</item>
<item>
<title>Octal escape sequence decoding in strings does not stop at non-octal digit</title>
<link>https://ask.clojure.org/index.php/14846/octal-escape-sequence-decoding-strings-does-stop-octal-digit</link>
<description>&lt;p&gt;Strings suppose to support standard Java escape sequences, including octal escape sequence: [0-7]{1,3} &lt;/p&gt;
&lt;p&gt;In Java decoding of octal sequences stop at the first non-octal digit or any other character if there are 1 or two octal digits in the escape sequence. For example:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;jshell&amp;gt; &quot;\18&quot;
$1 ==&amp;gt; &quot;\0018&quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;But Clojure reads up to 3 potentially octal digits greedily resulting in wrongly consuming non-octal digits:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Clojure 1.12.4
user=&amp;gt; &quot;\18&quot;
Syntax error reading source at (REPL:1:5).
Invalid digit: 8
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;non-octal characters:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Clojure 1.12.4
user=&amp;gt; &quot;\1d&quot;
Syntax error reading source at (REPL:1:5).
Invalid digit: d
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And succeed only when there is line terminator or exact three octal digits in supported octal range:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Clojure 1.12.4
user=&amp;gt; &quot;\1&quot;
&quot;&quot;
user=&amp;gt; &quot;\1&quot;
&quot;&quot;
user=&amp;gt; &quot;\12&quot;
&quot;\n&quot;
user=&amp;gt; &quot;\123&quot;
&quot;S&quot;
user=&amp;gt; &quot;\123d&quot;
&quot;Sd&quot;
&lt;/code&gt;&lt;/pre&gt;
</description>
<category>Syntax and reader</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14846/octal-escape-sequence-decoding-strings-does-stop-octal-digit</guid>
<pubDate>Thu, 18 Dec 2025 09:35:53 +0000</pubDate>
</item>
<item>
<title>[clojure.edn] Leading zeros in numbers</title>
<link>https://ask.clojure.org/index.php/14798/clojure-edn-leading-zeros-in-numbers</link>
<description>&lt;p&gt;clojure.edn allow leading zeros ending up reading such number as octal representation. The problem is that it is also allowed to have indefinite amount of leading zeros for octals:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;000000000000042  ;; =&amp;gt; 34
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and when there is a suffix &quot;M&quot; that forces floating point representation the same string become float 42 stripping all leading zeros.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;000000000000042M ;; =&amp;gt; 42M
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;At the same time EDN specification forbids integers with leading zeros at all even for floats.&lt;br&gt;
I found a ticket about leading zeros in data.json but I think it should be expanded to cover clojure as well.&lt;/p&gt;
&lt;p&gt;In the same scope but origin is in the EDN spec:&lt;br&gt;
float specification allows leading zeroes in exponent and only zeros in fractional parts:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;0.00000000...00
0.0e0001
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;probably because of that clojure.edn read such numbers without error too. &lt;/p&gt;
</description>
<category>Syntax and reader</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14798/clojure-edn-leading-zeros-in-numbers</guid>
<pubDate>Thu, 04 Dec 2025 13:31:23 +0000</pubDate>
</item>
<item>
<title>Double colon (&quot;::&quot;) in the middle or at the end of identifier.</title>
<link>https://ask.clojure.org/index.php/14787/double-colon-in-the-middle-or-at-the-end-of-identifier</link>
<description>&lt;p&gt;Right now double colon is allowed only when used as a start of not empty identifier prefix. I wonder is there some explanation why it is forbidden anywhere else?&lt;/p&gt;
&lt;p&gt;I found original commit, where this was introduced. &lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/clojure/clojure/commit/005ea1b5f96c5bb762e155032a865e29ad71bcf3&quot;&gt;https://github.com/clojure/clojure/commit/005ea1b5f96c5bb762e155032a865e29ad71bcf3&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;But commit message has no explanation why it allows only non-repeating colon&lt;/p&gt;
</description>
<category>Syntax and reader</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14787/double-colon-in-the-middle-or-at-the-end-of-identifier</guid>
<pubDate>Thu, 27 Nov 2025 12:15:33 +0000</pubDate>
</item>
<item>
<title>Macro expansion lose type hints</title>
<link>https://ask.clojure.org/index.php/14740/macro-expansion-lose-type-hints</link>
<description>&lt;p&gt;The following snippet demonstrate how type hints when put before a macro expression are being lost.&lt;br&gt;
On the first expression, the compiler correctly complains about the wrong type hint while it gets accepted if you wrap the hinted expression on a macro. &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ clj 
Clojure 1.12.3

user=&amp;gt; (import 'java.util.Date)

user=&amp;gt; (.setHours (Date.) ^long (.getHours (Date.)))
Syntax error (UnsupportedOperationException) compiling fn* at (REPL:1:1).
Cannot coerce int to long, use a cast instead

user=&amp;gt; (.setHours (Date.) ^long (-&amp;gt; (.getHours (Date.))))
nil
&lt;/code&gt;&lt;/pre&gt;
</description>
<category>Compiler</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14740/macro-expansion-lose-type-hints</guid>
<pubDate>Mon, 03 Nov 2025 13:50:41 +0000</pubDate>
</item>
<item>
<title>`pipeline-blocking` uses `thread` internally instead of `io-thread`</title>
<link>https://ask.clojure.org/index.php/14738/pipeline-blocking-uses-thread-internally-instead-of-thread</link>
<description>&lt;p&gt;&lt;code&gt;pipeline-blocking&lt;/code&gt; is explicitly meant for blocking operations (implying I/O). However, internally it uses &lt;code&gt;thread&lt;/code&gt; rather than &lt;code&gt;io-thread&lt;/code&gt; for processing: &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/clojure/core.async/blob/master/src/main/clojure/clojure/core/async.clj#L637-L640&quot;&gt;https://github.com/clojure/core.async/blob/master/src/main/clojure/clojure/core/async.clj#L637-L640&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Since 1.9.829-alpha2 this has practical implications, as only &lt;code&gt;io-thread&lt;/code&gt; will utilize virtual threads, when available.&lt;/p&gt;
&lt;p&gt;Can this be fixed / changed?&lt;br&gt;
If not, can an explicit &lt;code&gt;pipeline-io&lt;/code&gt; (or similar)  function be added to support this use case?&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;
</description>
<category>core.async</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14738/pipeline-blocking-uses-thread-internally-instead-of-thread</guid>
<pubDate>Wed, 29 Oct 2025 15:54:00 +0000</pubDate>
</item>
<item>
<title>clojure -X hangs with agent use</title>
<link>https://ask.clojure.org/index.php/14708/clojure-x-hangs-with-agent-use</link>
<description>&lt;p&gt;Given this repro:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(ns repro)

(defn exec-fn [_]
  (let [a (agent nil)]
    (prn (-&amp;gt; (java.lang.ProcessHandle/current) (.pid)))
    (send a (fn [_] 3))))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;the &lt;code&gt;clojure -X repro/exec-fn&lt;/code&gt; invocation is hanging.&lt;/p&gt;
&lt;p&gt;This seems to be unintentional, given that clojure -X doesn't wait for futures to finish either?&lt;/p&gt;
</description>
<category>Clojure</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14708/clojure-x-hangs-with-agent-use</guid>
<pubDate>Wed, 10 Sep 2025 21:02:32 +0000</pubDate>
</item>
<item>
<title>Can you help me choosing a book?</title>
<link>https://ask.clojure.org/index.php/14693/can-you-help-me-choosing-a-book</link>
<description>&lt;p&gt;Greetings,&lt;br&gt;
so I decided to learn Clojure, my background is Erlang. I am not working anymore in the IT industry.&lt;/p&gt;
&lt;p&gt;I want to learn Clojure for fun, in my spare time, and I love to use books for that.&lt;br&gt;
I love to build small projects while learning, not just theory.&lt;br&gt;
I see there are trillions of books, and I know it is a very subjective matter.&lt;/p&gt;
&lt;p&gt;I am looking for one good for beginners, and with a practical approach.&lt;br&gt;
Can you recommend one?&lt;/p&gt;
&lt;p&gt;I love &quot;Clojure for the Brave and True&quot;'s title and cover, and it also seems to build a project.&lt;/p&gt;
&lt;p&gt;Is that book still good in 2025?&lt;/p&gt;
&lt;p&gt;Cheers!&lt;/p&gt;
</description>
<category>Beginner</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14693/can-you-help-me-choosing-a-book</guid>
<pubDate>Tue, 26 Aug 2025 14:58:42 +0000</pubDate>
</item>
<item>
<title>select-keys on nil map</title>
<link>https://ask.clojure.org/index.php/14654/select-keys-on-nil-map</link>
<description>&lt;p&gt;I know that &lt;a rel=&quot;nofollow&quot; href=&quot;https://ask.clojure.org/index.php/1913/use-transients-with-select-keys-if-possible&quot;&gt;https://ask.clojure.org/index.php/1913/use-transients-with-select-keys-if-possible&lt;/a&gt; exists to optimize &lt;code&gt;select-keys&lt;/code&gt; for many keys, but I noticed that it does a lot of work even if the original map is &lt;code&gt;nil&lt;/code&gt;. Would there be interest in a patch that returns an empty map when given &lt;code&gt;nil&lt;/code&gt;? Something like:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(defn select-keys*
  &quot;Returns a map containing only those entries in map whose key is in keys&quot;
  {:added &quot;1.0&quot;
   :static true}
  [map keyseq]
  (if map
    (loop [ret {} keys (seq keyseq)]
      (if keys
        (let [entry (. clojure.lang.RT (find map (first keys)))]
          (recur
           (if entry
             (conj ret entry)
             ret)
           (next keys)))
        (with-meta ret (meta map))))
    {}))
&lt;/code&gt;&lt;/pre&gt;
</description>
<category>Collections</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14654/select-keys-on-nil-map</guid>
<pubDate>Fri, 01 Aug 2025 14:42:56 +0000</pubDate>
</item>
<item>
<title>Compiler-generated `foo__init.class` files lack `SourceFile` attribute</title>
<link>https://ask.clojure.org/index.php/14652/compiler-generated-fooinit-class-sourcefile-attribute</link>
<description>&lt;p&gt;Most .class files generated by Clojure contain the expected &lt;a rel=&quot;nofollow&quot; href=&quot;https://docs.oracle.com/javase/specs/jvms/se11/html/jvms-4.html#jvms-4.7.10&quot;&gt;SourceFile&lt;/a&gt; attribute (you can verify with &lt;code&gt;javap -v&lt;/code&gt;). But &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojure.org/reference/compilation#_compiling&quot;&gt;__init&lt;/a&gt; classfiles lack this metadata. I asked @alexmiller on Slack, and he suggested I bring it up here.&lt;/p&gt;
&lt;p&gt;The same appears to be true of classes generated via &lt;code&gt;proxy&lt;/code&gt;.&lt;/p&gt;
</description>
<category>Compiler</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14652/compiler-generated-fooinit-class-sourcefile-attribute</guid>
<pubDate>Thu, 31 Jul 2025 22:21:18 +0000</pubDate>
</item>
<item>
<title>Skip stacktrace creation in ExceptionInfo</title>
<link>https://ask.clojure.org/index.php/14634/skip-stacktrace-creation-in-exceptioninfo</link>
<description>&lt;p&gt;Many libraries and applications use exceptions as control flow or data collection, which allows for handling complex situations with more consistent and legible code. Some libraries use custom throwables (&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/IGJoshua/farolero&quot;&gt;IGJoshua/farolero&lt;/a&gt;, &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/NoahTheDuke/lazytest&quot;&gt;NoahTheDuke/lazytest&lt;/a&gt;) and some use ExceptionInfos (&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/scgilardi/slingshot/&quot;&gt;scgilardi/slingshot&lt;/a&gt;, &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/fmnoise/flow&quot;&gt;fmnoise/flow&lt;/a&gt;, &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/pangloss/pure-conditioning&quot;&gt;pangloss/pure-conditioning&lt;/a&gt;, &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/exoscale/ex&quot;&gt;exoscale/ex&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;One of the reasons that libraries reach for custom throwables is because they want to skip creation of a stack trace (which isn't used and would be thrown away immediately). Stack traces in Java are already fairly expensive to create, and then the filtering work done in &lt;code&gt;ExceptionInfo&lt;/code&gt; greatly increases that expense, making them much slower than needed. (There's an Ask about this but I can't find it.) This performance cost pressures developers to use custom throwables if their code will ever be used in a &quot;hot path&quot;, which harms portability and ease of development. (I want to write Clojure, not Java, and I want it to be usable in Clojurescript and Babashka and whatever other dialects might arise.)&lt;/p&gt;
&lt;p&gt;I know that there's a rejected Jira ticket (&lt;a rel=&quot;nofollow&quot; href=&quot;https://clojure.atlassian.net/browse/CLJ-2423&quot;&gt;CLJ-2423&lt;/a&gt;) for supporting the &quot;enableSuppression&quot; flag, but in light of these use-cases, I'd like to bring it up again.&lt;/p&gt;
</description>
<category>Clojure</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14634/skip-stacktrace-creation-in-exceptioninfo</guid>
<pubDate>Thu, 17 Jul 2025 14:46:52 +0000</pubDate>
</item>
<item>
<title>POSIX-style command line arguments in tools (-T)</title>
<link>https://ask.clojure.org/index.php/14608/posix-style-command-line-arguments-in-tools-t</link>
<description>&lt;p&gt;I have a couple command line tools written as libraries that I'd like to expose as proper Clojure Tools. They have classic &lt;a rel=&quot;nofollow&quot; href=&quot;https://www.gnu.org/prep/standards/html_node/Command_002dLine-Interfaces.html&quot;&gt;POSIX-style command line interfaces&lt;/a&gt;, relying on &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/clojure/tools.cli&quot;&gt;tools.cli&lt;/a&gt;. I could add an &lt;code&gt;-X&lt;/code&gt; kv-map interface, but there are a number of boolean flags that would not translate well to &lt;code&gt;:foo true&lt;/code&gt; style (such as arbitrary file paths).&lt;/p&gt;
&lt;p&gt;Is there a way to pass arbitrary arguments to a clojure Tool without using the kv-map style?&lt;/p&gt;
&lt;p&gt;And if not, would there be interest in a flag or option that would allow for such a thing?&lt;/p&gt;
</description>
<category>Clojure CLI</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14608/posix-style-command-line-arguments-in-tools-t</guid>
<pubDate>Thu, 03 Jul 2025 21:06:46 +0000</pubDate>
</item>
<item>
<title>Why does a qualified instance method call fails at compile time with NullPointerException if missing target</title>
<link>https://ask.clojure.org/index.php/14596/qualified-instance-compile-nullpointerexception-missing</link>
<description>&lt;p&gt;Has anyone else noticed a lot of Syntax error (NullPointerException) when using the new Class/.instanceMethod syntax? Specifically whenever I forget the first argument like &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(fn [] (String/.length))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;gets&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#error{:cause &quot;Cannot invoke \&quot;clojure.lang.Compiler$Expr.emit(clojure.lang.Compiler$C, clojure.lang.Compiler$ObjExpr, clojure.asm.commons.GeneratorAdapter)\&quot; because \&quot;this.target\&quot; is null&quot;,
       :via [{:type clojure.lang.Compiler$CompilerException,
              :message &quot;Syntax error compiling fn* at (/private/var/folders/cr/wpw7hgnx0jj9m33g28rtbpzc0000gn/T/form-init4871175438924650637.clj:1:1).&quot;,
              :data #:clojure.error{:phase :compile-syntax-check,
                                    :line 1,
                                    :column 1,
                                    :source &quot;/private/var/folders/cr/wpw7hgnx0jj9m33g28rtbpzc0000gn/T/form-init4871175438924650637.clj&quot;,
                                    :symbol fn*},
              :at [clojure.lang.Compiler analyzeSeq &quot;Compiler.java&quot; 7677]}
             {:type java.lang.NullPointerException,
              :message &quot;Cannot invoke \&quot;clojure.lang.Compiler$Expr.emit(clojure.lang.Compiler$C, clojure.lang.Compiler$ObjExpr, clojure.asm.commons.GeneratorAdapter)\&quot; because \&quot;this.target\&quot; is null&quot;,
              :at [clojure.lang.Compiler$InstanceMethodExpr emit &quot;Compiler.java&quot; 2060]}],
       :trace [[clojure.lang.Compiler$InstanceMethodExpr emit &quot;Compiler.java&quot; 2060]
               [clojure.lang.Compiler$BodyExpr emit &quot;Compiler.java&quot; 6723]
               [clojure.lang.Compiler$FnMethod doEmit &quot;Compiler.java&quot; 6243]
               [clojure.lang.Compiler$FnMethod emit &quot;Compiler.java&quot; 6045]
               [clojure.lang.Compiler$FnExpr emitMethods &quot;Compiler.java&quot; 4500]
               [clojure.lang.Compiler$ObjExpr compile &quot;Compiler.java&quot; 5136]
               [clojure.lang.Compiler$FnExpr parse &quot;Compiler.java&quot; 4662]
               [clojure.lang.Compiler analyzeSeq &quot;Compiler.java&quot; 7667]
               [clojure.lang.Compiler analyze &quot;Compiler.java&quot; 7360]
               [clojure.lang.Compiler analyze &quot;Compiler.java&quot; 7316]
               [clojure.lang.Compiler$BodyExpr$Parser parse &quot;Compiler.java&quot; 6683]
               [clojure.lang.Compiler$FnMethod parse &quot;Compiler.java&quot; 6022]
               [clojure.lang.Compiler$FnExpr parse &quot;Compiler.java&quot; 4585]
               [clojure.lang.Compiler analyzeSeq &quot;Compiler.java&quot; 7667]
               [clojure.lang.Compiler analyze &quot;Compiler.java&quot; 7360]
               [clojure.lang.Compiler eval &quot;Compiler.java&quot; 7736]
               [clojure.lang.Compiler eval &quot;Compiler.java&quot; 7694]
               [clojure.core$eval invokeStatic &quot;core.clj&quot; 3232]
               [clojure.core$eval invoke &quot;core.clj&quot; 3228]
               [nrepl.middleware.interruptible_eval$evaluate$fn__966$fn__967 invoke &quot;interruptible_eval.clj&quot; 87]
               [clojure.lang.AFn applyToHelper &quot;AFn.java&quot; 152]
               [clojure.lang.AFn applyTo &quot;AFn.java&quot; 144]
               [clojure.core$apply invokeStatic &quot;core.clj&quot; 667]
               [clojure.core$with_bindings_STAR_ invokeStatic &quot;core.clj&quot; 1990]
               [clojure.core$with_bindings_STAR_ doInvoke &quot;core.clj&quot; 1990]
               [clojure.lang.RestFn invoke &quot;RestFn.java&quot; 428]
               [nrepl.middleware.interruptible_eval$evaluate$fn__966 invoke &quot;interruptible_eval.clj&quot; 87]
               [clojure.main$repl$read_eval_print__9248$fn__9251 invoke &quot;main.clj&quot; 437]
               [clojure.main$repl$read_eval_print__9248 invoke &quot;main.clj&quot; 437]
               [clojure.main$repl$fn__9257 invoke &quot;main.clj&quot; 459]
               [clojure.main$repl invokeStatic &quot;main.clj&quot; 459]
               [clojure.main$repl doInvoke &quot;main.clj&quot; 368]
               [clojure.lang.RestFn invoke &quot;RestFn.java&quot; 1526]
               [nrepl.middleware.interruptible_eval$evaluate invokeStatic &quot;interruptible_eval.clj&quot; 84]
               [nrepl.middleware.interruptible_eval$evaluate invoke &quot;interruptible_eval.clj&quot; 56]
               [nrepl.middleware.interruptible_eval$interruptible_eval$fn__997$fn__1001
                invoke
                &quot;interruptible_eval.clj&quot;
                152]
               [clojure.lang.AFn run &quot;AFn.java&quot; 22]
               [nrepl.middleware.session$session_exec$main_loop__1065$fn__1069 invoke &quot;session.clj&quot; 202]
               [nrepl.middleware.session$session_exec$main_loop__1065 invoke &quot;session.clj&quot; 201]
               [clojure.lang.AFn run &quot;AFn.java&quot; 22]
               [java.lang.Thread run &quot;Thread.java&quot; 1447]]}
&lt;/code&gt;&lt;/pre&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14596/qualified-instance-compile-nullpointerexception-missing</guid>
<pubDate>Mon, 30 Jun 2025 13:33:36 +0000</pubDate>
</item>
<item>
<title>Using letfn* for defining corecursive reified implementations</title>
<link>https://ask.clojure.org/index.php/14592/using-letfn-defining-corecursive-reified-implementations</link>
<description>&lt;p&gt;I was finding a way to have co-recursive reified instances, and after looking at the implementation of &lt;code&gt;clojure.lang.Compiler&lt;/code&gt; I've found out that this can actually be achieved with &lt;code&gt;letfn*&lt;/code&gt;. Consider the following proof-of-concept:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(defmacro thunk [&amp;amp; body]
  `(reify* [clojure.lang.IFn]
      (invoke [this] ~@body)))

(letfn* [g (thunk (+ 1 2 3 (f)))
         f (thunk (+ 1 2 3))]
    (f))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This works, and seems to be faster than other state-based approaches (e.g. using &lt;code&gt;atom&lt;/code&gt; to resolve forward declarations). &lt;/p&gt;
&lt;p&gt;This said, I recognize that this may not be standard behavior. for instance using &lt;code&gt;(reify* ...)&lt;/code&gt; directly in the &lt;code&gt;letfn*&lt;/code&gt; bindings will cause the &lt;code&gt;reify*&lt;/code&gt; block to be parsed as a &lt;code&gt;MetaExpr&lt;/code&gt; which breaks a cast in the implementation of &lt;code&gt;LetFnExpr&lt;/code&gt;. For example:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(letfn* [g (reify* [clojure.lang.IFn] (invoke [this] (+ 1 2 3 (f))))
         f (reify* [clojure.lang.IFn] (invoke [this] (+ 1 2 3)))] 
  (f))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;But since this would implicitly add metadata to the &lt;code&gt;reify*&lt;/code&gt; forms we get this error:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;class clojure.lang.Compiler$MetaExpr cannot be cast to class clojure.lang.Compiler$ObjExpr (clojure.lang.Compiler$MetaExpr and clojure.lang.Compiler$ObjExpr are in unnamed module of loader 'app')
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The only way I've managed to create a &lt;code&gt;reify*&lt;/code&gt; form without metadata is by creating the form in macro, such as the &lt;code&gt;thunk&lt;/code&gt; macro defined in the first example.&lt;/p&gt;
&lt;p&gt;Is using &lt;code&gt;reify*&lt;/code&gt; within &lt;code&gt;letfn*&lt;/code&gt; bindings supported? If not, are there any other methods that avoid mutable state that could be employed in similar cases? &lt;/p&gt;
</description>
<category>Compiler</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14592/using-letfn-defining-corecursive-reified-implementations</guid>
<pubDate>Fri, 27 Jun 2025 10:38:18 +0000</pubDate>
</item>
<item>
<title>Idiomatic way to use java.util.Optional</title>
<link>https://ask.clojure.org/index.php/14501/idiomatic-way-to-use-java-util-optional</link>
<description>&lt;p&gt;Is there an easy way to work with &lt;code&gt;java.utils.Optional&lt;/code&gt; values in Clojure? I'm currently using 1.12 so I can say things like &lt;code&gt;(Optional/.orElse foo nil)&lt;/code&gt; to convert the optional value to a &quot;normal&quot; value (X or nil), but that and other Optional methods are still sources of tension or boilerplate compared idiomatic Clojure constructs (&lt;code&gt;some-&amp;gt;&lt;/code&gt; for example).&lt;/p&gt;
&lt;p&gt;If such a way doesn't currently exist, can it be considered for addition to Clojure? Maybe opening up &lt;code&gt;deref&lt;/code&gt; to work on Optionals as well.&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14501/idiomatic-way-to-use-java-util-optional</guid>
<pubDate>Mon, 07 Apr 2025 14:16:59 +0000</pubDate>
</item>
<item>
<title>Why is shuffle not nil-safe?</title>
<link>https://ask.clojure.org/index.php/14479/why-is-shuffle-not-nil-safe</link>
<description>&lt;p&gt;Shuffling an empty collection is fine:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;user&amp;gt; (shuffle [])
[]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;But shuffling &lt;code&gt;nil&lt;/code&gt; results in NPE:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;user&amp;gt; (shuffle nil)
Execution error (NullPointerException) at java.util.ArrayList/&amp;lt;init&amp;gt; (ArrayList.java:181).
Cannot invoke &quot;java.util.Collection.toArray()&quot; because &quot;c&quot; is null
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Why is it not nil-safe like other seq ops?&lt;/p&gt;
</description>
<category>Clojure</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14479/why-is-shuffle-not-nil-safe</guid>
<pubDate>Wed, 26 Mar 2025 14:04:15 +0000</pubDate>
</item>
<item>
<title>Can we add metaphors/analogies for functional closures in Clojure to the docs please?</title>
<link>https://ask.clojure.org/index.php/14472/metaphors-analogies-functional-closures-clojure-docs-please</link>
<description>&lt;p&gt;Hi,&lt;br&gt;
Having been a longtime happy and satisfied user of Clojure I realized that there is very little to introduce someone new to Clojure to &lt;strong&gt;closures&lt;/strong&gt;  where functions [like vehicles] are passed in with opaqueness to their variables [like passengers] to another function.  I think this is probably a stumbling block for many beginners and might even, unfortunately, discourage people from adopting the language without further explanation of this caveat.  I think many programmers will also disagree with my assessment because they have &quot;closure eyes&quot; and can transparently understand passing functions around as first-class-citizens so-to-speak.  &lt;/p&gt;
&lt;p&gt;I propose that we amend the documentation to explicitly mention that closures are basically like vehicles or cars with passengers.  &lt;/p&gt;
&lt;p&gt;&lt;code&gt;the fact that not everything is transparent to the top level function call is something non-obvious &lt;/code&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;pre&gt;&lt;code&gt;(defn make-adder [x]
 (fn [y] (+ x y)))

(def add5 (make-adder 5))
 (add5 10) ;; Returns 15
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In this example:&lt;/p&gt;
&lt;p&gt;make-adder is like a vehicle factory. When you call it with 5, it creates a new vehicle.&lt;br&gt;
This new vehicle (the returned function) has a permanent passenger: the value 5 is sitting in the x seat.&lt;/p&gt;
&lt;p&gt;There's one empty seat (y) that you can fill when you drive the vehicle (call the function).&lt;/p&gt;
&lt;p&gt;When you call (add5 10), you're putting 10 in the y seat and driving the vehicle.&lt;/p&gt;
&lt;p&gt;Inside, the passengers interact: x (which is 5) and y (which is 10) are added together.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;How REPLs and Closures Intertwine&lt;br&gt;
The REPL (Read-Eval-Print-Loop) and closures interact in interesting ways:&lt;/p&gt;
&lt;p&gt;Creation and Persistence:&lt;br&gt;
When you define (def add5 (make-adder 5)) in the REPL, you're parking a vehicle (with 5 already inside) in your garage with the name &quot;add5&quot;. This vehicle persists between REPL evaluations.&lt;br&gt;
Inspection Limitations:&lt;br&gt;
In the REPL, you can see that add5 is a function, but you can't directly inspect who's sitting inside it. If you evaluate add5, you'll just see something like &lt;code&gt;#function[user/make-adder/fn--123].&lt;/code&gt;&lt;br&gt;
Usage in REPL:&lt;br&gt;
You can use the closure by calling it: (add5 10). The REPL will evaluate this by driving the vehicle with 10 in the y seat, and print the result (15).&lt;/p&gt;
</description>
<category>Docs</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14472/metaphors-analogies-functional-closures-clojure-docs-please</guid>
<pubDate>Thu, 20 Mar 2025 14:13:58 +0000</pubDate>
</item>
<item>
<title>core.async 1.8 beta1 cached thread pools can grow to hundreds of threads when doing io work</title>
<link>https://ask.clojure.org/index.php/14428/core-async-beta1-cached-thread-pools-hundreds-threads-doing</link>
<description>&lt;p&gt;Hi, I've been testing the new clojure.core.async 1.8.711-beta1, and suspected that since the default fixed thread pool was replaced with a cached thread pool, it could be possible for the system to create a very large number of OS threads, in the order of hundreds or thousands depending on the size of the workload.&lt;/p&gt;
&lt;p&gt;I am wondering if this was intended or if there might be a better middle-ground such as still using a CachedThreadPool but potentially accepting maximum sizes for each pool type via sys props, with reasonable defaults.&lt;/p&gt;
&lt;p&gt;Example code below:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(ns user)

(require '[clojure.core.async :as a]
         '[clojure.core.async.impl.dispatch :as d])

(defn do-work
  &quot;Simulate some async work which &quot;
  [task-count task-timeout]
  (a/go-loop [c (a/merge
                 (doall
                  (for [i (range task-count)]
                    (a/go
                      ;;; this simulates non-blocking park insdie the go-block
                      (a/&amp;lt;! (a/timeout
                             (rand-int task-timeout)))
                      ;;; this simulates blocking IO inside an io-thread
                      (a/&amp;lt;! (a/io-thread
                             (Thread/sleep
                              ^int (rand-int task-timeout))))
                      i))))]
    (let [v (a/&amp;lt;! c)]
      (if (nil? v)
        {:pool-size (.getPoolSize ^java.util.concurrent.ThreadPoolExecutor (d/executor-for :core-async-dispatch))}
        (recur c)))))

(def active
  (atom false))

(defn run-sim
  []
  (reset! active true)
  (a/go-loop [iter 1]
    (let [start (System/currentTimeMillis)
          {:keys [pool-size]} (a/&amp;lt;! (do-work
                                     2000  ;;; simulated number of tasks
                                     100)) ;;; simulated max delay in ms
          stop (System/currentTimeMillis)
          elapsed (- stop start)]
      (println &quot;Iteration:&quot; iter &quot;Pool Size:&quot; pool-size &quot;Elapsed:&quot; elapsed)
      (when (and @active
                 (&amp;lt; iter 10))
        (recur (inc iter))))))

(defn stop-sim
  []
  (reset! active false))

(comment
  (run-sim)   ;;; run the sim
  (stop-sim)) ;;; stop the sim
&lt;/code&gt;&lt;/pre&gt;
</description>
<category>Libs</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14428/core-async-beta1-cached-thread-pools-hundreds-threads-doing</guid>
<pubDate>Wed, 26 Feb 2025 18:54:58 +0000</pubDate>
</item>
<item>
<title>a) how: programmatically set REPL ‘context’ ‘prj-1 aware’? b) how: programmatically switch REPL ‘context’ ‘prj-n aware’?</title>
<link>https://ask.clojure.org/index.php/14422/programmatically-context-programmatically-switch-context</link>
<description>&lt;p&gt;Ok, regardless of editor, running &lt;em&gt;clj&lt;/em&gt; in a directory will start a repl that has &quot;project context&quot; to project deps.edn in &lt;em&gt;that&lt;/em&gt; directory, and that is the way that &lt;em&gt;most&lt;/em&gt; Clojure developers create a &lt;em&gt;connected&lt;/em&gt; repl.&lt;/p&gt;
&lt;p&gt;The implication seems to be to work on a &lt;em&gt;different&lt;/em&gt; project one must (System/exit 0) VM and start another VM using &lt;em&gt;clj&lt;/em&gt; command to ‘create a connected repl’ to project deps.edn in a different directory? This appears to be idiomatically (colloquially) referred to as ‘restarting the REPL’ I believe?&lt;/p&gt;
&lt;p&gt;Seems rather draconian for a dev env, let alone a lisp dev env? I thought the highly dynamic heritage of lisp replete with multiple REPLs was universally sought after? &lt;strong&gt;10 years later&lt;/strong&gt; and no multiple REPLs for clojure? Personally, I’m somewhat surprised, but maybe nobody really wants, needs or requires multiple clojure REPLs? I think multiple REPLs could be transformational in many use cases IMHO, or maybe I’m really ‘out of the loop’ no pun intended?&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;03-10-2015&lt;/strong&gt; Clojure stream socket repl discussion (&lt;a rel=&quot;nofollow&quot; href=&quot;https://groups.google.com/g/clojure-dev/c/Dl3Stw5iRVA/m/mgwvmEnjnBoJ&quot;&gt;https://groups.google.com/g/clojure-dev/c/Dl3Stw5iRVA/m/mgwvmEnjnBoJ&lt;/a&gt;) several notable sub-quotes:&lt;/p&gt;
&lt;p&gt;“I think it is important, with tooling, to have the broadest, open notion of the types of 'use cases' for Clojure, and for workflows of people using Clojure, lest you actually limit them. I hope people are able to write their languages and DSLs, test embedded control/debug consoles, design next-generation REPLs and debuggers, grab data dumps etc, all from their REPL. That's the heritage of Lisp. Many people are doing data science, languages, genetics, rule-systems etc type things with Clojure, not just web apps&lt;/p&gt;
&lt;p&gt;But it is quite common in rich Common Lisp IDEs like Lispworks for people to have multiple listener (REPL) sessions open at the same time (against the same runtime). You can launch long running processes that produce streaming output, switch to another listener and continue interaction and development, have separate listeners for separate contexts/state/command-history etc. There's a lot to Lisp development that's not RPC.&lt;/p&gt;
&lt;p&gt;Note multiple listeners, data inspectors and more. Maybe not the latest GUIs, but the capabilities should be a source of inspiration for any Clojure IDE.”&lt;/p&gt;
&lt;p&gt;Previously hinted personal end goal: exploit ‘critical mass’ for a (truly) ‘dynamic’ clojure dev env, including dynamic java recompilation, namespace reloading, etc. and include at a minimum:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;clojure.repl.deps&lt;/li&gt;
&lt;li&gt;clojure.tools.build.api (clojure.tools.build)&lt;/li&gt;
&lt;li&gt;clojure.tools.deps&lt;/li&gt;
&lt;li&gt;clojure.tools.deps.cli.api (clojure.deps.cli)&lt;/li&gt;
&lt;li&gt;clojure.tools.namespace&lt;/li&gt;
&lt;li&gt;clojure.tools.tools.api (clojure.tools.tools)&lt;/li&gt;
&lt;li&gt;GitHub - clj-commons/virgil: Recompile Java code without restarting&lt;br&gt;
the REPL (&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/clj-commons/virgil&quot;&gt;https://github.com/clj-commons/virgil&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;other polyglot ‘evaluation/compilation’ TBD&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I also included a few tools to help come back up to speed quicker:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;GitHub - nubank/morse: A graphical, interactive tool for browsing&lt;br&gt;
Clojure data (&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/nubank/morse&quot;&gt;https://github.com/nubank/morse&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;[clj-ns-browser/clj-ns-browser &quot;2.0.0-SNAPSHOT&quot;] – Clojars&lt;br&gt;
(&lt;a rel=&quot;nofollow&quot; href=&quot;https://clojars.org/clj-ns-browser/versions/2.0.0-SNAPSHOT&quot;&gt;https://clojars.org/clj-ns-browser/versions/2.0.0-SNAPSHOT&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Eventually will look at many ‘current projects’ including: GitHub - HumbleUI/HumbleUI: Clojure Desktop UI framework (&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/HumbleUI/HumbleUI&quot;&gt;https://github.com/HumbleUI/HumbleUI&lt;/a&gt;) as stated to build better apps than possible with web, AND access full power of your computer (multithreaded), wouldn’t that be convenient?&lt;/p&gt;
&lt;p&gt;Another quote from &lt;strong&gt;03-10-2015&lt;/strong&gt; Clojure stream socket repl discussion (&lt;a rel=&quot;nofollow&quot; href=&quot;https://groups.google.com/g/clojure-dev/c/Dl3Stw5iRVA/m/IHoVWiJz5UIJ&quot;&gt;https://groups.google.com/g/clojure-dev/c/Dl3Stw5iRVA/m/IHoVWiJz5UIJ&lt;/a&gt;):&lt;/p&gt;
&lt;p&gt;“REPL stands for something - Read, Eval, Print, Loop. It does not stand for - Eval RPC Server/Window.”&lt;/p&gt;
&lt;p&gt;Anyway, that would be ERSW, seriously, I couldn’t agree more, a required lisp feature, for me anyway: multiple simultaneous-concurrent (multi-threaded) REPLs, I refer to as ‘Clojure Listeners’ (‘in-process’ or ‘against the same runtime’) non-socket non-nREPL non-LSP non-network non-middleware non-multi-VM based REPL approaches that support multiple simultaneous dev management ‘native VM’ approaches for polyglot projects ala GraalVM.&lt;/p&gt;
&lt;p&gt;[SEE Multiple Clojure Listeners] (&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/mgrisius/clj-mode/blob/0.9/Clojure_Listener_2025-02-23_09-02-41.jpg&quot;&gt;https://github.com/mgrisius/clj-mode/blob/0.9/Clojure_Listener_2025-02-23_09-02-41.jpg&lt;/a&gt;) &lt;/p&gt;
&lt;p&gt;Note JavaScript Listener “JS-1” pictured. Could have python, R, ruby, or whatever language(s) available in GraalVM. ‘Clojure Listeners’ used with or without emacs, ‘regardless of editor’, in any Java VM for that matter. Could easily have multi-threaded socket-based listeners . . .&lt;/p&gt;
&lt;p&gt;Clojure Listeners: multi-threaded, full history, type ahead, line editing, completion, pop-up menus, colorized output, colorized-balanced-brackets-([{, etc. Also working on other listener features: multi-line editing, enhanced source lookup, doc lookup, repo-artifact search, embeddable .e.g. in morse, etc. all leveraging the ‘purest clojure value chain possible’!&lt;/p&gt;
&lt;p&gt;As previously mentioned, my basic ‘old style’ simple.bat with (~60mb) über jar simple compatibility with emacs lisp-inferior-mode works good with ‘legacy’ approach and new ‘CLI deps.edn approach’ basic use so far, both with ~1 second startup time. Zero optimization has been done thus far, e.g. GraalVM native image, etc.&lt;/p&gt;
&lt;p&gt;My forward-looking goal &amp;amp; reason for asking initial question: compatibility with future clojure tool direction(s), NOT invent the next ‘technical debt’ ad hoc one-off hack. My Holy Graal: I want a fully dynamic long running VM under full clojure programmatic control.&lt;/p&gt;
&lt;p&gt;So, the question remains: &lt;strong&gt;a) how to programmatically set REPL with ‘context’ for ‘project-1 aware’? b) how to programmatically switch REPL ‘context’ to ‘project-n aware’?&lt;/strong&gt;&lt;/p&gt;
</description>
<category>Clojure CLI</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14422/programmatically-context-programmatically-switch-context</guid>
<pubDate>Sun, 23 Feb 2025 16:56:50 +0000</pubDate>
</item>
<item>
<title>Comparing ratios with BigDecimals can throw</title>
<link>https://ask.clojure.org/index.php/14411/comparing-ratios-with-bigdecimals-can-throw</link>
<description>&lt;p&gt;Observe:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(&amp;lt; 1/4 0.5M)
;=&amp;gt; true        ; as expected

(&amp;lt; 1/3 0.5M)
; Execution error (ArithmeticException) at java.math.BigDecimal/divide (BigDecimal.java:1783).
; Non-terminating decimal expansion; no exact representable decimal result.
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is because Clojure tries to coerce the ratio to a BigDecimal, which can fail.&lt;/p&gt;
&lt;p&gt;This worked (and produced expected results) in Clojure up to 1.2.1; the current behaviour is from 1.3.0 onwards. Not sure whether this is a bug or expected behaviour; in either case, I haven’t seen it documented.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;=&lt;/code&gt;, &lt;code&gt;&amp;gt;=&lt;/code&gt; all exhibit the same behaviour. &lt;code&gt;=&lt;/code&gt; works.&lt;/p&gt;
&lt;p&gt;I’ve also noticed that &lt;code&gt;=&lt;/code&gt; can’t determine whether a ratio is equal to a bigdec, although &lt;code&gt;&amp;lt;&lt;/code&gt; and &lt;code&gt;&amp;gt;&lt;/code&gt; do sometimes produce a good answer:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;((juxt &amp;lt; = &amp;gt;) 1/2 0.5M)
;=&amp;gt; [false false false]

((juxt &amp;lt; = &amp;gt;) 1/4 0.5M)
;=&amp;gt; [true false false]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The same is true of ratios and doubles:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;((juxt &amp;lt; = &amp;gt;) 1/2 0.5M)
;=&amp;gt; [false false false]

((juxt &amp;lt; = &amp;gt;) 1/4 0.5M)
;=&amp;gt; [true false false]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This seems contrary to the docstring of &lt;code&gt;=&lt;/code&gt;, which states that „[it] compares numbers and collections in a type-independent manner”.&lt;/p&gt;
</description>
<category>Compiler</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14411/comparing-ratios-with-bigdecimals-can-throw</guid>
<pubDate>Fri, 21 Feb 2025 20:52:49 +0000</pubDate>
</item>
<item>
<title>a) how to start REPL with ‘context’ for ‘project-1 aware’? b) How to switch REPL ‘context’ to ‘project-n aware’?</title>
<link>https://ask.clojure.org/index.php/14392/start-with-context-project-aware-switch-context-project-aware</link>
<description>&lt;p&gt;Been away from clojure for a while, taking a fresh look at CLI &amp;amp; deps tool chain current status, direction &amp;amp; potential work flow(s). Previously maintained linux, macOS &amp;amp; MS Win / WSL2 dev envs, only looking at MS Win clojure right now.&lt;/p&gt;
&lt;p&gt;Dev env includes GraalVM JDK 23, clojure 1.12.0, emacs 27.1 with minimal (ancient) lisp-inferior-mode clj-mode (&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/mgrisius/clj-mode&quot;&gt;https://github.com/mgrisius/clj-mode&lt;/a&gt;), and Apache ant/ivy 1.10.3 for Transitive Dependency Management (TDM), classpath &amp;amp; java command construction. My ‘legacy’ emacs, clojure &amp;amp; java code are operational again.&lt;/p&gt;
&lt;p&gt;Using basic ‘old style’ simple.bat with (~60mb) über jar simple compatibility with emacs lisp-inferior-mode with ~1 second startup time, e.g. m-x eval-expression (run-lisp “simple.bat”):&lt;br&gt;
java -cp E:\dev\projects\simple\target\0.0.1.standalone.jar clojure.main&lt;/p&gt;
&lt;p&gt;Current goals include: convert to CLI &amp;amp; deps tools, among others.&lt;/p&gt;
&lt;p&gt;Installed clj-msi (Clojure 1.12.0.1501) Clojure for Windows 25.5.3460.1501, create basic project, deps.edn etc. Can use CLI from cmd.exe or powershell.exe to execute basic actions: invoke REPL, check versions, download deps, create über jar etc. Command line stuff works good!&lt;/p&gt;
&lt;p&gt;Not sure how best to leverage CLI &amp;amp; deps from a basic .bat file so that the resulting REPL is ‘project aware’, e.g. sees project deps.edn, build.clj, user.clj plus ‘tools.build’ related capabilities? So far, subtle differences between CLI interactive and basic .bat cmd.exe or powershell.exe results.&lt;/p&gt;
&lt;p&gt;As the tools.build Guide states: “We want to write this program with our favorite programming language, Clojure, and tools.build is a library of functions commonly needed for builds that can be connected together in flexible ways. Writing a build program does take a bit more code than other declarative approaches, but can be easily extended or customized far into the future, creating a build that grows with your project.”&lt;/p&gt;
&lt;p&gt;I prefer writing clojure code over complex cross platform compatible (shell) scripts, workarounds or hacks. So, I think I want full CLI functionality to use from the REPL to avoid incidental complexity, e.g. ‘very complicated’ problems discussed in Clojure CLI Reference in ‘Quoting keys and values’ related to platform specific issues wrt cmd.exe or powershell.exe concerns. Overall goal: avoid ‘technical debt’ from ANY platform specific minutiae for ANY shell, e.g. bash/tcsh, cmd.exe, powershell.exe, or even any new emacs lisp to focus solely on investment in purest clojure value chain possible.&lt;/p&gt;
&lt;p&gt;BTW: happily seems like there’s ‘critical mass’ for a (fairly complete) ‘dynamic’ clojure dev env with tools akin to early lisp machine (lispm) (e.g. Symbolics) ‘procedural’ style defsystem.&lt;/p&gt;
&lt;p&gt;Re-read clojure doc a few times, no mention on how a REPL is or s/b connected (‘in-process’) in a single VM with access to a ‘project’ with ‘tools.build’ and related features enabled? Or how to switch ‘build context’ to another ‘project’. Looked at monorepo / Polylith type subprojects that use ‘with-project-root’. Might be a good fit for a ‘mega project’ but doesn’t seem like a good fit (at least to me) for disparate, scattered or loosely coupled projects. Could keep a list of target project dirs and ‘map’ specific build tool process using ‘with-project-root’?&lt;/p&gt;
&lt;p&gt;Also mentioned in tools.build Guide: ‘Parametrized builds’ that s/b easy to use from CLI and via programmatic use to generate :dev :test :debug :deploy :install :prod :maintenance or :whatever actions or artifacts are required in conjunction with a ‘clj -T:build action-name’ approach.  Seems very reasonable, if there was a repeatable initial setup or process to make project deps.edn etc. &amp;amp; tools.build aware at a REPL.&lt;/p&gt;
&lt;p&gt;To summarize, it would be nice to have a minimal .bat file and/or ‘user.clj’ to enable the CLI deps experience/capabilities/tools programmatically via REPL. Am I over thinking or missing anything here? Perhaps by design or maybe it’s too early to ask for normative, idiomatic or canonical recommendations?&lt;/p&gt;
&lt;p&gt;My initial question is a) how to start a REPL with ‘context’ that is ‘project-1 aware’? b) How to switch a REPL ‘context’ to be ‘project-n aware’?&lt;/p&gt;
&lt;p&gt;I apologize I’m just starting out with CLI, deps.edn, tools.build, user.clj, etc. and have not absorbed many of the intricacies re required libraries, operational details, setup and intended use cases. Any suggestions would be greatly appreciated, thanks for sharing any insights!&lt;/p&gt;
</description>
<category>Clojure CLI</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14392/start-with-context-project-aware-switch-context-project-aware</guid>
<pubDate>Mon, 17 Feb 2025 17:14:46 +0000</pubDate>
</item>
<item>
<title>What is idiomatic way to represent an immutable pair in Clojure?</title>
<link>https://ask.clojure.org/index.php/14317/what-is-idiomatic-way-to-represent-an-immutable-pair-clojure</link>
<description>&lt;p&gt;Hi!&lt;br&gt;
What is idiomatic way to represent an immutable pair in Clojure where pair is an immutable container for two component (kinda first and last) which can't be modified after construction.&lt;/p&gt;
&lt;p&gt;Use case is following -- create data structure with first and second components which will not be modified by consumers. Consumers will read first and second components using destructuring or first/second selectors. &lt;/p&gt;
&lt;p&gt;I can see a de-facto way to represent it via vector.&lt;br&gt;
There are other alternatives like:&lt;br&gt;
 - use list&lt;br&gt;
 - use MapEntry&lt;/p&gt;
&lt;p&gt;it seems that list is &quot;ligther&quot; data structure than vector. Maybe using list to model pair for the use above has advantages? (less pressure on memory, etc.)&lt;/p&gt;
&lt;p&gt;Thanks!&lt;/p&gt;
</description>
<category>Clojure</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14317/what-is-idiomatic-way-to-represent-an-immutable-pair-clojure</guid>
<pubDate>Thu, 26 Dec 2024 18:02:36 +0000</pubDate>
</item>
<item>
<title>How to define namespace interface boundaries (like with index.js files in JS)</title>
<link>https://ask.clojure.org/index.php/14315/define-namespace-interface-boundaries-like-with-index-files</link>
<description>&lt;h2&gt;tl;dr&lt;/h2&gt;
&lt;p&gt;One of the things I actually like about JS is that I can declaratively define the interfaces/boundaries of folder-level modules through defining a public interface by re-exporting what's supposed to be accessible to other modules and I'm wondering if there's something similar in Clojure (and if not - what's the best way to request a feature).&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;EDIT: Don't know why the formatting isn't working, the question's preview looks fine...&lt;/p&gt;
&lt;p&gt;Let's say there's the following folder structure:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;| my-project/
|-- src/
|---- product/
|------ product_related_module/
|------ other_product_related_module/
|---- catalog/
|------ catalog_related_module/
|---- checkout/&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;I don't want the catalog and checkout modules to know anything about internal things of the product module. Instead I want the product module (all modules actually) to declare its interface, which to me means that there's a file that explains what's being exposed and supposed to be used.&lt;/p&gt;
&lt;p&gt;In JS, I can define whatever is supposed to be publicly by using index.js files that do only one thing: re-exporting what's supposed to be public. Everything else is considered internal (can be enforced with eslint).&lt;/p&gt;
&lt;p&gt;This helps tremendously to maintain a loosely coupled and strongly cohesive project. With this, the internal structure of the &lt;code&gt;src/product&lt;/code&gt; module can be re-organized in any way, as long as the interface does not change, the rest of the application doesn't need to care.&lt;/p&gt;
&lt;p&gt;I've seen many clojure examples like this:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;`&lt;/code&gt;clj&lt;br&gt;
(ns my-project.catalog.catalog-related-module.get-catalog-page&lt;br&gt;
  (:require [my-project.product.product-related-module.foo :as foo]))&lt;br&gt;
&lt;code&gt;`&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;So I'm wondering if there's a way to add re-exporting files, so I could do this:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;`&lt;/code&gt;clj&lt;br&gt;
(ns my-project.catalog.catalog-related-module.get-catalog-page&lt;br&gt;
  (:require [my-project.product :refer [foo]]))&lt;br&gt;
&lt;code&gt;`&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;In javascript I could achieve this by using &lt;code&gt;index.js&lt;/code&gt; files:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;`&lt;/code&gt;js&lt;br&gt;
// src/product/product-related-module/index.js&lt;br&gt;
export { foo } from './foo.js'&lt;/p&gt;
&lt;p&gt;// src/product/index.js&lt;br&gt;
export { foo } from './product-related-module/index.js'&lt;br&gt;
&lt;code&gt;`&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Ideally I could even restrict from requiring anything from a namespace inside the product-namepsace when accessing from outside.&lt;/p&gt;
</description>
<category>Clojure</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14315/define-namespace-interface-boundaries-like-with-index-files</guid>
<pubDate>Thu, 26 Dec 2024 09:26:55 +0000</pubDate>
</item>
<item>
<title>Java interop issue</title>
<link>https://ask.clojure.org/index.php/14240/java-interop-issue</link>
<description>&lt;p&gt;Hi everyone,&lt;/p&gt;
&lt;p&gt;Failing to make clojure work with our commercial java library. I can run the following Java code on my machine and it works fine: &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;import com.numerix.pro.Application;
import com.numerix.pro.ApplicationCall;
import com.numerix.pro.ApplicationData;
import com.numerix.pro.ApplicationObjectFactory;
import com.numerix.pro.ApplicationWarning;

public final class FxAmericanOption {

    public static void main(final String argv[]) 
    {
        int rVal = 0;      // exit value
        try {
            System.out.println(&quot;Running: &quot; + new Throwable().getStackTrace()[0].getClassName() + &quot;\n&quot;);

            final Application app = new Application();
            {
                final ApplicationCall call = new ApplicationCall();
                call.addValue(&quot;ID&quot;,       &quot;USD_Curve&quot;);
                call.addValue(&quot;OBJECT&quot;,   &quot;Curve&quot;);
                call.addValue(&quot;TYPE&quot;,     &quot;Yield&quot;);
                call.addValue(&quot;Now Date&quot;, ApplicationObjectFactory.parseDate(&quot;26-Oct-2003&quot;));
                call.addValue(&quot;CURRENCY&quot;, &quot;USD&quot;);
                call.addValue(&quot;RATE&quot;,     0.04);

                final String[] outHeaders =
                    new String[] {&quot;Updated&quot;, &quot;Timer&quot;, &quot;ID&quot;};

                final ApplicationWarning warning = new ApplicationWarning();

                app.call(call, outHeaders, warning);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I tried porting it to clojure 1.12 like this &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(ns hello
  (:import (com.numerix.pro Application ApplicationCall
                            ApplicationWarning 
                            ApplicationObjectFactory)))
           
(def myapp (new Application))
(def appcall (new ApplicationCall))
(def warning (new ApplicationWarning))

(.addValue ^ApplicationCall appcall &quot;NAME&quot; &quot;Yield Curve&quot;)
(.addValue ^ApplicationCall appcall &quot;ID&quot; &quot;MyCurve&quot;)
(.addValue ^ApplicationCall appcall &quot;OBJECT&quot; &quot;Curve&quot;)
(.addValue ^ApplicationCall appcall &quot;TYPE&quot; &quot;Yield&quot;)
(.addValue ^ApplicationCall appcall &quot;Now Date&quot; (ApplicationObjectFactory/parseDate &quot;26-Oct-2023&quot;))
(.addValue ^ApplicationCall appcall &quot;CURRENCY&quot; &quot;USD&quot;)
(.addValue ^ApplicationCall appcall &quot;RATE&quot; 0.04)

(def outHeaders (into-array String [&quot;timer&quot; &quot;id&quot;]))

(^[ApplicationCall String/1 ApplicationWarning] Application/.call ^Application myapp
                                                                  ^ApplicationCall appcall
                                                                  ^String/1 outHeaders
                                                                  ^ApplicationWarning warning)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I can inspect appcall object and it looks totally fine - all the .addValue register correctly with it. But when I evaluate the last form with Application/.call I get an error which I don't understand how to address.. &lt;/p&gt;
&lt;pre&gt;&lt;code&gt; Execution error (IllegalAccessError) at hello/eval10370 (REPL:25).
; failed to access class com.numerix.pro.ApplicationCommon from class hello$eval10370 (com.numerix.pro.ApplicationCommon is in unnamed module of loader 'app'; hello$eval10370 is in unnamed module of loader clojure.lang.DynamicClassLoader @cc01572)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Any help much appreciated! &lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14240/java-interop-issue</guid>
<pubDate>Tue, 12 Nov 2024 19:25:31 +0000</pubDate>
</item>
<item>
<title>Found some typos in clojure.core, how to contribute a patch?</title>
<link>https://ask.clojure.org/index.php/14150/found-some-typos-in-clojure-core-how-to-contribute-a-patch</link>
<description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;For example, &lt;code&gt;if&lt;/code&gt; is mispelled in defonce docs:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(defmacro defonce
  &quot;defs name to have the root value of the expr iff the named var has no root value,
  else expr is unevaluated&quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I've already signed the Clojure Contributor Agreement.&lt;/p&gt;
</description>
<category>Docs</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14150/found-some-typos-in-clojure-core-how-to-contribute-a-patch</guid>
<pubDate>Sun, 29 Sep 2024 14:22:30 +0000</pubDate>
</item>
<item>
<title>Separate bindable reporting function from clojure.test/report</title>
<link>https://ask.clojure.org/index.php/14089/separate-bindable-reporting-function-from-clojure-report</link>
<description>&lt;p&gt;&lt;strong&gt;Set Up&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;clojure.test&lt;/code&gt; is built on the idea that a test will call an assertion function that directly calls a reporting function: &lt;code&gt;is&lt;/code&gt; calls &lt;code&gt;report&lt;/code&gt; (through &lt;code&gt;do-report&lt;/code&gt;). The function &lt;code&gt;report&lt;/code&gt; is a multimethod, allowing for adding or overriding keys to allow for implementing alternative reporting styles. It's also dynamic, meant to be rebound if an entirely new reporting system is to be used (TAP, JUnit, etc).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Problem&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;As discussed in the excellent &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/lambdaisland/kaocha/blob/15e553ddba5497a91099f0edda8433d66ef1094f/src/kaocha/report.clj#L40-L71&quot;&gt;kaocha source code&lt;/a&gt;, these two approaches don't work together, which leads to issues such as kaocha's workarounds (and monkey-patching), &lt;a rel=&quot;nofollow&quot; href=&quot;https://codeberg.org/leiningen/leiningen/src/commit/795c3a5d68de7a2465582da4184c42d7bd065c76/sample.project.clj#L371-L373&quot;&gt;leiningen&lt;/a&gt;'s monkey-patching, Cursive's test runner not always integrating with other tools due to &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojurians.slack.com/archives/C0744GXCJ/p1720462210536379?thread_ts=1713354339.092179&amp;amp;cid=C0744GXCJ&quot;&gt;binding &lt;code&gt;report&lt;/code&gt;&lt;/a&gt;, and others.&lt;/p&gt;
&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.lambdasierra.com/2022/hello&quot;&gt;Alessandra Sierra&lt;/a&gt; wrote about &lt;a rel=&quot;nofollow&quot; href=&quot;https://stuartsierra.com/2010/07/05/lazytest-status-report&quot;&gt;this issue&lt;/a&gt; as well when she attempted a follow-up to &lt;code&gt;clojure.test&lt;/code&gt; called Lazytest (which I have resurrected over the last year). She ended up not finishing the library, and many other alternatives to Clojure test have not been as successful as one might hope either.&lt;/p&gt;
&lt;p&gt;Given that &lt;code&gt;clojure.test&lt;/code&gt; is here to stay, it seems prudent to make it easier to use and adapt without changing the fundamental api.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Potential Solution&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Separating the &quot;dynamic variable to be rebound&quot; from &quot;the default reporting function&quot; would make it easier for libraries and tools to choose to extend &lt;code&gt;report&lt;/code&gt; or replace it entirely, without worrying that they'll clash or run into each other. This can be accomplished by adding a new dynamic variable &lt;code&gt;*reporter*&lt;/code&gt; to &lt;code&gt;clojure.test&lt;/code&gt; that &lt;code&gt;do-report&lt;/code&gt; calls, and defaulting &lt;code&gt;*reporter*&lt;/code&gt; to &lt;code&gt;clojure.test/report&lt;/code&gt;. (&lt;code&gt;report&lt;/code&gt; would stay dynamic so as to not change working code.)&lt;/p&gt;
&lt;p&gt;With such a change in place, workarounds such as Leiningen's &lt;a rel=&quot;nofollow&quot; href=&quot;https://codeberg.org/leiningen/leiningen/src/commit/b72ac7840c34e89eb358bada5ab5c2466008d476/src/leiningen/test.clj#L115-L129&quot;&gt;monkey-patching&lt;/a&gt; could simply bind &lt;code&gt;*report*&lt;/code&gt; with a new function and not worry about stepping on any other library's toes.&lt;/p&gt;
</description>
<category>Test</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14089/separate-bindable-reporting-function-from-clojure-report</guid>
<pubDate>Tue, 27 Aug 2024 18:38:20 +0000</pubDate>
</item>
<item>
<title>How to suppress/capture the output of defspec for use in clojure.test?</title>
<link>https://ask.clojure.org/index.php/14040/how-suppress-capture-the-output-defspec-for-use-clojure-test</link>
<description>&lt;p&gt;I've been a fan of &lt;code&gt;test.check&lt;/code&gt; since the beginning. However, I've never found a convenient way to capture the output when using &lt;code&gt;defspec&lt;/code&gt;.  When used with &lt;code&gt;clojure.test&lt;/code&gt;, one gets output that looks like:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;Testing tst.tupelo.y64
{:result true, :num-tests 999, :seed 1722976402694, :time-elapsed-ms 53, :test-var &quot;dospec-line-53&quot;}
{:result true, :num-tests 999, :seed 1722976402747, :time-elapsed-ms 36, :test-var &quot;dospec-line-44&quot;}&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;somewhat polluting the unit test output.  How can one capture and/or suppress this output?&lt;/p&gt;
</description>
<category>test.check</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14040/how-suppress-capture-the-output-defspec-for-use-clojure-test</guid>
<pubDate>Tue, 06 Aug 2024 20:41:33 +0000</pubDate>
</item>
<item>
<title>Type inference in defn?</title>
<link>https://ask.clojure.org/index.php/14027/type-inference-in-defn</link>
<description>&lt;pre&gt;&lt;code&gt;(ns graalvm-list-issue.main
  (:require
   [clojure.java.io :as io])
  (:gen-class))

(defn- home-path []
  (System/getProperty &quot;user.home&quot;))

(defn- local-dir []
  (io/file (home-path) &quot;.local&quot;))

(defn -main [&amp;amp; _args]
  (println (seq (.list (io/file (home-path) &quot;.local&quot;))))
  (println (seq (.list (local-dir)))))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;(Full code is here: &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/conao3/clojure-graalvm-list-issue&quot;&gt;https://github.com/conao3/clojure-graalvm-list-issue&lt;/a&gt;)&lt;/p&gt;
&lt;p&gt;The first &lt;code&gt;println&lt;/code&gt; line has no reflection, the second &lt;code&gt;println&lt;/code&gt; line has reflection, and an error occurs during execution in GraalVM.&lt;br&gt;
I see no difference between the two calls, and since it is obvious that it is io/file as the return value of &lt;code&gt;local-dir&lt;/code&gt;, it should be type-inferred as java.io.File. What do you think?&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;Investivate Clojure source code:&lt;/p&gt;
&lt;p&gt;Key function is &lt;code&gt;hasJavaClass&lt;/code&gt; and &lt;code&gt;getJavaClass&lt;/code&gt;.&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/clojure/clojure/blob/8c8e4f6ef21f3d0f59deb60cdc7e1b584f596d59/src/jvm/clojure/lang/Compiler.java#L359-L361&quot;&gt;https://github.com/clojure/clojure/blob/8c8e4f6ef21f3d0f59deb60cdc7e1b584f596d59/src/jvm/clojure/lang/Compiler.java#L359-L361&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;FnExpr: &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/clojure/clojure/blob/8c8e4f6ef21f3d0f59deb60cdc7e1b584f596d59/src/jvm/clojure/lang/Compiler.java#L4450-L4454&quot;&gt;https://github.com/clojure/clojure/blob/8c8e4f6ef21f3d0f59deb60cdc7e1b584f596d59/src/jvm/clojure/lang/Compiler.java#L4450-L4454&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;InvokeExpr: &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/clojure/clojure/blob/8c8e4f6ef21f3d0f59deb60cdc7e1b584f596d59/src/jvm/clojure/lang/Compiler.java#L4286-L4290&quot;&gt;https://github.com/clojure/clojure/blob/8c8e4f6ef21f3d0f59deb60cdc7e1b584f596d59/src/jvm/clojure/lang/Compiler.java#L4286-L4290&lt;/a&gt;&lt;/p&gt;
</description>
<category>Clojure</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14027/type-inference-in-defn</guid>
<pubDate>Mon, 22 Jul 2024 01:43:33 +0000</pubDate>
</item>
<item>
<title>Ref transactions causing deadlock at the REPL</title>
<link>https://ask.clojure.org/index.php/14016/ref-transactions-causing-deadlock-at-the-repl</link>
<description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I've come across some strange behavior while playing around with refs at the REPL.&lt;br&gt;
So I have a ref with a simple watcher function:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(defn watcher [_ r o n]
  (printf &quot;ref: %s old: %s new: %s time: %d\n&quot; @r o n (System/currentTimeMillis))
  (flush))

(def x (ref 2))
(add-watch x nil watcher) 
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I then evaluate the following expression two times in a row: &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(future (dosync (ensure x) (Thread/sleep 3000) (alter x * 2)))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;What I would expect to happen is that the watcher function should print the ref's value two times in a row, about 3 seconds apart.&lt;br&gt;
But nothing happens.&lt;br&gt;
When I then try to access the ref with another command such as&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(dosync (ensure x) (alter x inc))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The REPL blocks completely. Once I did get the expected results several minutes later, another time I got this error message:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Execution error at reftest.core/eval24449 (form-init12758928819079876959.clj:34).                                               
Transaction failed after reaching retry limit
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;What I find perplexing is that everything seems to work just fine when I evaluate this let-block:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(let [x (ref 2)]
  (add-watch x nil watcher)
  (println &quot;start:&quot; (deref x))
  (future (dosync (ensure x) (Thread/sleep 3000) (alter x * 2)))
  (future (dosync (ensure x) (Thread/sleep 3000) (alter x * 2)))
  (dosync (ensure x) (alter x inc))
  (println &quot;end:&quot; @x))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Is the behavior at the REPL some kind of bug or am I doing something wrong?&lt;br&gt;
How can I make sure that such STM transactions don't fail in real code?&lt;/p&gt;
</description>
<category>Refs, agents, atoms</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14016/ref-transactions-causing-deadlock-at-the-repl</guid>
<pubDate>Tue, 09 Jul 2024 14:28:33 +0000</pubDate>
</item>
<item>
<title>Optimize `select-keys`</title>
<link>https://ask.clojure.org/index.php/13964/optimize-select-keys</link>
<description>&lt;p&gt;Some preliminary testing show that &lt;code&gt;select-keys&lt;/code&gt; can be almost twice as fast if it were rewritten to use a transient map rather than a proper map as it does today.&lt;/p&gt;
&lt;p&gt;In order to do so, &lt;code&gt;select-keys&lt;/code&gt; would need to move to after where &lt;code&gt;transient&lt;/code&gt; and its friends are defined. &lt;/p&gt;
&lt;p&gt;If there is any interest in pursuing this, I'd be happy to provide a problem statement, more data on the performance,  a couple of possible solutions, and perhaps ultimately a patch.&lt;/p&gt;
</description>
<category>Collections</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/13964/optimize-select-keys</guid>
<pubDate>Tue, 11 Jun 2024 07:18:28 +0000</pubDate>
</item>
<item>
<title>Documentation on alternative radix/0-prefixed numbers</title>
<link>https://ask.clojure.org/index.php/13860/documentation-on-alternative-radix-0-prefixed-numbers</link>
<description>&lt;p&gt;The data structures section on numbers (&lt;a rel=&quot;nofollow&quot; href=&quot;https://clojure.org/reference/data_structures#Numbers&quot;&gt;https://clojure.org/reference/data_structures#Numbers&lt;/a&gt;) doesn't mention any of the alternate radix numbers. Reading the code in LispReader is challenging, I'm not exactly sure how it should work. Is there another place this is documented? If not, can the various ways be documented?&lt;/p&gt;
&lt;p&gt;Here's what I've discovered from reading the regex and code, not sure which of this is intentional or undefined behavior:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;0      ; 0
+0     ; 0
+0N    ; 0N
1      ; 1
-1     ; -1
123    ; 123
123N   ; 123N
0x1A   ; 26
0x1AN  ; 26N
012    ; 10
012N   ; 10N
12r1   ; 1
12r1N  ; fails
12r2a  ; 34
12r2aN ; fails
&lt;/code&gt;&lt;/pre&gt;
</description>
<category>Docs</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/13860/documentation-on-alternative-radix-0-prefixed-numbers</guid>
<pubDate>Tue, 30 Apr 2024 16:22:09 +0000</pubDate>
</item>
<item>
<title>Cannot invoke &quot;clojure.lang.Var.isBound()&quot; because &quot;clojure.lang.Compiler.LOADER&quot; is null, potential bug?</title>
<link>https://ask.clojure.org/index.php/13819/cannot-clojure-isbound-because-clojure-compiler-potential</link>
<description>&lt;p&gt;As per &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojurians.slack.com/archives/C03S1KBA2/p1713446287942589&quot;&gt;discussion&lt;/a&gt; on slack I'm posting here the findings regarding clojure.lang.Compiler.LOADER being null during the analysis phase of GraalVM native-image run.&lt;/p&gt;
&lt;p&gt;The full reproduction can be found &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/FieryCod/graalvm-repro&quot;&gt;here&lt;/a&gt; and the link to issue on Oracle GraalVM side &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/oracle/graal/issues/8801&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;What is this issue about?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Native Image cannot be produced and throws an error during analysis phase when Clojure 1.11.2 (although the previous version of Clojure might be also affected) is used and reflection entries for java.lang.UUID and clojure.lang.Keyword are present in &lt;code&gt;reflectionconfig.json&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;I can't however reproduce the error prior to Clojure 1.9.0. For more information please kindly take a look into a repro.&lt;/p&gt;
</description>
<category>Compiler</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/13819/cannot-clojure-isbound-because-clojure-compiler-potential</guid>
<pubDate>Thu, 18 Apr 2024 16:11:35 +0000</pubDate>
</item>
<item>
<title>Why does compilation of fn fail when referencing a class with a failing static field initializer?</title>
<link>https://ask.clojure.org/index.php/13810/compilation-referencing-class-failing-static-initializer</link>
<description>&lt;p&gt;Given a Clojure function which references a class, if that class has a static field with an initializer which fails when run, the function will fail to compile because the compiler (needlessly) runs the initializer even if the respective field is not accessed. Notably, this does &lt;em&gt;not&lt;/em&gt; happen when storing the class in a var and then referencing it through that instead (see workaround below). Could the compiler support the direct reference here?&lt;/p&gt;
&lt;h2&gt;Reproducer&lt;/h2&gt;
&lt;p&gt;(The following code is also available at &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/bevuta/clojure-fn-compilation-issue-repro&quot;&gt;https://github.com/bevuta/clojure-fn-compilation-issue-repro&lt;/a&gt;)&lt;/p&gt;
&lt;p&gt;&lt;code&gt;deps.edn&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;{:deps {io.netty/netty-codec {:mvn/version &quot;4.1.108.Final&quot;}}}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;src/repro/fail.clj&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(ns repro.fail
  (:import io.netty.handler.codec.compression.BrotliOptions))

(defn bar []
  BrotliOptions)

(defn -main [&amp;amp; args]
  (prn (bar)))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here, the &lt;code&gt;bar&lt;/code&gt; function references the &lt;code&gt;io.netty.handler.codec.compression.BrotliOptions&lt;/code&gt; class. That class has &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/netty/netty/blob/c1d0fd2dbf7907a99ab702795e35d9de8068c1cb/codec/src/main/java/io/netty/handler/codec/compression/BrotliOptions.java#L32-L34&quot;&gt;a package-private static field named &lt;code&gt;DEFAULT&lt;/code&gt;&lt;/a&gt; with an initializer. That initializer depends on a class which is provided by an optional third-party library. However, even though &lt;code&gt;bar&lt;/code&gt; never references that field, the initializer gets run and fails because that library is not present.&lt;/p&gt;
&lt;p&gt;Run it like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ clojure -M -m repro.fail
Execution error (ClassNotFoundException) at jdk.internal.loader.BuiltinClassLoader/loadClass (BuiltinClassLoader.java:641).
com.aayushatharva.brotli4j.encoder.Encoder$Parameters
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Workaround&lt;/h2&gt;
&lt;p&gt;The issue can be worked around by putting the class value into a separate &lt;code&gt;def&lt;/code&gt; and using that in the function instead:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;src/repro/ok.clj&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(ns repro.ok
  (:import io.netty.handler.codec.compression.BrotliOptions))

(def foo BrotliOptions)

(defn bar []
  foo)

(defn -main [&amp;amp; args]
  (prn (bar)))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Run it like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;$ clojure -M -m repro.ok
io.netty.handler.codec.compression.BrotliOptions
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Relevance&lt;/h2&gt;
&lt;p&gt;The issue was encountered in the context of &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/clj-commons/aleph/issues/703&quot;&gt;https://github.com/clj-commons/aleph/issues/703&lt;/a&gt;&lt;/p&gt;
</description>
<category>Compiler</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/13810/compilation-referencing-class-failing-static-initializer</guid>
<pubDate>Mon, 08 Apr 2024 15:01:01 +0000</pubDate>
</item>
<item>
<title>Returning the last assigned value from `let` w/o a body</title>
<link>https://ask.clojure.org/index.php/13782/returning-the-last-assigned-value-from-let-w-o-a-body</link>
<description>&lt;p&gt;This is more of a suggestion, not really sure where to post it though. Please refer me to the relevant forum if there exists a better one.&lt;/p&gt;
&lt;p&gt;Basically I'm going under the assumption that no one uses &lt;code&gt;let&lt;/code&gt; without a body. The only reason I can imagine for doing that is purely for side-effects, and &lt;code&gt;do&lt;/code&gt; etc. are a much better fit, and currently &lt;code&gt;(let [x 1 y 2 z (+ x y)]) =&amp;gt; nil&lt;/code&gt; (rather than throwing a spec error, as if this is useful expected behavior? But why?)&lt;/p&gt;
&lt;p&gt;In any case, if my assumption is correct, then I propose &lt;code&gt;let&lt;/code&gt; returns the last assigned value, such that &lt;code&gt;(let [x 1 y 2 z (+ x y)]) =&amp;gt; 3&lt;/code&gt;, that is &lt;code&gt;z&lt;/code&gt;. This is ergonomic, and intuitive in my eyes. It's also especially useful for long binding forms building off of the same variables only for the final one to be important, which then requires a whole row with special funky indentation just for that.&lt;/p&gt;
</description>
<category>Macros</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/13782/returning-the-last-assigned-value-from-let-w-o-a-body</guid>
<pubDate>Wed, 13 Mar 2024 23:17:32 +0000</pubDate>
</item>
<item>
<title>How to create a short-lived remote-prepl such that it can be gracefully shutdown?</title>
<link>https://ask.clojure.org/index.php/13760/create-short-lived-remote-prepl-such-that-gracefully-shutdown</link>
<description>&lt;p&gt;TLDR: How can I start a &quot;one time use&quot; remote-prepl connection that runs a single command, gets the return value, and then releases all resources used?&lt;/p&gt;
&lt;p&gt;I asked this in slack but didn't receive a response. It's probably not usually a big deal in practice but it's been bothering me, so I figured I would more formally log it here.&lt;/p&gt;
&lt;p&gt;I was under the impression that short lived remote-prepl clients is an intended usage. That it should enable one to connect to the remote, eval something, get the return value and disconnect. &lt;/p&gt;
&lt;p&gt;Some example code I found to this effect is here:&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/Olical/how-to-be-a-repl-sorcerer/blob/b6bd530f3d0c6b165248d980d7ce6cd28e8da51f/src/sorcery/main.clj#L20&quot;&gt;https://github.com/Olical/how-to-be-a-repl-sorcerer/blob/b6bd530f3d0c6b165248d980d7ce6cd28e8da51f/src/sorcery/main.clj#L20&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Modified slightly:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(ns prepl-question
  (:require [clojure.core.server :as server])
  (:import [java.io PipedReader PipedWriter]))

(def srv
  (server/start-server {:accept 'clojure.core.server/io-prepl
                        :port   0
                        :name   &quot;srv&quot;}))

(defn remote-eval [code]
  (with-open [reader (PipedReader.)
              writer (PipedWriter.)]
    (.connect reader writer)
    (let [result! (promise)]
      (future
        (server/remote-prepl
          &quot;localhost&quot; (.getLocalPort srv)
          reader
          (fn [msg]
            (deliver result! msg)))
        (println &quot;DONE&quot;))
      (.write writer code)
      (.flush writer)
      @result!

      ;; doesn't print &quot;DONE&quot;
      (let [r @result!]
        (.close reader)
        (.close writer)

        ;;(.write writer &quot;:repl/quit\n&quot;) ;; also tried this
        ;;(.flush writer)

        r))))

(remote-eval &quot;(+ 1 2 3)&quot;)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I've found no way to get &quot;DONE&quot; to print, signifying the stopping of the prepl thread loop, with any combination of closing the streams used. &lt;/p&gt;
&lt;p&gt;Looking at the remote-prepl source code a bit, it seems like &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/clojure/clojure/blob/f06ef8ad0b3d3ca5cbea64f55e416de1065a65e0/src/clj/clojure/core/server.clj#L341&quot;&gt;this line here&lt;/a&gt; will call close on the reader, but it will be called when the reader is already closed. But at least in the example above, I've found that this causes things to hang forever when &lt;code&gt;close&lt;/code&gt; is called the second time. I'm guessing this is related to the issue described here: &lt;a rel=&quot;nofollow&quot; href=&quot;https://stackoverflow.com/a/45703662&quot;&gt;https://stackoverflow.com/a/45703662&lt;/a&gt;, related to the PipedReader/Writer setup.&lt;/p&gt;
&lt;p&gt;But I'm not sure if this could be considered a bug in the prepl code or if I'm using it wrong. &lt;/p&gt;
</description>
<category>REPL</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/13760/create-short-lived-remote-prepl-such-that-gracefully-shutdown</guid>
<pubDate>Tue, 27 Feb 2024 17:04:50 +0000</pubDate>
</item>
<item>
<title>Can direct-linking be enabled for my own code and not for libraries?</title>
<link>https://ask.clojure.org/index.php/13757/can-direct-linking-enabled-for-own-code-and-not-for-libraries</link>
<description>&lt;p&gt;Blanketly enablind direct-linking can break libraries, and I can't control what vars in them are affected, but I'd still like to improve performance at least in parts of my own code.&lt;/p&gt;
&lt;p&gt;Would the following work?&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(binding [clojure.core/*compiler-options* 
  {:direct-linking true}]
  ,,,
  )
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here's the docs: &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojuredocs.org/clojure.core/*compiler-options*&quot;&gt;https://clojuredocs.org/clojure.core/*compiler-options*&lt;/a&gt;&lt;/p&gt;
</description>
<category>Compiler</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/13757/can-direct-linking-enabled-for-own-code-and-not-for-libraries</guid>
<pubDate>Tue, 27 Feb 2024 12:47:39 +0000</pubDate>
</item>
<item>
<title>Why can't I type hint these floats?</title>
<link>https://ask.clojure.org/index.php/13743/why-cant-i-type-hint-these-floats</link>
<description>&lt;p&gt;I want to ensure I'm using unboxed and unreflected arithmetic on arrays of floats, but I can't get it to compile.&lt;/p&gt;
&lt;p&gt;How can I type hint a float in a function like this?&lt;/p&gt;
&lt;p&gt;&lt;code&gt;`&lt;/code&gt;&lt;br&gt;
(defn ff2a&lt;/p&gt;
&lt;p&gt;  ^&quot;[F&quot; ; Return type hint for a float array&lt;/p&gt;
&lt;p&gt;  [^float f1 ^float f2] ; Argument type hints&lt;/p&gt;
&lt;p&gt;  (float-array [f1 f2]))&lt;br&gt;
&lt;code&gt;`&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;I get this error when I try to load it into the REPL:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;Syntax error (IllegalArgumentException) compiling fn* [...] Only long and double primitives are supported&lt;/code&gt;&lt;/p&gt;
</description>
<category>Java Interop</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/13743/why-cant-i-type-hint-these-floats</guid>
<pubDate>Thu, 15 Feb 2024 18:48:26 +0000</pubDate>
</item>
<item>
<title>What's an ideomatic way to manage state in a library?</title>
<link>https://ask.clojure.org/index.php/13734/whats-an-ideomatic-way-to-manage-state-in-a-library</link>
<description>&lt;p&gt;I’m porting a JS library to clojure (and, potentially cljs), and I’m struggling with reasoning about local state. Imagine a scenario where you do RPC over websockets, and the server reply contextually depend on what the server had already sent you. You'd want to keep a local cache of the replies from the server, then.&lt;/p&gt;
&lt;p&gt;In OOP world it's expected you incapsulate both the socket and the cache and provide the library users an interface that sends RPCs and transparently handles the cache population and pulling results from it. What would be the ideomatic way to do the same in clojure[-script]? Would I just return a map and expect my functions to take it as a first argument, returning the update state along with the rpc result?&lt;/p&gt;
</description>
<category>Refs, agents, atoms</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/13734/whats-an-ideomatic-way-to-manage-state-in-a-library</guid>
<pubDate>Thu, 15 Feb 2024 12:46:36 +0000</pubDate>
</item>
<item>
<title>Method values vs Method references</title>
<link>https://ask.clojure.org/index.php/13719/method-values-vs-method-references</link>
<description>&lt;p&gt;with &lt;a rel=&quot;nofollow&quot; href=&quot;https://docs.oracle.com/javase/tutorial/java/javaOO/methodreferences.html&quot;&gt;java method references&lt;/a&gt; the following works (this code is taken from java.time.LocalDate):&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;public static LocalDate parse(CharSequence text, DateTimeFormatter formatter) {
    return formatter.parse(text, LocalDate::from);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;the second arg to the parse method is a TemporalQuery - a functional interface that takes a single TemporalAccessor as arg. In this example, instead of passing a TemporalQuery instance, here a method reference is being passed, where the method signature matches that of TemporalQuery - ie takes a single TemporalAccessor as arg. &lt;/p&gt;
&lt;p&gt;Trying to do similar in clojure:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(^[CharSequence TemporalQuery] DateTimeFormatter/parse formatter &quot;20200202&quot; java.time.LocalDate/from)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;results in &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Execution error (ClassCastException) at user/eval2266 (form-init14137309762912529150.clj:1).
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;class user$eval2266$invoke&lt;strong&gt;LocalDate_from&lt;strong&gt;2268 cannot be cast to class java.time.temporal.TemporalQuery (user$eval2266$invoke&lt;/strong&gt;LocalDate_from&lt;/strong&gt;2268 is in unnamed module of loader clojure.lang.DynamicClassLoader @37e99783; java.time.temporal.TemporalQuery is in module java.base of loader 'bootstrap')&lt;/p&gt;
&lt;p&gt;Is this a bug or intentional do you think? If intentional, some docs on how clojure method values compare to java method references would be useful.&lt;/p&gt;
</description>
<category>Clojure</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/13719/method-values-vs-method-references</guid>
<pubDate>Wed, 14 Feb 2024 10:10:10 +0000</pubDate>
</item>
<item>
<title>Method Values and Syntax Errors</title>
<link>https://ask.clojure.org/index.php/13710/method-values-and-syntax-errors</link>
<description>&lt;p&gt;Copied from this &lt;a rel=&quot;nofollow&quot; href=&quot;https://old.reddit.com/r/Clojure/comments/1apdx2d/method_values_inside_clojure/kq6iy82/&quot;&gt;reddit comment&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;So if an ambiguous method is a syntax error (syntax, really?), does that mean that when I update a Java lib that provides a new overload, it will break my code? Even worse, if I have a Clojure lib on the classpath that uses a Java lib, and then update the Java lib and it now provides another overload, the Clojure lib breaks. This would be bad and could result in all kinds of update hell.&lt;/p&gt;
&lt;p&gt;Adding an overload is a very common backwards compatible change in Java code that should be expected. Please don't make it create &quot;syntax&quot; errors in Clojure wrappers.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;My own words:&lt;/p&gt;
&lt;p&gt;One of Clojure's strengths is the resiliency of code, that something written years ago still works today. This has historically applied to libraries that provide idiomatic wrappers around Java libraries as well. However, the use of syntax errors instead of falling back to reflection means that such libraries (if they use the new method values syntax) will be more brittle than other interop code, limiting its usefulness in long-lived code.&lt;/p&gt;
&lt;p&gt;I understand the reasons for using hard errors (performance, clarity, simplicity), but I agree that it's a strange choice given Clojure's otherwise incredible flexibility and willingness to support a variety of usages.&lt;/p&gt;
&lt;p&gt;What is lost or degraded by falling back to reflection (and a reflection warning) in ambiguous cases?&lt;/p&gt;
</description>
<category>Clojure</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/13710/method-values-and-syntax-errors</guid>
<pubDate>Tue, 13 Feb 2024 14:16:48 +0000</pubDate>
</item>
</channel>
</rss>