Fork me on GitHub

Due to certain constraints, the program that needs a representation of the map isn't one of Clojure origins - but it is concerned with Clojure code, and I'm using babashka as a middleman, haha. Thanks guys, I got something working.


Can someone help me. Why multithread sval of lazy-seq will make the cpu to 100% useage?


got some code?


in performance-conscious code i often see stuff like (though obviously more complicated)

(let [local-constant (computation)]
  (defn foo []
is let faster than using def ?

Alex Miller (Clojure team)04:05:45

yes, but probably the scoping is actually the higher concern than performance

Alex Miller (Clojure team)04:05:53

def is global, let is local

Alex Miller (Clojure team)04:05:11

so using the let there means only foo will have access to local-constant


I just assume anything like that encountered in the wild is a premature optimization

💯 4

i see, that makes sense! thanks!


Or scoping wise someone being a jerk, because I can still get at local constant if I want by using reflection, but they just want to make my life harder


you can get a local using reflection?


But, to be clear, I wouldn’t consider it a “jerk move.” It tells you something about the utility of local-constant. It says, “this cannot be used outside of this function.” It can be more informative than a var.

👆 4

I usually assume if you’re looking at source, you can grab forms and run them at your leisure, even if scoping makes it hard 🙂


I spent a good chunk of the week before last using reflection to monkey patch part of a library we use (counting utf8 characters where the correct thing was counting utf16). I have definite views about about people making decisions about what parts of a program I have access to.

donotwant 4

Closed over data is stored in instance fields on fn objects, so you can reflect and get it


@hiredman I'm just not promising it'll be there later.


Otherwise I have to name it


anybody aware of a relatively lightweight clojure library for performing mathematical interpolation?


I wouldn't get my hopes up for something clojure specific, clojure is a poor platform for numerics generally. But if there's a java lib, this is the sort of thing that's easy to use without a wrapper.


clearly designed for animation smoothing rather than curve smoothing, though I imagine the math can be made to cross over


Maths is not my strong suit, but maybe ? It’s from the prolific mathematician/artist behind

💯 4

like linear, quadratic etc. for curve-fitting


But, to be clear, I wouldn’t consider it a “jerk move.” It tells you something about the utility of local-constant. It says, “this cannot be used outside of this function.” It can be more informative than a var.

👆 4

for those of you who uses emacs (evil-mode), which package do you use to handle s-expression manipulation and smart parentheses?


Anyone know what a "Not enough space" message from jmap means?

jmap -dump:format=b,file=heapdump.bin 9
Not enough space
Command exits with status 0. Not sure if the space it's talking about is disk or memory. I'm guessing it has something to do with memory... Trying to load the heapdump in visualvm gets stuck on the "Loading heap dump..." screen. Likely due to a malformed heapdump because of the Not enough space error.


not enough heap space is much more likely than not enough disk space (unless you are using docker with a small volume...)


The / fs is at 27% used :thinking_face:


df -h
Filesystem      Size  Used Avail Use% Mounted on
overlay          20G  5.4G   15G  27% /
tmpfs            64M     0   64M   0% /dev
tmpfs           3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/nvme0n1p1   20G  5.4G   15G  27% /dumps
shm              64M     0   64M   0% /dev/shm
tmpfs           3.9G   12K  3.9G   1% /run/secrets/
tmpfs           3.9G     0  3.9G   0% /proc/acpi
tmpfs           3.9G     0  3.9G   0% /sys/firmware
^ Doesn't appear to be close to hitting any storage limits. Wonder if this is some weird thing about docker not being able to create "large" files.


yeah, this is most likely a memory thing - can you do this again with twice the max heap limit in the jvm?


Perhaps. I was trying to avoid that since I don't have a repro for this issue yet.


The potentially malformed/incomplete heap dump file is a bit over 62mib.


you could try

jcmd <pid> GC.heap_dump <file-path>


Ooo, that went through. What's the difference in commands?


I'm not absolutely certain, it's supposed to end up doing the same thing, but it might not allocate memory where jamp would(?)


> It is recommended to use the latest utility, `jcmd` instead of `jmap` utility for enhanced diagnostics and reduced performance overhead. > - TIL


clearly there's some improvement if only one of them worked :D


I was a bit amused by this problem if it was a memory issue with getting a heap dump. In order to debug a memory leak, I need a heap dump. In order to get a heap dump, I need memory. 😆


this reminds me I want to try jdb again now that I have a better understanding of how clojure maps to the vm...


it would be interesting to have a clojure-friendly wrapper(s) for the various jdk cli tools


That could be interesting. What makes them Clojure unfriendly? The Clojure guts often surfacing?


for jdb, it's the fact that one clojure function call is indirected through multiple levels of interface methods and inner classes


I've looked at enough stack traces now that I'd be more likely to know what to do with it


also, jdb lets you evaluate arbitrary expressions in a scope, this would be much more interesting if those expressions could be piped into the clojure compiler instead of just being java pseudocode :D


How can I intentionally trigger a clojure.lang.LispReader$ReaderException? I seem to just get RuntimeExceptions around EOF.


what if you close the source stream then read?


that gives a Exceptioninfo, with ReaderExecption as the cause, yeah

Alex Miller (Clojure team)16:05:33

you're always going to get wrapping unless you're calling the reader directly


(read-string ":::") gives me a runtime exception. Does read-string work differently?


@dominicm look directly at *e - the cause is a ReaderException


same with (read-string ")") actually


Clojure 1.10.1
  (read-string ":::")
  (catch Exception e
    [(type e) (ex-data e) (ex-cause e)]))
[java.lang.RuntimeException nil nil]


Same for ")".


try just returning the exception:


user=> *e                                                                                                                                                                                                                                                               
#error {                                                                                                                                                                                                                                                                
 :cause "Unmatched delimiter: )"                                                                                                                                                                                                                                        
 [{:type clojure.lang.ExceptionInfo                                                                                                                                                                                                                                     
   :message nil                                                                                                                                                                                                                                                         
   :data #:clojure.error{:phase :read-source}                                                                                                                                                                                                                           
   :at [clojure.main$repl$read_eval_print__9086$fn__9087 invoke "main.clj" 433]}                                                                                                                                                                                        
  {:type clojure.lang.LispReader$ReaderException                                                                                                                                                                                                                        
   :message "java.lang.RuntimeException: Unmatched delimiter: )"                                                                                                                                                                                                        
   :data #:clojure.error{:line 1, :column 2}                                                                                                                                                                                                                            
   :at [clojure.lang.LispReader read "" 314]}                                                                                                                                                                                                            
  {:type java.lang.RuntimeException                                                                                                                                                                                                                                     
   :message "Unmatched delimiter: )"                                                                                                                                                                                                                                    
   :at [clojure.lang.Util runtimeException "" 221]}]                                                                                                                                                                                                           
 [[clojure.lang.Util runtimeException "" 221]            


user=> (try (read-string ":::") (catch Exception e e))
#error {
 :cause "Invalid token: :::"
 [{:type java.lang.RuntimeException
   :message "Invalid token: :::"
   :at [clojure.lang.Util runtimeException "" 221]}]
 [[clojure.lang.Util runtimeException "" 221]
  [clojure.lang.LispReader interpretToken "" 412]
  [clojure.lang.LispReader read "" 305]
  [clojure.lang.LispReader read "" 216]
  [clojure.lang.LispReader read "" 205]
  [clojure.lang.RT readString "" 1878]
  [clojure.lang.RT readString "" 1873]
  [clojure.core$read_string invokeStatic "core.clj" 3815]
  [clojure.core$read_string invoke "core.clj" 3805]
  [user$eval5 invokeStatic "NO_SOURCE_FILE" 1]
  [user$eval5 invoke "NO_SOURCE_FILE" 1]
  [clojure.lang.Compiler eval "" 7177]
  [clojure.lang.Compiler eval "" 7132]
  [clojure.core$eval invokeStatic "core.clj" 3214]
  [clojure.core$eval invoke "core.clj" 3210]
  [clojure.main$repl$read_eval_print__9086$fn__9089 invoke "main.clj" 437]
  [clojure.main$repl$read_eval_print__9086 invoke "main.clj" 437]
  [clojure.main$repl$fn__9095 invoke "main.clj" 458]
  [clojure.main$repl invokeStatic "main.clj" 458]
  [clojure.main$repl_opt invokeStatic "main.clj" 522]
  [clojure.main$main invokeStatic "main.clj" 667]
  [clojure.main$main doInvoke "main.clj" 616]
  [clojure.lang.RestFn invoke "" 397]
  [clojure.lang.AFn applyToHelper "" 152]
  [clojure.lang.RestFn applyTo "" 132]
  [clojure.lang.Var applyTo "" 705]
  [clojure.main main "" 40]]}
Same sort of stacktrace for *e too


I get the same result for your try/catch, but the prn of the object itself in the repl does show ReaderException


If I type ::: in the REPL, and check *e then I get something that looks like that you provided.


odd, I'm using 1.10.1

Alex Miller (Clojure team)16:05:52

oh, it only wraps in ReaderException if using a LineNumberingPushbackReader, which readString does not


Same, just in a clj - nothing fancy going on

Alex Miller (Clojure team)16:05:06

another possibly confusing bit is that ReaderException is also an ex-info (implements IExceptionInfo, but is not an ExceptionInfo instance)


Yeah, that's why I'm interested in it 😈


Although I've broken something really badly...

Execution error (VerifyError) at java.lang.Class/getDeclaredConstructors0 (                                                                        
Catch type is not a subclass of Throwable in exception handler 232                                                                                                
Exception Details:                                                                                                                                                
    io/dominic/try_PLUS_meander/core$eval19804.invokeStatic()Ljava/lang/Object; @232: astore_1                                                                    
    Type 'clojure/lang/IExceptionInfo' (constant pool 140) is not assignable to 'java/lang/Throwable'                                                             
    0x0000000: b200 0fb6 0014 c000 16bb 0018 59bb 001a                                                                                                            
    0x0000010: 5912 1cc0 001e b700 21c0 0023 b700 26b9                                                                                                            
    0x0000020: 002a 0200 57b2 002d b600 14c0 0016 122f                                                                                                            
    0x0000030: b200 33b9 0036 0300 c000 38bf 00bf 0000                                                                                                            
    0x0000040: 00bf 0000 bf4c b200 424b a701 754c b200        
Quite impressive!


I guess IExceptionInfo can't be caught on. You can't generally treat ReaderException and ExceptionInfo.

Alex Miller (Clojure team)17:05:04

Java depends on the exception class hierarchy

Alex Miller (Clojure team)17:05:20

so you can't really do things you'd want interface wise


I'm not sure I really get java, but my first thought is that ReaderException should extend ExceptionInfo instead. But I'm betting it's not possible.

Alex Miller (Clojure team)17:05:00

pretty sure I looked at that option though when I added this in 1.10

Alex Miller (Clojure team)17:05:24

I don't remember now why I didn't do that


It does extend RuntimeException, I'm betting you can't extend multiple classes like that in Java (is that multiple inheritance?).

Alex Miller (Clojure team)17:05:04

you can't, but you wouldn't need to

Alex Miller (Clojure team)17:05:25

ReaderException < ExceptionInfo < RuntimeException would be same effect

Alex Miller (Clojure team)17:05:34

this patch seems like it would have been an alternative

Alex Miller (Clojure team)17:05:03

I would have to scrounge through some old notes to see if I tried that and if so why I didn't do that. I do recall trying several things in this area.

Alex Miller (Clojure team)17:05:08

would really need a much more thorough review to see if there are any catch sites that catch both ExceptionInfo and ReaderException to ensure those are still properly differentiated


Is there a way to write a reporter for cognitect/test-runner? I want to spit out a JSON report


I could simply switch to kaocha…but wondering if there is a way to extend it

Alex Miller (Clojure team)17:05:41

it just runs clojure.test, which does have some notion of being able to customize reporting


So I can simply implement the multimethod and it should work?


Cool, got it. Yeah I’ve tinkered with it before, should be able to do so. Thanks


Thanks Alex. Both are good starting points

Alex Miller (Clojure team)17:05:34

you might have to wrap test-runner to make this runnable via clj though


Sure, I’ll have to plug intot he test-runners run-test call

Alex Miller (Clojure team)17:05:14

if you can get to the point where you have a more precise idea of what you need, would be happy to look at changing test-runner - I know there's already at least one pr towards this


An easy thing that can be done is to simply provide an option that takes a namespace/fn which is the override multimethod and run all tests binding clojure.test/report with this provided namespace/fn

Alex Miller (Clojure team)17:05:21

well, would be more interested in evaluating options than doing the first easy thing we can think of :)


My general use case tends to be running a bunch of tests against source code that interns turn in and generating a JSON based report that I can then turn into either an html page or an email or something. I do this for JS and C and so on. I hacked together a solution with Kaocha, but there’s a bit more there than I need


if I (def my-map {:a {} :b {} :c {}}) is guaranteed that (for [[k _] my-map] k) will return (:a :b :c) ? as far as i understood deps.edn use the fact that :deps {...} preserve the order.


if so, they are using an alternative ordered implementation when reading hash-maps


maps are explicitly not ordered


i don't believe so. which is i suppose why deps.edn uses top level and newest rather than first version it finds? since first found isn't well defined


as far I understand tools.deps behavior: if a depends on [email protected] and b depends on [email protected] - clj -Sdeps "{:deps {a {...} b {...}}}" will use [email protected] - clj -Sdeps "{:deps {b {...} a {...}}}" will use [email protected] (pick first algorithm)


so the one picked is determined by hash order? that's weird


that is not correct

👍 4

and it is a verifiable hypothesis


you can experiment with resolution using clj -Stree @souenzzo


> top level and newest rather i thought alex had been very specific that he does not copy maven's first encountered version

Alex Miller (Clojure team)21:05:00

both cases you've described should use [email protected]

👍 4
Alex Miller (Clojure team)21:05:09

maven is actually what you describe

Alex Miller (Clojure team)21:05:05

"first found" is well-defined in maven (by sibling order in pom.xml) and in lein (b/c deps is a vector, not a map)