Skip to content

isnull

builtin · libnexusinterp/nexus-value/ov-null-mat-proprietary.cc

: tf = isnull (x)

Return true when x carries the internal null marker given to a literal [], "", or '' written directly in source.

A value can be empty without being null. The interpreter tags the empty result of a bare literal as null so that, during indexed assignment, it can tell a deletion request apart from the assignment of an ordinary empty value. This distinction is what a user class needs when it overloads subsasgn, so isnull rather than isempty is the correct test there. Consider:

A(I) = []

versus

X = []; A(I) = X

In the first statement the right-hand side is the literal [], which is null; provided the index I is non-empty, the elements it selects should be removed from A. In the second statement the right-hand side is empty but not null, because it arrives through the variable X; the empty value should instead be assigned into the selected positions. The null marker is lost as soon as the literal is bound to a variable, which is why the two cases differ.

The built-in char type shows the same rule in action:

str = "Hello World";
nm = "Wally";
str(7:end) = nm                # indexed assignment
  ⇒  str = Hello Wally
str(7:end) = ""                # indexed deletion
  ⇒  str = Hello