Syntax for show
for Arrays with undef elements?
#41947
Labels
arrays
[a, r, r, a, y, s]
display and printing
Aesthetics and correctness of printed representations of objects.
@nassarhuda and I were talking about this this morning, and we were wondering:
Currently vectors with undefined elements print in
show
with those elements printed as#undef
. But this of course is not a valid identifier (it looks like a comment).We've made great strides towards always printing valid julia code for 2-arg
Base.show
for most types and containers, via efforts like #32408, #32423, and others.It would be nice to tie up this neatly for Arrays as well!
Here's an example of the currently not working behavior:
We could maybe take the approach of creating a separate value/identifier that could be printed here, which indicates that the
[...]
expression should leave those elements undefined.We of course cannot use the existing
undef
value for that, because someone might already be puttingundef
into vectors for whatever reasons (i.e.[undef, 1, undef]
is already valid syntax).We could create a new value for this, maybe like
var"#undef"
, and just tell people "Hey this value can't be put in array literals. Sorry! :)".So I propose something like this:
And then change the
[]
constructor to skipvar"#undef"
elements, so something like changing:julia/base/array.jl
Lines 416 to 423 in e4a6f1d
to:
With this change, the display of vectors could be changed so that if it contained undefined slots, it would display those slots as
var"#undef"
. For example, something like this:Thoughts? :) Thanks!
The text was updated successfully, but these errors were encountered: