clojure

doojin 2026-04-02T06:24:37.084109Z

For a simple JVM clojure process that is reserved for running one SCI script at a time for server-side HTML rendering, does -Xmx128m suffice?

p-himik 2026-04-02T07:03:18.719219Z

Scripts like (inc 1) - most likely yes. Scripts like (vec (range 10000000)) - definitely no.

doojin 2026-04-02T07:03:56.316679Z

Perhaps, I should use node.js or babashka for 128MB of heap?

doojin 2026-04-02T07:04:51.044049Z

How much RAM does a vector of 10 million elements consume?

p-himik 2026-04-02T07:07:02.787919Z

You can try using https://github.com/clojure-goes-fast/clj-memory-meter to measure. But I don't know how to apply it to whatever sci does.

reefersleep 2026-04-02T08:21:50.418499Z

+1 for clj-memory-meter, just used it to find a memory "leak"

jmckitrick 2026-04-02T11:32:33.591959Z

Does anyone know of a code complexity tool for clojure that easily integrates into the build cycle? For example, something that builds on a linter by setting 'max-depth' or 'max-lines-in-functions' and similar metrics to manage code complexity, whether generated by AI or human?

jmckitrick 2026-04-02T12:39:05.498669Z

Excellent, thanks!

2026-04-02T18:18:59.803389Z

I had today a very interesting "edge" case, of what in clojure "defines a ns". I was working on two libs at the same time, and for debugging I copied (temporary) code from one to the other, and then "commented" it out (but kept the file) so I had dependency situation: lib1: src/a/b/x.clj (this file was empty, better said all commented) lib2: src/a/b/x.clj (this was real code) Declaring in third project a dependency to "lib1" and "lib2" , did the "wrong" thing: (require '[a.b.x]) created an "empty" ns "a.b.x" (and ignored the non empty 'src/a/b/x.clj' of lib2) So an "empty" clj file in the right place made clojure "find and create the ns" (empty and it stopped searching further) . (I would expect that at least an "ns" declaration would be needed to create a ns, so I thought that the first (empty) clj file would be fully ignored regarding ns creation/searching)

2026-04-02T18:22:30.623599Z

you should get an error if there really is no ns declaration, the namespace won't be created if there isn't one, and require checks to see if the expected namespace was created after loading the file

2026-04-02T18:23:34.017759Z

nop. no error. Juts a very fast ending (require) which surprised me, as the "real one" did printing on "geting required". and it was all commented.

2026-04-02T18:24:24.986829Z

huh

2026-04-02T18:27:07.305189Z

deleting it fixed it, and it "took" the other one.

2026-04-02T18:27:13.323489Z

something must have changed in load maybe

2026-04-02T18:28:33.818569Z

clj -Sdeps '{:paths ["."]}'
Clojure 1.12.4
user=> (spit "foo.clj" "")
nil
user=> (require 'foo)
nil
user=> (require 'bar)
Execution error (FileNotFoundException) at user/eval5 (REPL:1).
Could not locate bar__init.class, bar.clj or bar.cljc on classpath.
user=> *clojure-version*
{:major 1, :minor 12, :incremental 4, :qualifier nil}
user=>

2026-04-02T18:29:32.995959Z

I had the same filename twice on classpath....,no sure this changes.

2026-04-02T18:29:40.503179Z

user=> (require '[foo :as f])
Syntax error compiling at (REPL:1:1).
namespace 'foo' not found after loading '/foo'
user=>

Alex Miller (Clojure team) 2026-04-02T18:30:47.269329Z

only the "first" one on the classpath is relevant, the second will not be seen via resource loading. and an empty file is still a file.

2026-04-02T18:31:28.790599Z

(even without ns declaration ?)

2026-04-02T18:32:07.225669Z

it seems like the intent is to throw if you require something that doesn't create the ns, but that only happens if you have an :as in your require clause

2026-04-02T18:32:22.924249Z

ahhhh, intresting

2026-04-02T18:33:54.784249Z

indeed....

(require '[scicloj.ml.xgboost :as xgboost])
gives error, but not: (require '[scicloj.ml.xgboost))

Alex Miller (Clojure team) 2026-04-02T18:34:10.891989Z

if there is no :as, you are presumably loading for side effects (of which there may be none)

2026-04-02T18:34:37.764509Z

yes, indeed, I load for side effect.

2026-04-02T18:35:36.140609Z

I think even without :as, it should throw

2026-04-02T18:35:50.084029Z

was hard to figure out what happened....

2026-04-02T18:36:35.555419Z

I guess I assumed that when you require a namespace you "cause (it) to be necessary." and if you just want to load a random file and not care about the namespace you can use load or :load in the ns macro

Alex Miller (Clojure team) 2026-04-02T18:37:03.843069Z

there may be something here, not trying to discount that, just trying to post rationalize

Alex Miller (Clojure team) 2026-04-02T18:37:42.405609Z

I thought about some of this last for :as-alias as that is a case where you are explicitly NOT loading

2026-04-02T18:38:21.843229Z

To me it is "strange" that in extacly that situation (whuich is edge case, of couse):

(require '[scicloj.ml.xgboost :as xgboost])
throws a nice and informative error message, but
(require '[scicloj.ml.xgboost])
throws nothing and creates an empty ns

2026-04-02T18:38:48.561019Z

but :as-alias still calls create-ns

2026-04-02T18:39:58.013679Z

the code for this also hasn't changed in a long time, so this behavior has been the case for a long time

Alex Miller (Clojure team) 2026-04-02T18:41:11.661169Z

it is helpful to mentally separate load (from disk) and create (in runtime). we usually do these together but they are (mostly) independent

2026-04-02T18:41:24.172949Z

in second case, I get error only once I use the ns: ; Execution error (ClassNotFoundException) at http://java.net.URLClassLoader/findClass (URLClassLoader.java:445). ; scicloj.ml.xgboost (and vscode is confused as well and even makes 'completion proposals')

Alex Miller (Clojure team) 2026-04-02T18:42:27.543949Z

an Ask Clojure about this would be fine

👍 1
Alex Miller (Clojure team) 2026-04-02T20:16:51.444219Z

afaict, loading the empty file does not create a namespace

Alex Miller (Clojure team) 2026-04-02T20:17:42.041959Z

how did you get to the ExecutionError you posted above?

2026-04-02T20:18:56.844419Z

the execution error is just what happens when you try to do something with the namespace that doesn't exist

Alex Miller (Clojure team) 2026-04-02T20:20:33.160479Z

which seems correct (the namespace wasn't defined and wasn't created)

2026-04-02T20:20:37.421719Z

Clojure 1.12.4
user=> (spit "foo.clj" "")
nil
user=> (require 'foo)
nil
user=> (require '[foo :as f])
Syntax error compiling at (REPL:1:1).
namespace 'foo' not found
user=>
is the issue, the difference of behavior with and without the :as when the file is empty, everything else is confusion arising from that

Alex Miller (Clojure team) 2026-04-02T20:20:50.861049Z

the main "problem" seems to be ^^ that difference of behavior

👍 1
Alex Miller (Clojure team) 2026-04-02T20:28:08.704699Z

other interesting adjacencies:

user=> (use 'foo)
Syntax error compiling at (REPL:1:1).
namespace 'foo' not found after loading '/foo'
user=> (compile 'foo)
Execution error (NullPointerException) at user/eval3 (REPL:1).
Cannot invoke "clojure.lang.PersistentVector.count()" because "objx.constants" is null