90 lines
2.4 KiB
Plaintext
90 lines
2.4 KiB
Plaintext
;; Function To Be Tested: RPLACD
|
|
;;
|
|
;; Source: Guy L Steele's CLTL
|
|
;; Section: 15.3 Alteration of List Structure
|
|
;; Page: 272
|
|
;;
|
|
;; Created By: Kelly Roach
|
|
;;
|
|
;; Creation Date: June 27,1986
|
|
;;
|
|
;; Last Update: June 27,1986
|
|
;; July 3, 1986 Sye/ create the test cases
|
|
;;
|
|
;; Filed As: {ERIS}<LISPCORE>CML>TEST>15-3-RPLACD.TEST
|
|
;;
|
|
;;
|
|
;; Syntax: (RPLACD X Y)
|
|
;;
|
|
;; Function Description:
|
|
;; (RPLACD X Y) changes the CDR of X to Y and returns
|
|
;; (the modified) X. X must be a cons, but Y may be
|
|
;; any Lisp object.
|
|
;; For example:
|
|
;;
|
|
;; (SETQ X '(A B C))
|
|
;; (RPLACD X 'D) => (A . D)
|
|
;; Now X => (A . D)
|
|
;;
|
|
;;
|
|
;; Argument(s): X - a list
|
|
;; Y - anything
|
|
;;
|
|
;; Returns: a list
|
|
;;
|
|
|
|
(do-test "test rplacd - test case copied from page 273 of CLtL"
|
|
(and (SETQ X '(A B C))
|
|
(EQUAL (RPLACD X 'D) '(A . D))
|
|
(EQUAL X '(A . D))
|
|
)
|
|
)
|
|
|
|
(do-test "test rplacd1"
|
|
(and (equal (rplacd '(1) 2) '(1 . 2))
|
|
(equal (rplacd '(1 . 3) 2) '(1 . 2))
|
|
(equal (rplacd '(2 4 . 6) ()) '(2))
|
|
(equal (rplacd '(a (c d (e f))) '(g . h)) '(a g . h) )
|
|
)
|
|
)
|
|
|
|
(do-test "test rplacd - use rplacd to construct circular lists"
|
|
(let (( a (copy-list '(1 2 3 4))) (b (copy-list '(11 22 (33 44) 55 66))))
|
|
(rplacd (nthcdr 1 a) a)
|
|
(rplacd (nthcdr 2 b) b)
|
|
(not (and (list-length a) (list-length b)))
|
|
)
|
|
)
|
|
|
|
(do-test "test rplacd2"
|
|
(and (prog2 (setq a '(To further (the wise use of) (land and water))
|
|
b '(To work (for (the (stablilization))) of world (population))
|
|
c '(To (protect "all" life . from) pollution #\, "radiation" (and toxic) substance)
|
|
d '(Goal 1)
|
|
e '(Goal 2)
|
|
f '(Goad 3))
|
|
(and (equal (rplacd (last f) c) (cons '3 c))
|
|
(equal (rplacd (last b) f) (append '((population)) f))
|
|
(equal (rplacd (last e) b) (cons '2 b))
|
|
(equal (rplacd (last a) e) (cons '(land and water) e))
|
|
(equal (rplacd (cdr d) a) (cons '1 a))
|
|
(equal d '(Goal 1 To further (the wise use of) (land and water)
|
|
Goal 2 To work (for (the (stablilization))) of world (population)
|
|
Goad 3 To (protect "all" life . from) pollution #\, "radiation" (and toxic)
|
|
substance))
|
|
)
|
|
)
|
|
;;
|
|
(progn (setq a '(((1 2) 4 5) (6 7) 8 9))
|
|
(rplacd (last a) 10)
|
|
(rplacd (cdr (second a)) 7.7)
|
|
(rplacd (cddar a) 5.5)
|
|
(rplacd (cdaar a) 2.22)
|
|
(equal a '(((1 2 . 2.22) 4 5 . 5.5) (6 7 . 7.7) 8 9 . 10))
|
|
)
|
|
)
|
|
)
|
|
|
|
|
|
STOP
|