How to replace all values in an array with missing values?

Ah thanks for the correction! and sorry for the confusion, I had a wrong model of the memory layout for this kind of arrays (I thought each struct would be stored inline in the array). So here the undefined reference is not in A but in the array (so the compiler needs to add a check for #undef when accessing the array).

Then it’s better than I thought: it’s easier to check an array is well initialized, than to check initialization of all struct fields.

In other words, x.f or x[i] can be undefined but x cannot ever be undefined. That’s an significant difference and I’m not sure why you’re trying to insist that it’s no difference at all.

Not sure what you mean: I’m talking about these undefined x.f and x[i], not undefined x.

The point still stands with “opt out” being available (and to some extent also undefined array elements), though not as strongly as I thought.

The distinction is this: in Java, say, you can have an object reference x which, rather than being an instance of the type you want is null. That cannot happen in Julia: if you have x then it’s not null/undef. (There are undefined variables but that’s a different thing altogether.)

5 Likes

Ah yes it’s great that you cannot pass #undef around, no disagreement here as I wrote above:

I agree having no null value is a huge improvement, it makes it much less likely to have an “undefined reference” exception in practice.

1 Like

Wow, thanks for this very informative explanation!