Apparently, the line that I had quoted from the online version of _The Scheme Programming Language, 2nd Edition_ became garbled in the cut-and-paste process,so I am resending this message with that line manually typed:
----- message begins immediately after this line ----- Thank you very much for your responses. The list notation is much clearer now. Russ's parallel between the Scheme '.' (dot) notation and Oz's '|' (bar) notation was especially enlightening, although I do wish to make one minor clarification: You wrote the following: > In scheme (cons 'a '(b c)) yields (a b c), which is a . (b c). According to Chapter 2: "Getting Started" of the online version of _The Scheme Programming Language_ ( see http://www.scheme.com/tspl2d/start.html#g1560 ), however, the following is true (see Section 2.2: Simple Expressions, just before Exercise 2.2.1): > '(a . (b . (c . ()))) => (a b c) This would seem to indicate that, in fact, in Scheme, (cons 'a '(b c)) yields (a b c), which is '(a . (b c)). Cheers, Ben --- Russ Abbott <[EMAIL PROTECTED]> wrote: > 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 > ----- message ends immediately before this line ----- Cheers, Ben _________________________________________________________________________________ mozart-users mailing list [email protected] http://www.mozart-oz.org/mailman/listinfo/mozart-users
