On 9/17/07, Andreas Franke <[EMAIL PROTECTED]> wrote:
>
> Jules Jacobs wrote:
> > 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 Y d)}   % blocks
> > declare X Y {Test f(d X Y)}   % displays 'case'(2)
>
> Have a look at the corresponding section in the Oz Tutorial:
> http://www.mozart-oz.org/documentation/tutorial/node5.html#control.pattern
> ==============================================
>
>
>       5.6.1 Case Statement
>
>     |case E of |/Pattern_1/| then |/S1/|
>     [] |/Pattern_2/| then |/S2/|
>     [] ...
>     else |/S/| end|
>
> All variables introduced in /Pattern_i/ are implicitly declared,
> and have a scope stretching over the corresponding /Si/.
>
>
>       5.6.2 Semantics
>
> 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.
> [...]
>
> ==============================================
> Features of a record can be thought of as sorted lexicographically, see
> http://www.mozart-oz.org/documentation/tutorial/node3.html#label20
> In your case with R = f(a _ c) = f(1:a 2:_ 3:c) we have
> {Arity R} = [1 2 3]).  Thus left-to-right means that the matching
> against the value for feature 1 happens first, and this may block.
>
> HTH,
> Andreas
>
>
> _________________________________________________________________________________
> mozart-users mailing list
> [email protected]
> http://www.mozart-oz.org/mailman/listinfo/mozart-users
>

Thank you! From a language design point of view, why does case have this
behavior (dept-first, left-to-right)? CTM also gives this example:

declare X Y
if f(X Y d)==f(a Y c) then {Browse 'case'(1)}
else {Browse 'case'(2)} end

This displays 'case'(2).

Why do these constructs behave differently in this case?

Thank you,

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

Reply via email to