push.lsp 1.38 KB
Newer Older
1 2 3 4 5
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Sat Apr 19 22:05:34 2003
;;;; Contains: Tests of PUSH

6

7

8

9

10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
;;; See also places.lsp

(deftest push.1
  (let ((x nil))
    (push 'a x))
  (a))

(deftest push.2
  (let ((x 'b))
    (push 'a x)
    (push 'c x))
  (c a . b))

(deftest push.3
  (let ((x (copy-tree '(a))))
    (push x x)
    (and
     (eqt (car x) (cdr x))
     x))
  ((a) a))

31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
;;; Test that explicit calls to macroexpand in subforms
;;; are done in the correct environment

(deftest push.4
  (macrolet
   ((%m (z) z))
   (let ((x nil))
     (values
      (push (expand-in-current-env (%m 1)) x)
      x)))
  (1) (1))

(deftest push.5
  (macrolet
   ((%m (z) z))
   (let ((x nil))
     (values
      (push 1 (expand-in-current-env (%m x)))
      x)))
  (1) (1))

52 53 54 55
(deftest push.order.1
  (let ((x (list nil)) (i 0) a b)
    (values
     (push (progn (setf a (incf i)) 'z)
sds's avatar
sds committed
56
           (car (progn (setf b (incf i)) x)))
57 58 59 60
     x
     i a b))
  (z) ((z)) 2 1 2)

61 62
(deftest push.order.2
  (let ((x (vector nil nil nil nil))
sds's avatar
sds committed
63 64
        (y (vector 'a 'b 'c 'd))
        (i 1))
65 66 67 68 69 70
    (push (aref y (incf i)) (aref x (incf i)))
    (values x y i))
  #(nil nil nil (c))
  #(a b c d)
  3)

71 72 73 74 75 76 77
(deftest push.order.3
  (let ((x '(a b c)))
    (values
     (push (progn (setq x '(d e)) 'z) x)
     x))
  (z d e) (z d e))

78 79
(def-macro-test push.error.1 (push x y))

80
;;; Need to add push vs. various accessors