Dear Wizard-in-training. Another way to think about it is that it's just notation.
X | Xr means the list whose car is X and whose crd is Xr.
Writing a | nil is the same thing as writing [a].
Similarly, [a b c] = a | [b c] = a | b | [c] = a | b | c | nil
Think of | as an infix cons--except that it can be used not only to build lists but to
represent their structure as well.
Or just imagine that | is the same as '.' in scheme--if I remember
my scheme right.
In scheme (cons 'a '(b c)) yields (a b c), which is a . (b c).
-- Russ
On 11/25/05, Maximilian Wilson <[EMAIL PROTECTED]> wrote:
On 11/25/05, Benjamin L. Russell <[EMAIL PROTECTED]> wrote:
> 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)?
The unification algorithm requires it. A list is a set of '|' tuples,
right? That is, instead of representing the list [a b c] as cons(a,
cons(b, cons(c, nil))) it is represented as a record with '|' as the
label: '|'(a '|'(b '|'(c nil))). Matching this list against X|Foo,
which itself is '|'(X Foo), requires that X=a and Foo='|'(b '|'(c
nil)). The variable names, as you can see, are not significant. In
your pattern-matching example using #s, matching Xs#Ys against
X|Xr#Y|Yr comes out basically the same way. The outer-level #s match
against each other, and X must have the structure '|'(X Xr) and Y must
have the structure '|'(Y Yr), which effectively means X=car and
Xr=cdr.
Max Wilson
--
Be pretty if you are,
Be witty if you can,
But be cheerful if it kills you.
_________________________________________________________________________________
mozart-users mailing list [email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users
_________________________________________________________________________________ mozart-users mailing list [email protected] http://www.mozart-oz.org/mailman/listinfo/mozart-users
