;;; Defined Functions Test ;;; ;;; File: test-defs.in ;;; Author: course ;;; Version: 1 ; Turn off gc ; (set-gc-limit 10000000) (list 1 2 3 4 5) ; Should be (1 2 3 4 5) ; Should print 3 blank lines. (progn (terpri) (terpri) (terpri)) (cddr '(1 2 3 4 5)) ; Should be (3 4 5) (cadr '(1 2 3 4 5)) ; Should be 2 (cdddr '(1 2 3 4 5)) ; Should be (4 5) (caddr '(1 2 3 4 5)) ; Should be 3 (cddddr '(1 2 3 4 5)) ; Should be (5) (cadddr '(1 2 3 4 5)) ; Should be 4 (null nil) ; Should be T (null t) ; Should be NIL (null '(1 . 2)) ; Should be NIL (not nil) ; Should be T (not t) ; Should be NIL (not '(1 . 2)) ; Should be NIL (atom 2) ; Should be T (atom 'x) ; Should be T (atom #'+) ; Should be T (atom '(1 . 2)) ; Should be NIL (atom #'list) ; Should be NIL ; Should be (1 4 9 16 25) (mapcar #'(lambda (n) (* n n)) '(1 2 3 4 5)) (mapcar #'car '((x 1) (y 2))) ; Should be (x y) (mapcar #'cadr '((x 1) (y 2))) ; Should be (1 2) (or) ; Should be NIL (or 5) ; Should be 5 (or nil nil 5) ; Should be 5 (or nil nil nil) ; Should be nil (or (not (boundp 'xx)) xx) ; Should be T (and) ; Should be T (and 1 2 3) ; Should be 3 (and 1 nil 3) ; Should be NIL (and (boundp 'xx) xx) ; Should be NIL (if t 1) ; Should be 1 (if nil 1) ; Should be nil (if t 1 2) ; Should be 1 (if nil 1 2) ; Should be 2 (if (boundp 'xx) xx 55) ; Should be 55 (equal 1 1) ; Should be T (equal 'x 'x) ; Should be T (equal '(x y) '(x y)) ; Should be T (equal ; Should be T '(x y (1 . 2) (a (b (c)))) '(x y (1 . 2) (a (b (c))))) (equal 1 2) ; Should be NIL (equal 'x 'y) ; Should be NIL (equal '(x y) '(x z)) ; Should be NIL (equal ; Should be NIL '(x y (1 . 2) (a (b (c)))) '(x y (1 . 2) (a (b (d))))) (listp nil) ; Should be T (listp '(x . y)) ; Should be T (listp 'x) ; Should be NIL (listp 6) ; Should be NIL (numberp nil) ; Should be NIL (numberp '(x . y)) ; Should be NIL (numberp 'x) ; Should be NIL (numberp 6) ; Should be T (zerop 8) ; Should be NIL (zerop -8) ; Should be NIL (zerop 0) ; Should be T (length nil) ; Should be 0 (length '(1)) ; Should be 1 (length '(1 2)) ; Should be 2 (length '(1 . 2)) ; Should be 1 (length '(1 2 3)) ; Should be 3 (length '(1 (2 2) . 3)) ; Should be 2 (append nil '(1 2 3 4 5)) ; Should be (1 2 3 4 5) (append '(1 2) '(3 4 5)) ; Should be (1 2 3 4 5) (append '(1 2 3 4 5) nil) ; Should be (1 2 3 4 5) (append '(1) '(2) '(3 4 5)) ; Should be (1 2 3 4 5) (append '(1 2) '(3) '(4) '(5)) ; Should be (1 2 3 4 5) (append '(1 2) nil '(3 4) '(5)) ; Should be (1 2 3 4 5) (append '(1 2 3) '(4 5) 'x) ; Should be (1 2 3 4 5 . x) (last '(1 2 3 4 5)) ; Should be (5) (last '(1 2 3 4 . 5)) ; Should be (4 . 5) (last 1) ; Should be error (last nil) ; Should be NIL (member 'x '(s t x y z)) ; Should be (X Y Z) (member 'x '(s t y z)) ; Should be NIL ; Should be NIL (member (cons 1 2) '(s t (1 . 2) y z)) ; Should be ((1 . 2) Y Z) (member (cons 1 2) '(s t (1 . 2) y z) :test #'equal) ; Should be (X 3) (assoc 'x '((s 1) (t 2) (x 3) (y 4) (z 5))) ; Should be NIL (assoc 'x '((s 1) (t 2) (y 4) (z 5))) ; Should be NIL (assoc (cons 1 2) '((x 1) ((1 . 2) 2) (z 3))) ; Should be ((1 . 2) 2) (assoc (cons 1 2) '((x 1) ((1 . 2) 2) (z 3)) :test #'equal) (abs 9) ; Should be 9 (abs -9) ; Should be 9 (abs 0) ; Should be 0 (> 2 1) ; Should T (> 3 2 1) ; Should T (> 4 3 2 1) ; Should T (> 2 2) ; Should NIL (> 3 1 1) ; Should NIL (> 4 3 3 1) ; Should NIL (>= 2 1) ; Should T (>= 3 2 1) ; Should T (>= 4 3 2 1) ; Should T (>= 2 2) ; Should T (>= 3 1 1) ; Should T (>= 4 3 3 1) ; Should T (>= 2 3) ; Should NIL (>= 3 1 2) ; Should NIL (>= 4 3 4 1) ; Should NIL (<= 1 2) ; Should T (<= 1 2 3) ; Should T (<= 1 2 3 4) ; Should T (<= 2 2) ; Should T (<= 1 1 3) ; Should T (<= 1 3 3 4) ; Should T (<= 3 2) ; Should NIL (<= 2 1 3) ; Should NIL (<= 1 4 3 4) ; Should NIL (/= 2 1) ; Should T (/= 3 2 4) ; Should T (/= 4 3 5 1) ; Should T (/= 2 2) ; Should NIL (/= 1 1 1) ; Should NIL (/= 3 4 5 3) ; Should NIL (max 1 2) ; Should be 2 (min 1 2) ; Should be 1 (max 1 2 3 4) ; Should be 4 (min 1 2 3 4) ; Should be 1 (max 1 4 2 3) ; Should be 4 (min 1 4 2 3) ; Should be 1 (max 3 4 1 2) ; Should be 4 (min 3 4 1 2) ; Should be 1 z ; Should be unbound error (setf z 8) ; Should be 8 z ; Should be 8 (macroexpand-1 '(setf z 8)) ; Should be (SETQ Z 8) (setf (symbol-value 'z) 5) ; Should be 5 z ; Should be 5 ; Should be (SET (QUOTE Z) 5) (macroexpand-1 '(setf (symbol-value 'z) 5)) (symbol-function 'z) ; Should be unbound error ; Should be # (setf (symbol-function 'z) #'+) ; Should be # (symbol-function 'z) (z 1 2 3 4 5) ; Should be 15 ; Should be (SET-SYMBOL-FUNCTION (QUOTE Z) ; (FUNCTION +)) (macroexpand-1 '(setf (symbol-function 'z) #'+)) (symbol-plist 'z) ; Should be NIL ; Should be (X 1) (setf (symbol-plist 'z) '(x 1)) ; Should be (X 1) (symbol-plist 'z) ; Should be (SET-SYMBOL-PLIST (QUOTE Z) ; (QUOTE (X 1))) (macroexpand-1 '(setf (symbol-plist 'z) '(x 1))) (setq x (cons 10 20)) (setf (car x) 11) ; Should be 11 x ; Should be (11 . 20) ; Should be (CAR (RPLACA X 11)) (macroexpand-1 '(setf (car x) 11)) (setf (cdr x) 22) ; Should be 22 x ; Should be (11 . 22) ; Should be (CDR (RPLACD X 22)) (macroexpand-1 '(setf (cdr x) 22)) (let ((x 1) (y 90)) (+ x y)) ; Should be 91 (setq x '(1 (2 3) 4)) (setq y (copy-list x)) ; Should be (1 (2 3) 4) (eql x y) ; Should be NIL (eql (cddr x) (cddr y)) ; Should be NIL (eql (cadr x) (cadr y)) ; Should be T (setq y (copy-tree x)) ; Should be (1 (2 3) 4) (eql x y) ; Should be NIL (eql (cddr x) (cddr y)) ; Should be NIL (eql (cadr x) (cadr y)) ; Should be NIL ; Should be (FUNCALL (FUNCTION (LAMBDA (X Y) (+ X Y))) ; 1 90) (macroexpand-1 '(let ((x 1) (y 90)) (+ x y))) (defun counter () (let ((value 0)) #'(lambda () (setf value (+ 1 value)) value))) (setq x (counter)) (funcall x) x (funcall x) x (funcall x) x ; Should be ; (LET ((DO--F ; (FUNCTION ; (LAMBDA (DO----F V1 V2) ; (COND (E V) ; (T (FUNCALL DO----F ; DO----F ; N1 N2))))))) ; (FUNCALL DO--F DO--F I1 I2)) ; (macroexpand-1 '(do ((v1 i1 n1) (v2 i2 n2)) (e v))) (do ((m 3 (+ m 1)) (result 0 (+ result m))) ((> m 6) result)) ; Should be 18 (reverse nil) ; Should be NIL (reverse '(1)) ; Should be (1) (reverse '(1 2 3 4 5)) ; Should be (5 4 3 2 1) ; Should be (X 2 (4 3 (5 X) 8) X) (subst 'x 1 '(1 2 (4 3 (5 1) 8) 1)) ; Should be (1 2 (4 3 (5 1) 8) 1) (subst 'x '(5 1) '(1 2 (4 3 (5 1) 8) 1)) ; Should be (1 2 (4 3 X 8) 1) (subst 'x '(5 1) '(1 2 (4 3 (5 1) 8) 1) :test #'equal) (remove 3 '(1 2 3 4 5)) ; Should be (1 2 4 5) (remove 9 '(1 2 3 4 5)) ; Should be (1 2 3 4 5) (remove 1 '(0 1 0 1 0 1)) ; Should be (0 0 0) ; Should be (8 (1 . 2) 9) (remove '(1 . 2) '(8 (1 . 2) 9)) ; Should be (8 9) (remove '(1 . 2) '(8 (1 . 2) 9) :test #'equal) (nth -1 '(1 2)) ; Should be error (nth 0 '(1 2)) ; Should be 1 (nth 1 '(1 2)) ; Should be 2 (nth 2 '(1 2)) ; Should be NIL (nth 3 '(1 2)) ; Should be NIL (sort '(1 3 5 2 4 6) #'<) ; Should be (1 2 3 4 5 6) (sort '(1 3 5 2 4 6) #'>) ; Should be (6 5 4 3 2 1) (defun and3 (x y z) (and x y z)) (symbol-function 'and3) (compile 'and3) (symbol-function 'and3) (defun foobar (x y lst) (mapcar #'(lambda (x) (and x y z)) lst)) (symbol-function 'foobar) (compile 'foobar) (symbol-function 'foobar) 'DONE