Drop-in replacement for clojure.pprint/cl-format.
When the format argument is a string, delegates directly to cl-format. When it is a DSL form (vector or keyword), compiles it to a format string first, then invokes cl-format with the result.
Drop-in replacement for clojure.pprint/cl-format. When the format argument is a string, delegates directly to cl-format. When it is a DSL form (vector or keyword), compiles it to a format string first, then invokes cl-format with the result.
(clj-format writer fmt & args)Format args according to fmt, writing to writer.
fmt can be:
writer can be:
Examples: (clj-format nil "~D item~:P" 5) ;; => "5 items" (clj-format nil [:int " item" [:plural {:rewind true}]] 5) ;; => "5 items" (clj-format nil [:each {:sep ", "} :str] [1 2 3]) ;; => "1, 2, 3" (clj-format true "Hello ~A!" "world") ;; prints, returns nil
Format args according to fmt, writing to writer.
fmt can be:
- a string — passed directly to cl-format (full backward compatibility)
- a vector — compiled from DSL to a format string, then passed to cl-format
- a keyword — shorthand for a single bare directive (e.g., :str for ~A)
writer can be:
- nil/false — returns the formatted string
- true — prints to *out*, returns nil
- a Writer — writes to that writer, returns nil
Examples:
(clj-format nil "~D item~:P" 5) ;; => "5 items"
(clj-format nil [:int " item" [:plural {:rewind true}]] 5) ;; => "5 items"
(clj-format nil [:each {:sep ", "} :str] [1 2 3]) ;; => "1, 2, 3"
(clj-format true "Hello ~A!" "world") ;; prints, returns nil(compile-format dsl)Compile a clj-format DSL form into a cl-format string.
Examples: (compile-format :str) ;; => "~A" (compile-format [:str {:width 10}]) ;; => "~10A" (compile-format [:cardinal " file" [:plural {:rewind true}]]) ;; => "~R file~:P"
Compile a clj-format DSL form into a cl-format string.
Examples:
(compile-format :str) ;; => "~A"
(compile-format [:str {:width 10}]) ;; => "~10A"
(compile-format [:cardinal " file" [:plural {:rewind true}]])
;; => "~R file~:P"(parse-format s)Parse a cl-format string into the clj-format DSL.
Examples: (parse-format "~A") ;; => [:str] (parse-format "Hello ~A!") ;; => ["Hello " :str "!"] (parse-format "~R file~:P") ;; => [:cardinal " file" [:plural {:rewind true}]]
Parse a cl-format string into the clj-format DSL.
Examples:
(parse-format "~A") ;; => [:str]
(parse-format "Hello ~A!") ;; => ["Hello " :str "!"]
(parse-format "~R file~:P") ;; => [:cardinal " file" [:plural {:rewind true}]]cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |