Skip to content

Instantly share code, notes, and snippets.

@danlentz
Created September 9, 2013 17:33
Show Gist options
  • Save danlentz/6498875 to your computer and use it in GitHub Desktop.
Save danlentz/6498875 to your computer and use it in GitHub Desktop.
clj-pprint
user=> (def attrs '([:db/cardinality :db.cardinality/one]
[:db/doc "Documentation string for an entity."]
[:db/fulltext true]
[:db/ident :db/doc]
[:db/valueType :db.type/string]))
user=> attrs
([:db/cardinality :db.cardinality/one] [:db/doc "Documentation string for an
entity."] [:db/fulltext true] [:db/ident :db/doc] [:db/valueType :db.type/string])
user=> (use 'clojure.pprint)
nil
user=> (def fmt "~:<~:@{[~25s ~30s]~:^~:@_~}~:>")
#'user/fmt
user=> (cl-format true fmt attrs)
([:db/cardinality :db.cardinality/one ]
[:db/doc "Documentation string for an entity."]
[:db/fulltext true ]
[:db/ident :db/doc ]
[:db/valueType :db.type/string ])
nil
;;;
Since you're interested in pprint/cl-format, I'll deconstruct the format string for you:
"~:<~:@{[~25s ~30s]~:^~:@_~}~:>" ; the entire format string
~:< ~:> ; creates a logical block
~:@{ ~} ; iterates through the vectors in the list
[ ] ; creates a pair of literal brackets
~25s ~30s ; creates a pair of fixed-width columns
~:^ ; breaks the iteration on the last pair
~:@_ ; creates a mandatory newline
user=> (let [keys ["Attribute" "Value"]]
(print-table keys (map (partial zipmap keys) attrs)))
=====================================================
Attribute | Value
=====================================================
:db/cardinality | :db.cardinality/one
:db/doc | Documentation string for an entity.
:db/fulltext | true
:db/ident | :db/doc
:db/valueType | :db.type/string
=====================================================
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment