Null object: Difference between revisions
Content added Content deleted
Line 1,027: | Line 1,027: | ||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
⚫ | |||
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> |
|||
⚫ | |||
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: |
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) |
<lang Phix>type nullableString(object o) |
||
Line 1,065: | Line 1,046: | ||
q = NULL |
q = NULL |
||
--q = 1 -- error</lang> |
--q = 1 -- error</lang> |
||
See also [[Undefined_values#Phix|Undefined_values]] |
|||
=={{header|PHL}}== |
=={{header|PHL}}== |