clojure 2025-12-07

i use babashka.fs for a bunch of stuff, and it works with java.nio.file.Path a bunch instead of with strings. that's fine, except when i try to use Path with the clojure standard library, like slurp, it throws an error that it can't open the path as an InputStream. would it be possible to extend slurp to accept paths and not just strings?

it looks like slurp just delegates to https://clojuredocs.org/clojure.java.io/reader, which already accepts Files, so maybe it could accept Paths too?

this is a gap in http://clojure.java.io - there's open issues for it

👍 1

you can use fs/file to convert a path to a file so clojure knows how to deal with it

gotcha, ty. i've been using str just so the error handling is all in one place

gosh that's an old ticket

You can upvote

once they started the Ask site, they closed the jira to public voting/discussion and created an Ask question for each open jira ticket. all voting and discussion now happens on that associated Ask

is the ask linked somewhere on the jira ticket? I don't see it

oh i see it's the link you originally posted

lol sorry, it's the clojure q/a site, at "http://ask.clojure.org", so we call the questions Asks

👍 1

it's for both general clojure-related questions and for bug reports/feature requests

what's the idiomatic way to write (do (f) nil)? i.e. discard the return value

Just throwing for fun (let [_ (f)])

if there's gonna be golfing it, then (if (f)) is smaller than when

I would also prefer (do (f) nil) for clarity though.

do like that is fine, it really depends on your goal, there often isn't a reason to "discard" the value at all

Using constantly is something that is slept on sometimes, like ((constantly nil) ...) but here the do is clearer

(when (f))

1
🤯 2

I'd definitely use (do ...), with a comment on why the value gets discarded.

(when (f)) can still return false

👍 1

in this case it was so that (defexpect) wouldn't try to treat it as an assertion

How can (when (f)) return false?

what about non-idiomatic ways? (#{(f)} nil) is a fun one

😆 1

(when (f)) is good golf but (do ... nil) is clearer, to my eye

👍 2