The multimethods print-method and print-dup handle this.

- James


On 13 July 2014 18:51, Sam Raker <sam.ra...@gmail.com> wrote:

> I'm working my way through an intro to Clojure book, and I just got to the
> section on protocols. I might be missing something/committing a category
> error, but I'm wondering if there's a way to change the way a protocol is
> represented in the repl, akin to redefining `__repr__`/`__str__` in Python.
> The example protocol in the book involves a matrix (i.e., a vector of
> vectors). I can do this
>
> (extend-protocol Matrix
>     clojure.lang.IPersistentVector
>     ...
>     (pprint [vov] (clojure.pprint/pprint vov)))
>
>
> which works fine when I call (pprint m) on a Matrix m:
>
> (pprint m)
> ; [[0 0 0]
>    [0 0 0]
>    [0 0 0]]
>
> What I'd like is to just have the same behavior "calling" the variable
> from the repl, i.e.
>
> m
> ; [[0 0 0]
>    [0 0 0]
>    [0 0 0]]
>
>
> Can/should this be done? Is this a job for macros? Am I just being
> lazy/un-Clojuric and just get over it and use (pprint m)?
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to