~ubuntu-branches/ubuntu/vivid/gcl/vivid

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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Tue Nov 12 06:30:14 2002
;;;; Contains: Tests of LOOP local variable initialization

(in-package :cl-test)

(deftest loop.8.1
  (loop with x = 1 do (return x))
  1)

(deftest loop.8.2
  (loop with x = 1
        with y = (1+ x) do (return (list x y)))
  (1 2))

(deftest loop.8.3
  (let ((y 2))
    (loop with x = y
	  with y = (1+ x) do (return (list x y))))
  (2 3))

(deftest loop.8.4
  (let (a b)
    (loop with a = 1
	  and b = (list a)
	  and c = (list b)
	  return (list a b c)))
  (1 (nil) (nil)))


;;; type specs

(deftest loop.8.5
  (loop with a t = 1 return a)
  1)

(deftest loop.8.6
  (loop with a fixnum = 2 return a)
  2)

(deftest loop.8.7
  (loop with a float = 3.0 return a)
  3.0)

(deftest loop.8.8
  (loop with a of-type string = "abc" return a)
  "abc")

(deftest loop.8.9
  (loop with (a b) = '(1 2) return (list b a))
  (2 1))

(deftest loop.8.10
  (loop with (a b) of-type (fixnum fixnum) = '(3 4) return (+ a b))
  7)

(deftest loop.8.11
  (loop with a of-type fixnum return a)
  0)

(deftest loop.8.12
  (loop with a of-type float return a)
  0.0)

(deftest loop.8.13
  (loop with a of-type t return a)
  nil)

(deftest loop.8.14
  (loop with a t return a)
  nil)

(deftest loop.8.15
  (loop with a t and b t return (list a b))
  (nil nil))

(deftest loop.8.16
  (loop with (a b c) of-type (fixnum float t) return (list a b c))
  (0 0.0 nil))

(deftest loop.8.17
  (loop with nil = nil return nil)
  nil)

;;; The NIL block of a loop encloses the entire loop.

(deftest loop.8.18
  (loop with nil = (return t) return nil)
  t)

(deftest loop.8.19
  (loop with (nil a) = '(1 2) return a)
  2)

(deftest loop.8.20
  (loop with (a nil) = '(1 2) return a)
  1)

(deftest loop.8.21
  (loop with b = 3
	and (a nil) = '(1 2) return (list a b))
  (1 3))

(deftest loop.8.22
  (loop with b = 3
	and (nil a) = '(1 2) return (list a b))
  (2 3))

;;; The NIL block of a loop encloses the entire loop.

(deftest loop.8.23
  (loop
   with a = 1
   and  b = (return 2)
   return 3)
  2)

;;; Error cases

;;; The spec says (in section 6.1.1.7) that:
;;; "An error of type program-error is signaled (at macro expansion time)
;;;  if the same variable is bound twice in any variable-binding clause
;;;  of a single loop expression. Such variables include local variables,
;;;  iteration control variables, and variables found by destructuring."
;;;
;;; This is somewhat ambiguous.  Test loop.8.error.1 binds A twice in
;;; the same clause, but loop.8.error.2 binds A in two different clauses.
;;; I am interpreting the spec as ruling out the latter as well.

(deftest loop.8.error.1
  (classify-error
   (loop with a = 1
	 and  a = 2 return a))
  program-error)

(deftest loop.8.error.2
  (classify-error
   (loop with a = 1
	 with a = 2 return a))
  program-error)