1
0
mirror of synced 2026-05-05 07:34:31 +00:00
Files
Interlisp.medley/internal/test/LANGUAGE/AUTO/15-2-LAST.TEST

64 lines
1.8 KiB
Plaintext

;; Function To Be Tested: LAST
;;
;; Source: Guy L Steele's CLTL
;; Section: 15.2 Lists
;; Page: 267
;;
;; Created By: Karin M. Sye, Kelly Roach
;;
;; Creation Date: June 27,1986
;;
;; Last Update: Jan 28, 1987 Jim Blum - made PLIST for A even number of atoms in LAST1 test
;; because SUN complains if same variable is used in a DEFSTRUCT field name if odd
;; number of atoms in property list
;;
;; Filed As: {ERIS}<LISPCORE>CML>TEST>15-2-LAST.TEST
;;
;;
;; Syntax: (LAST LIST)
;;
;; Function Description:
;; LAST returns the last cons (NOT the last element!) of LIST.
;; If LIST is NIL, it returns NIL.
;; For example:
;;
;; (SETQ X '(A B C D))
;; (LAST X) => (D)
;; (RPLACD (LAST X) '(E F))
;; X => '(A B C D E F)
;; (LAST '(A B C . D)) => (C . D)
;;
;;
;; Argument(s): X - a list
;;
;; Returns: a list
;;
(do-test "test last0 - test cases copied from page 267 of CLtL"
(and (setq x '(a b c d))
(equal (last x) '(d))
(rplacd (last x) '(e f))
(equal x `(a b c d e f))
(equal (last '(a b c . d)) '(c . d))))
(do-test "test last1"
(progn (defun fun (x y) (equal (last x) y))
;
(and (fun '(1 2 3 4 5) '(5))
(fun '() ())
(fun '(1 . 2) '(1 . 2))
(fun '(d k s i e u w d (k l j h)) '((k l j h)))
(fun '(a b c d (e f g) h (((i)))) '((((i)))))
(progn (setq a 1) (setf (symbol-plist 'a) '(foo1 foo2 foo3 foo4)) (fun (symbol-plist 'a) '(foo4)))
(progn (setq a (append '(foo) (make-list 10 :initial-element 'rah) '(foon)))
(and (fun a '(foon)) (fun (reverse a) '(foo)))))))
(do-test "test last2"
(progn (setq a (list (function +) (function -) (function *)))
(= (funcall (car (last a)) 1 2 3 40) 240)
(= (apply (car (last (reverse a))) '(1 2 3 40)) 46)))
STOP