Hi,

I have brought the book  Concepts, Techniques, and Models of Computer
Programming and working through it.

I am having problem understanding pattern matching using case
statement , for example on page 67 of chapter 2 :

It is says that semantic statement of case statement is :
 (case <x> of <lit>(<feat>1:<x>1 ... <feat>n:<x>n) then <s>1 else <s>2 end , E)

And the actions are :
1. If the label of E(<x>) is <lit> and its arity is [<feat>1 ...
<feat>n] , then push .....
2. ....

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?

Any help will be appreciated.

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

Reply via email to