Null object: Difference between revisions
Content added Content deleted
(added factor example) |
(Added Oz explanation.) |
||
Line 266: | Line 266: | ||
| None -> "unbound value" |
| None -> "unbound value" |
||
| Some _ -> "bounded value"</lang> |
| Some _ -> "bounded value"</lang> |
||
=={{header|Oz}}== |
|||
There is no explicit null in Oz. |
|||
===Unbound variables=== |
|||
If an unbound variable is accessed, the current thread will be suspended: |
|||
<lang oz>declare |
|||
X |
|||
in |
|||
{Show X+2} %% blocks</lang> |
|||
If you later assign a value to X in another thread, the original thread will resume and print the result of the addition. This is the basic building block of Oz' [http://c2.com/cgi/wiki?DeclarativeConcurrency declarative concurrency]. |
|||
===Undefined values=== |
|||
Access to undefined values will usually provoke an exception in Oz. |
|||
It is also possible to assign a unique "failed" value to a variable. Such a failed value encapsulates an exception. This can be useful in concurrent programming. |
|||
<lang oz>declare |
|||
X = {Value.failed dontTouchMe} |
|||
in |
|||
{Wait X} %% throws dontTouchMe</lang> |
|||
Sometimes algebraic data types like Haskell's Maybe are simulated using records. |
|||
<lang oz>declare |
|||
X = just("Data") |
|||
in |
|||
case X of nothing then skip |
|||
[] just(Result) then {Show Result} |
|||
end</lang> |
|||
=={{header|Perl}}== |
=={{header|Perl}}== |