Show() and sisters


Hi, here is my code :

julia> using Primes

julia> f=factor(binomial(30,12))
3 ⋅ 5^2 ⋅ 7 ⋅ 13 ⋅ 19 ⋅ 23 ⋅ 29

julia> repr(f)

julia> string(f)

Primes.Factorization has a nice show() method, but how to build a string from this representation ?

julia> reprmime("text/plain", f)
"3 ⋅ 5^2 ⋅ 7 ⋅ 13 ⋅ 19 ⋅ 23 ⋅ 29"


Wow, thank you a lot, this function is well hidden in the doc !


I did not find it from the docs, if you ?repr it shows up in the search.


You’re right, but I used the doc, where repr and string are in (that looks fine :-),
whereas reprmime and stringmime are in .

Anyway imho repr should be the good answer.


repr is equivalent to show(io, x), whereas reprmime (documented here) is equivalent to show(io, mime, x). The latter defaults to the former for text/plain, but it is sometimes desirable to distinguish the two, as described here:

Usually, you want repr(x) to be a form that you could use to enter the same object, i.e. includestring(repr(x)) should usually work. Whereas the text/plain version might be a more pretty-printed output that is designed for human consumption, not computer parsing.

That being said, I suspect that we should rename reprmime(mime, x) to repr(mime, x), just as writemime(io, mime, x) was renamed to show(io, mime, x).