clojure

jyn 2025-11-23T02:06:01.336789Z

is there a shorter way to write this code? it feels like a lot of duplication.

(if-let [head ('head some-map)] head)

jyn 2025-11-23T02:08:15.588719Z

oh wait i think this is just the same as ('head some-map) lol

πŸ˜‚ 1
2025-11-23T02:16:33.301349Z

Not exactly, equivalent for {head false}

exitsandman 2025-11-23T06:20:19.819709Z

(or ('head some-map) nil)
would be the exact equivalent to what you have there

πŸ‘ 2
mdiin 2025-11-23T08:59:37.241269Z

Or (get some-map 'head nil)

exitsandman 2025-11-23T09:10:16.965909Z

no, that yields false on {'head false}

mdiin 2025-11-23T09:26:35.672049Z

Ah yes, that is right.

2025-11-23T19:02:43.747799Z

Could someone show me a reproducible REPL use case for num? I'm planning on redoing the tests in clojure-test-suite but have been struggling to actually find a way to make num have observable behavior, at least in the REPL. My assumption was that some combination of int-array + ints + aget would allow me to extract a primitive/unboxed value that would fail (instance? java.lang.Integer ...) but I haven't managed to do so

2025-11-23T19:31:40.448939Z

Looks like there's a way to avoid reflection with it, is there a way to test whether reflection was used?

borkdude 2025-11-23T19:32:15.678049Z

you can capture *out* or *err* while compiling probably

2025-11-23T19:33:17.344499Z

Yeah I know there's *warn-on-reflection* and I could use binding with stdout/err like you're suggesting maybe deep_thinking

borkdude 2025-11-23T19:33:41.711969Z

user=> (binding [*err* (java.io.StringWriter.) *warn-on-reflection* true]  (load-string "(fn [x] (.length x))") (str *err*))
"Reflection warning, null:1:9 - reference to field length can't be resolved.\n"

1
πŸ’› 1
borkdude 2025-11-23T19:34:10.661899Z

But if you're doing this for other clojure dialects: this may be a highly specific JVM Clojure thing

borkdude 2025-11-23T19:34:40.730849Z

e.g. bb doesn't give any warnings on reflections. moreover. it always uses reflection for interop :-)

2025-11-23T19:36:37.739199Z

Yeah, it also appears there's a bug with how ClojureCLR handles num. I'd like to provide any sort of value to the tests for these whatsoever, but I think it'll have to be something very platform dependent to do that. My hope would be it would at least document what value, if any, is provided on a platform by platform basis for the function, which may at least save folks some effort in the future if they reach for it inappropriately

2025-11-23T19:46:53.973699Z

Not sure it helps at all, but

(definterface IChecker
  (isLong [^long l])
  (isLong [^Object l]))

(deftype Checker []
  IChecker
  (isLong  [this ^long l] true)
  (isLong [this ^Object l] false))

(let [l       (long 1)
      L       (num l)
      checker (Checker.)]
  [(.isLong checker l) (.isLong checker L)])
=> [true false]
instance? is always going to box its argument

1
πŸ’› 1
seancorfield 2025-11-23T20:44:02.087139Z

I've recently taken over maintenance of #slingshot and I've been mulling this issue: https://github.com/scgilardi/slingshot/issues/24 -- try+ cannot quite be used as a drop-in replacement for try because catch Exception e stops catching ex-info exceptions (and you need catch Object o instead). I've added a note as a comment on that issue, describing a potential fix for this (confusing) behavior that trips up quite a few people when they try to use Slingshot. My experiments so far indicate the new behavior seems backward-compatible with Slingshot, while making migration easier/less surprising, but I'd like to hear from more Slingshot users. Please either respond on that issue, or in a thread in #slingshot (since that will also get more Slingshot users into that channel!). Thanks!

austb 2025-11-24T21:48:25.588929Z

After the number of times slingshot has nullified our attempts at error handling causing serious escalations for customer facing issues, you won’t find me touching it with a 10 foot pole, so not really a user… but yes this sounds like an improvement over the current state of it