Julia: print() vs. show() for enums

Created on 11 Mar 2016  路  6Comments  路  Source: JuliaLang/julia

In https://github.com/JuliaLang/julia/pull/13900 I had changed the printing of enums in order to get this:

julia> @enum Fruit apple orange kiwi

julia> apple
apple::FRUIT = 1

This no longer works on master:

julia> apple
apple

I understand that print is now used instead of show. What function should now be implemented to achieve the same result? I guess we still need one compact version which doesn't print the type. See https://github.com/JuliaLang/julia/blob/892b9406e3c68a56e43587de740520c16dd0f6d8/base/Enums.jl#L88 for how it's done currently.

help wanted regression

Most helpful comment

That should be a by-name enum of verbosity levels rather than numbers

All 6 comments

This is due to the IOContext objects now used for printing (4706184a424eda72aa802f465c7f45c5545143e0). I think the problem is that there is only one kind of output-limiting flag, limit_output. We should introduce more verbosity levels, for example

0 = small summary, e.g. suitable for printing as one array element
1 = collections are truncated, everything else shown as normal
2 = show everything

The default would be 1, with 0 used inside arrays.

That should be a by-name enum of verbosity levels rather than numbers

So limit_output should be changed from a Bool to an enum?

That should be a by-name enum of verbosity levels rather than numbers

+1. Also +1 to the multiple levels of verbosity.

Enum is fine by me.

Fixed by #16354.

Was this page helpful?
0 / 5 - 0 ratings