On the `context` argument for `expressify`
Following up issue #1099, I think it would be good if the context argument to expressify was documented, as in: what is it, and how should expressify methods use it? As far as I can tell, it is ultimately passed down to sprint, so we could just say that.
Moreover, though, I think it is supposed to pass to any recursive expressify invocations. Yet this is not always done, e.g. from the AA sources:
function expressify(a::FracElem; context = nothing)
n = numerator(a, true)
d = denominator(a, true)
if isone(d)
return expressify(n)
else
return Expr(:call, ://, expressify(n), expressify(d))
end
end
and a bunch similar ones. Am I right in assuming these are not intentional, and we really should be adding a bunch of context=context args?
In that case, perhaps it would be worthwhile to reconsider whether context really should be an optional argument. Perhaps it should be required? Possibly even a positional argument instead of a keyword argument.
This one is for @thofma as my original concept of expressify did not have a context. Some things to consider:
- Does the ~:terse~:compact=>true go in the context?
- Can a :latex=>true go in the context? If yes, this would make Expr(:latex_form, a, b) a bit redundant.
- The :size_limit=>100 belongs in the io context and not the context to expressify.
Yes, it should be used recursively. We bolted it onto the system later and wanted to be backwards compatible. That is why it is a keyword argument with default value.
All properties can go into the context that we want, but then we have to be careful with the MIME types.
It is all a bit brittle and the julia printing "system" does not help much with consistency. For example, do you know which method is used to print the element p::MyType when displaying [p, p, p]? It checks whether
Base.show(io::IO, ::MIME"text/plain", p::MyType)
prints a new line and if not it calls
Base.show(io::IO, p::MyType)
(see https://github.com/JuliaLang/julia/issues/36253). There is no context flag indicating whether printing is invoked inside array printing. For dimension > 1 I think :compact => true is, but not for Vector.