Greetings, Fellow Witches and Wizards,

Whilst perusing the lore of the Tutorial of Oz, I
became somewhat puzzled by the pattern-matching of
lists.

Specifically, when pattern-matching a list of Xs into,
say, (X|Xr), how does Oz know that X denotes the car,
and Xr denotes the cdr of the list (to borrow Scheme
terminology)?  Consider the following procedure in
Figure 5.4: "Merging of two sorted lists," in Section
5.6.2: Basic Control Structures: Pattern Matching:
Semantics ( see
http://www.mozart-oz.org/documentation/tutorial/node5.html#label34
).

proc {SMerge Xs Ys Zs}
   case Xs#Ys
   of nil#Ys then Zs=Ys
   [] Xs#nil then Zs=Xs
   [] (X|Xr) # (Y|Yr) then 
      if X=<Y then Zr in 
         Zs = X|Zr
         {SMerge Xr Ys Zr}
      else Zr in 
         Zs = Y|Zr
         {SMerge Xs Yr Zr}
      end 
   end 
end

Here, the description says that the only assumption is
that Xs and Ys are two sorted input lists, while Zs is
the sorted output list.  Apparently, Xs#Ys is
pattern-matched against (X|Xr) # (Y|Yr) in Pattern_3
of the case-statement, where X is the car and Xr is
the cdr of the Xs.  Similarly, apparently, Y is the
car and Yr is the cdr of the Ys.

However, how does Oz know that X and Y are cars, and
Xr and Yr are cdrs?  Is there a trick to the variable
naming?  If I wrote, say, (Xr|X) # {Yr|Y) instead of
(X|Xr) # (Y|Yr), would that change anything?  How
about if I wrote (Xcar|Xcdr) # (Ycar|Ycdr)?

May the deities that be shed light on this confused
apprentice.

Your fellow wizard-in-training,

Benjamin L. Russell

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

Reply via email to