Hello,

Understanding the case statement is difficult for me. I'm reading CTM. The
book gives these examples in exercise 6 on page 110:

declare
proc {Test X}
   case X of f(a Y c) then {Browse 'case'(1)}
   else {Browse 'case'(2)} end
end

declare X Y {Test f(X b Y)}   % 1
declare X Y {Test f(a Y d)}   % 2
declare X Y {Test f(X Y d)}   % 3

The first example blocks, because it has to know whether X is a or not, and
whether Y is c or not.
The second example displays 'case'(2), because d is not c.
The third example blocks, but this is not what I expected, because d is not
c. Anyway, it still seems logical. First I thought that the rule was

1) If there is no way to bind the unbound variables such that we have to
execute the then, execute the else
2) If there is no way to bind the unbound variables such that we have to
execute the else, execute the then
3) Otherwise wait for more information.

Example 1: case (3) because we can bind X = a and Y = c (thus executing the
then), but we can also bind X = q and Y = c (thus executing the else).
Example 2: case (1) because now matter how we bind Y, d will never match
with c.
Example 3: case (1) for the same reason. But this is not correct: mozart
waits until I bind X before it executes the else.

So now I thought the rule was to wait until all variables match or don't
match their patterns (so wait until X is determined). To make sure that I
got it right I tried some more examples, until I got to this one:

declare X Y {Test f(d X Y)}   % 4

Note that this is the identical to example 3, but with the d moved to the
front. When I executed this example, mozart displayed 'case'(2).

So:

declare X Y {Test f(X Y d)}   % blocks
declare X Y {Test f(d X Y)}   % displays 'case'(2)

Now I'm totally confused. Three questions:

- What is the rule for case?
- Why does it behave like this, and not like I expected?

Thanks for your time,

Jules
_________________________________________________________________________________
mozart-users mailing list                               
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users

Reply via email to