Created
September 9, 2013 17:33
-
-
Save danlentz/6498875 to your computer and use it in GitHub Desktop.
clj-pprint
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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