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?
Scripts like (inc 1) - most likely yes.
Scripts like (vec (range 10000000)) - definitely no.
Perhaps, I should use node.js or babashka for 128MB of heap?
How much RAM does a vector of 10 million elements consume?
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.
+1 for clj-memory-meter, just used it to find a memory "leak"
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?
Excellent, thanks!
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)
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
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.
huh
So this file made a problem: https://github.com/scicloj/metamorph.ml/blob/528c5692b5f846fe26f7d66139c46017f7d77ead/src/scicloj/ml/xgboost.clj
https://github.com/clojure/clojure/blob/master/src/clj/clojure/core.clj#L5956-L5967
deleting it fixed it, and it "took" the other one.
something must have changed in load maybe
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=>
oh https://github.com/clojure/clojure/blob/master/src/clj/clojure/core.clj#L5991
I had the same filename twice on classpath....,no sure this changes.
user=> (require '[foo :as f])
Syntax error compiling at (REPL:1:1).
namespace 'foo' not found after loading '/foo'
user=>
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.
(even without ns declaration ?)
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
ahhhh, intresting
indeed....
(require '[scicloj.ml.xgboost :as xgboost])
gives error, but not:
(require '[scicloj.ml.xgboost))if there is no :as, you are presumably loading for side effects (of which there may be none)
yes, indeed, I load for side effect.
I think even without :as, it should throw
was hard to figure out what happened....
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
there may be something here, not trying to discount that, just trying to post rationalize
I thought about some of this last for :as-alias as that is a case where you are explicitly NOT loading
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 nsbut :as-alias still calls create-ns
the code for this also hasn't changed in a long time, so this behavior has been the case for a long time
it is helpful to mentally separate load (from disk) and create (in runtime). we usually do these together but they are (mostly) independent
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')
an Ask Clojure about this would be fine
https://ask.clojure.org/index.php/15022/why-does-requiring-from-an-empty-clj-creates-an-empty-ns
afaict, loading the empty file does not create a namespace
how did you get to the ExecutionError you posted above?
the execution error is just what happens when you try to do something with the namespace that doesn't exist
which seems correct (the namespace wasn't defined and wasn't created)
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 thatthe main "problem" seems to be ^^ that difference of behavior
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