clojure

2026-03-27T19:25:11.084239Z

anyone thought about a precompiler for clojure.pprint/cl-format that accepts an intuitive sexp based grammar rather than "<~a~{~^ ~a=\"~a\"~}~:[~;/~]>~%" — similar to the regex grammar in (common-lisp’s) cl-ppcre?

oyakushev 2026-03-31T07:52:17.751299Z

@alexmiller I've used cl-format more times than refs, agents, and structs combined. Having it in the core is one of the most whimsical and fun decisions in Clojure 🙂

❤️ 1
2026-03-31T19:00:35.806419Z

turns out that the hiccup model is a pretty ideal DSL for format strings

2026-03-31T19:13:19.513399Z

and everyone already knows it

dan.lentz 2026-04-01T20:46:45.747879Z

ok check out https://github.com/danlentz/clj-format if you're interested. feedback welcome.

Alex Miller (Clojure team) 2026-03-27T19:42:28.557919Z

what's not intuitive about that?

Alex Miller (Clojure team) 2026-03-27T19:42:54.774469Z

trollface

😂 5
☝️ 1
Alex Miller (Clojure team) 2026-03-27T19:45:22.591869Z

cl-format is a strange and wonderful place, but it is at least connected to a https://www.lispworks.com/documentation/HyperSpec/Body/f_format.htm#format. in the fullness of time, maybe this shouldn't have been in core in the first place

2026-03-27T19:51:32.384839Z

its awesome, if a bit long in the tooth. maybe in the early days helped persuade some CL devs. But maybe having in core is good because you don’t have every project trying to build a half-working bespoke version.

2026-03-27T20:01:36.970489Z

ha i’d like to see someone build a clojure.spec for it

2026-03-27T20:07:17.134779Z

maybe that amounts to basically the same thing

2026-03-27T20:31:15.507689Z

this isn’t even sporting with claude. com.github.danlentz/clj-format on the way

2026-03-27T22:20:07.704419Z

oof ok the DSL for this is not pretty

dan.lentz 2026-03-27T22:36:39.394749Z

this seems 0% better:

Input:  "<~a~{~^ ~a=\"~a\"~}~:[~;/~]>~%"                                                                              
                                                                                                                        
  Output: ["<" :str [:each :stop " " :str "=\"" :str "\""] [:if "/" nil] ">" :nl]     

dan.lentz 2026-03-27T23:20:25.106679Z

i am now remorseful for going down this path

😄 1
dan.lentz 2026-03-27T23:29:46.320949Z

i dunno. is this useful? ### Left-padded

clojure
(cl-format nil "~10@A" "foo")
(clj-format nil [[:str {:width 10 :pad :left}]] "foo")
;; => "       foo"
## Integer Formatting ### Comma-grouped
clojure
(cl-format nil "~:D" 1000000)
(clj-format nil [[:int {:group true}]] 1000000)
;; => "1,000,000"
### Always show sign
clojure
(cl-format nil "~@D" 42)
(clj-format nil [[:int {:sign :always}]] 42)
;; => "+42"
### Zero-padded date Source: Practical Common Lisp ch. 18
clojure
(cl-format nil "~4,'0D-~2,'0D-~2,'0D" 2005 6 10)

(clj-format nil
  [[:int {:width 4 :fill \0}] "-"
   [:int {:width 2 :fill \0}] "-"
   [:int {:width 2 :fill \0}]]
  2005 6 10)

;; => "2005-06-10"
### European-style grouping (dot separator, groups of 4)
clojure
(cl-format nil "~,,'.,4:D" 100000000)
(clj-format nil [[:int {:group-sep \. :group-size 4 :group true}]] 100000000)
;; => "1.0000.0000"

dan.lentz 2026-03-27T23:36:42.205469Z

its 100% DSL<->FormatString compatibility at this point. i'm sure there is a lot of AI slop at the moment but wondering if its worth the effort

dan.lentz 2026-03-28T00:08:37.021729Z

maybe it would be useful if the language was extended to support ANSI color?

dan.lentz 2026-03-28T00:12:17.878089Z

i guess only if you use babashka or something that assumes TTY

dan.lentz 2026-03-28T01:22:07.998249Z

https://github.com/danlentz/clj-format/blob/master/doc/examples.md if anyone finds something like this helpful i'll polish it https://github.com/danlentz/clj-format/blob/master/doc/examples.md

dan.lentz 2026-03-28T01:30:34.356649Z

this is way better than format strings

dan.lentz 2026-03-28T02:32:50.750909Z

actually ill definitely clean this up i would use it 10 times out of 10 over format strings

2026-03-27T19:55:46.430009Z

I have a proxy implementation of Thread which computes some blocking computation, and I am using it interactively during devtime, and running into an issue; specifically, the proxy also implements IDeref to allow effectively getting the returned value of the form used to construct the Thread as a return result from the thread, and this is interacting poorly with the printer. I can set the .toString implementation to not await, however it appears that this only helps in cases where I call out to str and similar, meanwhile println and the functions used by nrepl (presumably print-method) are calling to the IDeref default implementation for printing the object, which in my case is blocking on the thread to complete. Is there a way for me to construct a value similar to the method I have been using that will allow print-method to be overridden in a way that allows my code not to block on the thread's completion when using it interactively?

dpsutton 2026-03-27T19:57:03.829369Z

been a bit since i’ve been in this, but have you seen the IPending stuff as well?

dpsutton 2026-03-27T19:57:12.123329Z

this is a way to make sure the printer doesn’t just hang i think

dpsutton 2026-03-27T19:58:56.024329Z

connection=> (print (future (Thread/sleep 2000) (println "done from the thread")))
#future[<pending>]nil
connection=> 
done from the thread
which is why this works

dpsutton 2026-03-27T20:02:36.804149Z

(time (print (reify clojure.lang.IDeref
               (deref [_]
                 (Thread/sleep 2000)
                 (println "done from the deref")
                 :derefed))))
done from the deref
#connection$eval485774$reify__485775[:derefed]
"Elapsed time: 2011.382208 msecs"
vs
(time (print
        (let [value (atom nil)]
          (reify
            clojure.lang.IDeref
            (deref [_]
              (Thread/sleep 2000)
              (println "done from the deref")
              (reset! value :derefed)
              :derefed)
            clojure.lang.IPending
            (isRealized [_] (not= nil @value))))))
#connection$eval485780$reify__485781[<pending>]
"Elapsed time: 2.816042 msecs"
nil

2026-03-27T20:06:48.848939Z

I had not seen IPending, thanks!

👍 1