-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathappend.lsp
95 lines (75 loc) · 2.07 KB
/
append.lsp
1
2
3
4
5
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
;-*- Mode: Lisp -*-
;;;; Author: Paul Dietz
;;;; Created: Sat Apr 19 22:36:46 2003
;;;; Contains: Tests of APPEND
(in-package :cl-test)
(compile-and-load "cons-aux.lsp")
(deftest append.1
(append)
nil)
(deftest append.2
(append 'x)
x)
(deftest append.3
(let ((x (list 'a 'b 'c 'd))
(y (list 'e 'f 'g)))
(let ((xcopy (make-scaffold-copy x))
(ycopy (make-scaffold-copy y)))
(let ((result (append x y)))
(and
(check-scaffold-copy x xcopy)
(check-scaffold-copy y ycopy)
result))))
(a b c d e f g))
(deftest append.4
(append (list 'a) (list 'b) (list 'c)
(list 'd) (list 'e) (list 'f)
(list 'g) 'h)
(a b c d e f g . h))
(deftest append.5
(append nil nil nil nil nil nil nil nil 'a)
a)
(deftest append.6
(append-6-body)
0)
;;; Test suggested by Peter Graves
(deftest append.7
(let ((x (list 'a 'b 'c 'd)))
(eq (append x nil) x))
nil)
;;; Compiler macro expansion in correct env
(deftest append.8
(macrolet ((%m (z) z))
(append (expand-in-current-env (%m '(a b c)))))
(a b c))
(deftest append.9
(macrolet ((%m (z) z))
(append (expand-in-current-env (%m (list 1 2 3))) (list 4 5 6)))
(1 2 3 4 5 6))
(deftest append.10
(macrolet ((%m (z) z))
(append (list 1 2 3) (expand-in-current-env (%m (list 4 5 6)))))
(1 2 3 4 5 6))
;;; Order of evaluation tests
(deftest append.order.1
(let ((i 0) x y z)
(values
(append (progn (setf x (incf i)) (copy-list '(a b c)))
(progn (setf y (incf i)) (copy-list '(d e f)))
(progn (setf z (incf i)) (copy-list '(g h i))))
i x y z))
(a b c d e f g h i) 3 1 2 3)
(deftest append.order.2
(let ((i 0)) (values (append (incf i)) i))
1 1)
(def-fold-test append.fold.1 (append '(a b c) nil))
(def-fold-test append.fold.2 (append nil '(x) nil))
;;; Error tests
(deftest append.error.1
(signals-error (append '(a . b) '(z))
type-error)
t)
(deftest append.error.2
(signals-error (append '(x y z) '(a . b) '(z))
type-error)
t)