Null object: Difference between revisions

m
Line 1,027:
 
=={{header|Phix}}==
There is also a builtin NULL, however it is equivalent to the integer 0 and will trigger a type check if assigned to a variable declared as string or sequence. In most programs the zero-length string/sequence (""/{}) suffices,
Phix has a special unassigned value, that can be tested for using object(). There is no offical way to "un-assign" a variable, though you could fairly easily do so with a bit of inline assembly.
<lang Phix>object x
 
procedure test()
if object(x) then
puts(1,"x is an object\n")
else
puts(1,"x is unassigned\n")
end if
end procedure
 
test()
x = 1
test()</lang>
{{out}}
<pre>
x is unassigned
x is an object
</pre>
There is also a builtin NULL, however it is equivalent to the integer 0 and will trigger a type check if assigned to a variable declared as string or sequence. In most programs the zero-length string/sequence (""/{}) suffices,
but if you want a variable that can be a string/sequence or NULL, but not other arbitrary integer/float values, use something like the following user-defined types:
<lang Phix>type nullableString(object o)
Line 1,065 ⟶ 1,046:
q = NULL
--q = 1 -- error</lang>
See also [[Undefined_values#Phix|Undefined_values]]
 
=={{header|PHL}}==
7,818

edits