Hi,
This question may look silly, but so far I haven't
found a satisfying answer in the doc (maybe because
I didn't look at the right places or because I
misinterpreted what I read).
For which reason do these two procs behave
differently? (Head2 suspends)
proc {Head1 Xs ?R}
case Xs of
nil then R=unit
[] H|_ then R=H
end
end
proc {Head2 Xs ?R}
case Xs of
nil then R=unit
[] !R|_ then skip % <--- use the "!"
end
end
The tutorial says:
"Let us assume that expression E is evaluated to V.
Executing the case statement will sequentially try
to match V against the patterns Pattern_1, Pattern_2,
...,Pattern_n in this order. Matching V against
Pattern_i is done in left-to-right depth-first manner.
o If V matches Pattern_i without binding any variable
occuring in V, the corresponding Si statement is
executed.
o If V matches Pattern_i but binds some variables
occuring in V, the thread suspends
o If the matching of V and Pattern_i fails, V is tried
against the next pattern Pattern_i+1, otherwise the
else statement S is executed."
Now, in {Head2 [a b c]}, E (Xs) evaluates to [a b c], a
fully determined value, so should not suspend by the
second "rule" above.
A few lines further, it also says:
"Now remember again that the case statement and its
executing thread may suspend if X1 is insufficiently
instantiated to decide the result of the matching. "
If this is the reason why Head2 suspends, in what manner
is Head2's R "less instantiated" than Head1's H when the
case statement is executed?
Regs,
Alain
-
Please send submissions to users@mozart-oz.org
and administriva mail to users-request@mozart-oz.org.
The Mozart Oz web site is at http://www.mozart-oz.org/.