1
0
mirror of synced 2026-05-03 14:49:45 +00:00
Files
Interlisp.medley/internal/test/LANGUAGE/AUTO/15-2-LISTSTAR.TEST

92 lines
3.1 KiB
Plaintext

;; Function To Be Tested: LIST*
;;
;; Source: Guy L Steele's CLTL
;; Section: 15.2 Lists
;; Page: 267
;;
;; Created By: Kelly Roach
;;
;; Creation Date: June 27,1986
;;
;; Last Update: June 27,1986
;; July 15, 1986 Sye/ create test cases
;;
;; Filed As: {ERIS}<LISPCORE>CML>TEST>15-2-LIST*.TEST
;;
;;
;; Syntax: (LIST* ARG &REST OTHERS)
;;
;; Function Description:
;; LIST* is like LIST except that the last CONS
;; of the constructed list is ``dotted.'' The last argument to LIST*
;; is used as the CDR of the last cons constructed;
;; this need not be an atom. If it is not an atom,
;; then the effect is to add several new elements to the front of a list.
;; For example:
;;
;; (LIST* 'A 'B 'C 'D) => (A B C . D)
;; This is like
;; (CONS 'A (CONS 'B (CONS 'C 'D)))
;; Also:
;; (LIST* 'A 'B 'C '(D E F)) => (A B C D E F)
;; (LIST* X) = X
;;
;;
;; Argument(s): ARG - anything
;; OTHERS - anything
;;
;; Returns: a dotted list
;;
(do-test "test list*0 - test case copied from page 267 of CLtL"
(and (EQUAL (LIST* 'A 'B 'C 'D) '(A B C . D))
(EQUAL (LIST* 'A 'B 'C '(D E F)) '(A B C D E F))
(EQUAL (LIST* 'X) 'X)
)
)
(do-test "test list*1"
(and (equal (list* 999 999 999 999 999 999 999 999 999 999 999 999 999 999 999 999 999 999 999 999 999 999 999 999 999
999 999 999 999 999 999 999 999 999 999 999 999 999 999 999 999 999 999 999 999 999 999 999 999 999)
(append (make-list 48 :initial-element 999) '(999 . 999)))
(equal (list* "evening" 'sun 'reflected "in Lake" 'Shanti) '("evening" sun reflected "in Lake" . Shanti))
)
)
(do-test "test list*2"
(equal (list* 1.009 'a (cons 3 4) (funcall #'list* 2.009 #\g "string") (every #'evenp '(2 4 6 8)) (not (or 1 100 1000 0))
(apply #'list* 'm 'n 'b '(88)) (list* (+ 2 3) (caddr '(w x y z))) )
'(1.009 a (3 . 4) (2.009 #\g . "string") t nil (m n b . 88) 5 . y)))
(do-test "test list*3"
(progn
(setq aa '(a b c d e f g h))
(equal (list* (last aa) (nth 3 aa) (nthcdr 5 aa) (list* (car aa) (endp aa))
(progn 1 2 3 (setq x 1 y 2 z 3))
(prog2 (defun fun () "fun1") (fun))
(prog1 (setq a 100) (setq a (1+ a)))
(progn (defmacro mac () `(list* ,(* 2 2) ,(list-length ()))) (mac)))
'( (h) d (f g h) (a . nil) 3 "fun1" 100 4 . 0)) ))
(do-test "test list*4 - nested list* functions"
(and
(equal (setq aa (list* (list* (list* (list* (list* (list* (list* (list* (list* (list* 'a 'b 'c 'd 'e 'f 'g 'h 'i 'j 'k)))))))))))
'(a b c d e f g h i j . k) )
(equal (list* aa aa aa aa aa)
'((a b c d e f g h i j . k) (a b c d e f g h i j . k) (a b c d e f g h i j . k) (a b c d e f g h i j . k)
a b c d e f g h i j . k) )
)
)
(do-test "test list*5 - (list* x) is equivalent to x [page 268]"
(and (eq (list* ()) ())
(eq (list* 10) 10)
(equal (list* '(1)) '(1))
(equal (list* (list* (list 2))) '(2))
(prog2 (setq a (list* #'-)) (= (funcall a 4 3 2 1) -2))
(equal (list* (list (list* 1 2 3) '(4) ) '(5 . "a")) '(((1 2 . 3) (4)) 5 . "a"))
)
)
STOP