File: mapcan.lsp

package info (click to toggle)
gcl27 2.7.1-13
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 30,888 kB
  • sloc: lisp: 211,946; ansic: 52,944; sh: 9,347; makefile: 647; tcl: 53; awk: 52
file content (122 lines) | stat: -rw-r--r-- 2,595 bytes parent folder | download | duplicates (6)
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Sun Apr 20 07:22:46 2003
;;;; Contains: Tests of MAPCAN

(in-package :cl-test)

(compile-and-load "cons-aux.lsp")

(deftest mapcan.1
  (mapcan #'list nil)
  nil)

(deftest mapcan.2
  (mapcan #'list (copy-list '(a b c d e f)))
  (a b c d e f))

(deftest mapcan.3
  (let* ((x (list 'a 'b 'c 'd))
	 (xcopy (make-scaffold-copy x))
	 (result (mapcan #'list x)))
    (and
     (= (length x) (length result))
     (check-scaffold-copy x xcopy)
     (loop
      for e1 on x
      and e2 on result
      count (or (eqt e1 e2) (not (eql (car e1) (car e2)))))))
  0)

(deftest mapcan.4
  (mapcan #'list
	  (copy-list '(1 2 3 4))
	  (copy-list '(a b c d)))
  (1 a 2 b 3 c 4 d))

(deftest mapcan.5
  (mapcan #'(lambda (x y) (make-list y :initial-element x))
	  (copy-list '(a b c d))
	  (copy-list '(1 2 3 4)))
  (a b b c c c d d d d))

(defvar *mapcan.6-var* nil)
(defun mapcan.6-fun (x)
  (push x *mapcan.6-var*)
  (copy-list *mapcan.6-var*))

(deftest mapcan.6
  (progn
    (setf *mapcan.6-var* nil)
    (mapcan 'mapcan.6-fun (copy-list '(a b c d))))
  (a b a c b a d c b a))

(deftest mapcan.order.1
  (let ((i 0) x y z)
    (values
     (mapcan (progn (setf x (incf i))
		    #'list)
	     (progn (setf y (incf i))
		    '(a b c))
	     (progn (setf z (incf i))
		    '(1 2 3)))
     i x y z))
  (a 1 b 2 c 3)
  3 1 2 3)

(deftest mapcan.8
  (mapcan #'(lambda (x y) (make-list y :initial-element x))
	  (copy-list '(a b c d))
	  (copy-list '(1 2 3 4 5 6)))
  (a b b c c c d d d d))

(deftest mapcan.9
  (mapcan #'(lambda (x y) (make-list y :initial-element x))
	  (copy-list '(a b c d e f))
	  (copy-list '(1 2 3 4)))
  (a b b c c c d d d d))

(deftest mapcan.10
  (mapcan #'list
	  (copy-list '(a b c d))
	  (copy-list '(1 2 3 4))
	  nil)
  nil)

(deftest mapcan.11
  (mapcan (constantly 1) (list 'a))
  1)

(deftest mapcan.error.1
  (check-type-error #'(lambda (x) (mapcan #'identity x)) #'listp)
  nil)

(deftest mapcan.error.2
  (signals-error (mapcan) program-error)
  t)

(deftest mapcan.error.3
  (signals-error (mapcan #'append) program-error)
  t)

(deftest mapcan.error.4
  (signals-error (locally (mapcan #'identity 1) t) type-error)
  t)

(deftest mapcan.error.5
  (signals-error (mapcan #'car '(a b c)) type-error)
  t)

(deftest mapcan.error.6
  (signals-error (mapcan #'cons '(a b c)) program-error)
  t)

(deftest mapcan.error.7
  (signals-error (mapcan #'cons '(a b c) '(1 2 3) '(4 5 6))
		 program-error)
  t)

(deftest mapcan.error.8
  (signals-error (mapcan #'identity (list* (list 1) (list 2) 3))
		 type-error)
  t)