1 / 9

f irst, second, third, …, tenth

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.

Download Presentation

f irst, second, third, …, tenth

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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)

  2. 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

  3. http://www.cs.sfu.ca/CourseCentral/310/pwfong/Lisp/1/tutorial1.html Member function

  4. ‘(a b) does not EQ another copy of ‘(a b)(they are not the same symbol)

  5. 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?

  6. Copying a list

  7. 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]

  8. Make the same tests on copylist2

More Related