View Single Post
Old Nov 29, 2004, 05:45 PM   #12 (permalink)
YAYitsAndrew
Your Inner Child
 
YAYitsAndrew's Avatar
 
Join Date: Oct 2004
Location: NJ
Posts: 2,349
YAYitsAndrew will become famous soon enough
System Specs

as per your IM:

nil is an empty list. ()
cons joins an element with a list. (cons element list). This may be why mine didn't work before I was doing (cons list element). Anyway, (cons 'a nil) will be the element 'a added to the nil list. You get (a). (cons 'a (cons 'b nil)) is tricky. Work inside out just like in algebra. First (cons 'b nil) is (b). now we have (cons 'a (b)) which is (a b). If we wanted to get mor confused we could do (cons (cons 'a nil) (cons 'b nil)). That breaks to (cons (a) (b)) and should give the list ((a) b). I think you need (cons (cons 'a nil) (cons (cons 'b nil) nil)) to get ((a) (b)). Play around with it.

list is a little different, you specify all the elements of the list in the declaration. (list element1 element2 element3 ...). So (list a b c) is (a b c) and (list (list a) (list b)) is (list (a) (b)) is ((a) (b)).

When working in Lisp you need to be able to get your bearings straight when surrounded by parenthesis. Think of the algebraic equation (4 + (2 * (4 + 7 + (2 - 6) * (2 + 4)))). You'd solve that the same way you go about working in lisp. From the inside out.
YAYitsAndrew is online now   Reply With Quote