77 lines
2.2 KiB
Plaintext
77 lines
2.2 KiB
Plaintext
;; Function To Be Tested: FIFTH
|
|
;;
|
|
;; Source: Guy L Steele's CLTL
|
|
;; Section: 15.2 Lists
|
|
;; Page: 266
|
|
;;
|
|
;; Created By: Kelly Roach
|
|
;;
|
|
;; Creation Date: June 27,1986
|
|
;;
|
|
;; Last Update: June 27,1986
|
|
;; July 3, 1986 Sye/ create test cases
|
|
;;
|
|
;; Filed As: {ERIS}<LISPCORE>CML>TEST>15-2-FIFTH.TEST
|
|
;;
|
|
;;
|
|
;; Syntax: (FIFTH LIST)
|
|
;;
|
|
;; Function Description:
|
|
;; These functions are sometimes convenient for accessing particular
|
|
;; elements of a list. FIRST is the same as function CAR,
|
|
;; SECOND is the same as CADR, THIRD is the
|
|
;; same as CADDR, and so on.
|
|
;; Note that the ordinal numbering used here is one-origin,
|
|
;; as opposed to the zero-origin numbering used by function NTH:
|
|
;;
|
|
;; (FIFTH X) = (NTH 4 X)
|
|
;;
|
|
;;
|
|
;; macro SETF may be used with each of these functions to store
|
|
;; into the indicated position of a list.
|
|
;;
|
|
;; Argument(s): LIST - a list
|
|
;;
|
|
;; Returns: anything
|
|
;;
|
|
|
|
|
|
|
|
(do-test "test fifth0"
|
|
(and (eq (fifth ()) ())
|
|
(eq (fifth '(1)) ())
|
|
(eq (fifth '(1 2)) ())
|
|
(eq (fifth '(a b c)) ())
|
|
(eq (fifth '(a b c d)) ())
|
|
(eql (fifth '(1 2 3 4 5)) 5)
|
|
(equal (fifth '(nil nil nil ( t . t) (nil . t) (nil . nil))) '(nil . t))
|
|
(eql (fifth (list #\a #\c #\s #\g #\u #\r)) #\u)
|
|
(equal (fifth '("infor" "system" (("division" "xerox")) "system" ("groups" (789 333)) "exit"))
|
|
'("groups" (789 333)))
|
|
))
|
|
|
|
(do-test "test fifth1"
|
|
(prog2
|
|
(defun fun (list elm)
|
|
(typecase elm (number (= (fifth list) elm))
|
|
((or cons string) (equal (fifth list) elm))
|
|
(t (eq (fifth list) elm))
|
|
)
|
|
)
|
|
(and (fun '('foo1 'foo2 'foo3 'foo4 'foo5 'foo6) ''foo5)
|
|
(fun '((1) ((b)) (c . "c") ((d d)) (((e e) e ) e) "ffff" | * g * |) '(((e e) e ) e) )
|
|
(fun (progn (setq a '(2 4 6 8 10 12 14))
|
|
(rplaca (nthcdr 4 a) '("a" "b")) a) '("a" "b"))
|
|
(fun (fifth (append '(#\q #\a #\k #\!) '((10 20 30 40 50 60)) '("the" "end")))
|
|
50)
|
|
)
|
|
)
|
|
)
|
|
(do-test "test fifth2"
|
|
(progn (setq a (make-list 10))
|
|
(setf (fifth a) '( red yellow green pink blue brown))
|
|
(setf (fifth (fifth a)) '!dark-blue!)
|
|
(equal a '(nil nil nil nil (red yellow green pink !dark-blue! brown) nil nil nil nil nil))
|
|
)
|
|
)
|
|
STOP |