Null object: Difference between revisions

Added Tailspin solution
(Added Tailspin solution)
Line 1,905:
print("variable is nil")
}</lang>
 
=={{header|Tailspin}}==
Tailspin does not have a null value, but a transform is allowed to produce nothing at all, in which case that chain of computation simply stops. A templates transform can explicitly label cases as producing nothing by !VOID but also input values for which there is no matching branch will produce nothing. If you need computation to continue even in the event of nothing being produced, you can wrap the transform in an array/list to get an empty list.
<lang tailspin>
templates mightBeNothing
when <=0> do !VOID
when <=1> do 'something' !
end mightBeNothing
 
1 -> mightBeNothing -> 'Produced $;. ' -> !OUT::write
 
0 -> mightBeNothing -> 'Won''t execute this' -> !OUT::write
2 -> mightBeNothing -> 'Won''t execute this' -> !OUT::write
 
// capture the transform in a list to continue computation when no result is emitted
[1 -> mightBeNothing] -> \(
when <=[]> 'Produced nothing. ' !
otherwise 'Produced $(1);. ' !
\) -> !OUT::write
 
[0 -> mightBeNothing] -> \(
when <=[]> 'Produced nothing. ' !
otherwise 'Produced $(1);. ' !
\) -> !OUT::write
 
[2 -> mightBeNothing] -> \(
when <=[]> 'Produced nothing. ' !
otherwise 'Produced $(1);. ' !
\) -> !OUT::write
</lang>
{{out}}
<pre>Produced something. Produced something. Produced nothing. Produced nothing. </pre>
 
It is an error to try to assign nothing to a symbol or field.
<lang tailspin>
// throws an error
def nothing: 0 -> mightBeNothing;
 
// throws an error
{ nothing: 0 -> mightBeNothing }
 
// OK, simply results in the empty structure without a field called 'nothing'
{ 0 -> mightBeNothing -> (nothing: $) }
</lang>
 
=={{header|Tcl}}==
Anonymous user