> Now consider this fragment taken from exercise 5 on page 107-108 :
>
> local Test in
> proc {Test X}
> case X
> of '|'(1:a 2:Z) then {Browse 'case'(1)}
> [] f(a) then {Browse 'case'(2)}
> [] Y|Z andthen Y==Z then {Browse 'case'(3)}
> [] Y|Z then {Browse 'case'(4)}
> [] f(Y) then {Browse 'case'(5)}
> else {Browse 'case'(6)} end
> end
> {Test [b c a]}
> end
>
> Produces the answer 'case(4)' i.e clause [] Y|Z then {Browse 'case'(4)}
>
> But {Label [b c a]} is '|' and {Label '|'(1:a 2:Z)} is also '|'
> And {Arity [b c a]} is [1 2] and {Arity '|'(1:a 2:Z)} is also [1 2]
>
> So why it is not selecting the first clause?
Because it reads: of '|'(1:a 2:Z) then {Browse 'case'(1)} which means
the element should match a pattern whose label is '|' *and* whose
first element is 'a' and whose third element will be anything which
can be united with unbound variable Z.
So, yes [b c a]'s label is '|' but its first element is 'b', not 'a'.
And thus it matches the fourth case which is the Y|Z pattern which
means anything with a '|' label *and* whose first element can be bound
to the unbound variable Y and whose rest can be bound to Z; [b c a]
matches this pattern (and be careful, not the third case because Y is
not == Z).
That's my comment as another Oz newbie who is reading the same book :)
Cheers,
--
Emre Sevinc
Lecturer @ Istanbul Bilgi University Computer Science Department
Coordinator @ IBM Center for Advanced Studies Lab.
http://cs.bilgi.edu.tr/~emres/
http://cs.bilgi.edu.tr
http://cas.bilgi.edu.tr/cms/
_________________________________________________________________________________
mozart-users mailing list
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users