Skip to content

Instantly share code, notes, and snippets.

@tomfaulhaber
Created February 25, 2012 06:28
Show Gist options
  • Save tomfaulhaber/1906914 to your computer and use it in GitHub Desktop.
Save tomfaulhaber/1906914 to your computer and use it in GitHub Desktop.
Simple pprint on a deftype
user> (deftype Foo [a b c])
user.Foo
user> (def f (Foo. "The quick brown fox jumped over the" "lazy dog" "Friends, Romans, and Countrymen, lend me your ears")) │····
#'user/f
user> (def e (Foo. 1 2 3))
#'user/e
user> (defn augmented-dispatch [f]
(if (instance? Foo f)
(cl-format true
"~<{~;~<a ~_~w~:>, ~_~<b ~_~w~:>, ~_~<c ~_~w~:>~;}~:>"
[[(.a f)] [(.b f)] [(.c f)]])
(simple-dispatch f)))
#'user/augmented-dispatch
user> (with-pprint-dispatch augmented-dispatch (pprint [e f]))
[{a 1, b 2, c 3}
{a "The quick brown fox jumped over the",
b "lazy dog",
c "Friends, Romans, and Countrymen, lend me your ears"}]
nil
user>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment