90 likes | 187 Views
You can access the members of a list with the functions car (or first ) and cdr (or rest ): ( setf list '(a b c)) ( car list) ⇒ a ( first list) ⇒ a ( cdr list) ⇒ (b c) ( rest list) ⇒ (b c). f irst, second, third, …, tenth.
E N D
You can access the members of a list with the functions car (or first) and cdr (or rest):(setf list '(a b c)) (car list) ⇒ a (first list) ⇒ a (cdr list) ⇒ (b c) (rest list) ⇒ (b c)
first, second, third, …, tenth Common Lisp also defines the functions second, third and fourth (on up to tenth). Note that second is not the same as cdr or rest. cdr and rest both return the remaining list after the first element, while second returns the second item in the list:(rest list) ⇒ (b c) (second list) ⇒ b (third list) ⇒ c (fourth list) ⇒ nil
http://www.cs.sfu.ca/CourseCentral/310/pwfong/Lisp/1/tutorial1.html Member function
‘(a b) does not EQ another copy of ‘(a b)(they are not the same symbol)
Exercise If we want to account for list equivalence, we could have used the LISP built-in function equal instead of eq. What would be the behavior of list-member if we replace eq by =? By eql? By equal?
Exercise Get copylistworking and evaluate the following expressions: • (copylist '(A B C)) • (equal '(A B C) (copylist '(A B C))) [testing whether they contain the same data in the same arrangement] • (eq '(A B C) (copylist '(A B C))) [testing whether they are stored in the same memory location]