~ubuntu-branches/ubuntu/quantal/gclcvs/quantal

« back to all changes in this revision

Viewing changes to ansi-tests/loop8.lsp

  • Committer: Bazaar Package Importer
  • Author(s): Camm Maguire
  • Date: 2004-06-24 15:13:46 UTC
  • Revision ID: james.westby@ubuntu.com-20040624151346-xh0xaaktyyp7aorc
Tags: 2.7.0-26
C_GC_OFFSET is 2 on m68k-linux

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
;-*- Mode:     Lisp -*-
 
2
;;;; Author:   Paul Dietz
 
3
;;;; Created:  Tue Nov 12 06:30:14 2002
 
4
;;;; Contains: Tests of LOOP local variable initialization
 
5
 
 
6
(in-package :cl-test)
 
7
 
 
8
(deftest loop.8.1
 
9
  (loop with x = 1 do (return x))
 
10
  1)
 
11
 
 
12
(deftest loop.8.2
 
13
  (loop with x = 1
 
14
        with y = (1+ x) do (return (list x y)))
 
15
  (1 2))
 
16
 
 
17
(deftest loop.8.3
 
18
  (let ((y 2))
 
19
    (loop with x = y
 
20
          with y = (1+ x) do (return (list x y))))
 
21
  (2 3))
 
22
 
 
23
(deftest loop.8.4
 
24
  (let (a b)
 
25
    (loop with a = 1
 
26
          and b = (list a)
 
27
          and c = (list b)
 
28
          return (list a b c)))
 
29
  (1 (nil) (nil)))
 
30
 
 
31
 
 
32
;;; type specs
 
33
 
 
34
(deftest loop.8.5
 
35
  (loop with a t = 1 return a)
 
36
  1)
 
37
 
 
38
(deftest loop.8.6
 
39
  (loop with a fixnum = 2 return a)
 
40
  2)
 
41
 
 
42
(deftest loop.8.7
 
43
  (loop with a float = 3.0 return a)
 
44
  3.0)
 
45
 
 
46
(deftest loop.8.8
 
47
  (loop with a of-type string = "abc" return a)
 
48
  "abc")
 
49
 
 
50
(deftest loop.8.9
 
51
  (loop with (a b) = '(1 2) return (list b a))
 
52
  (2 1))
 
53
 
 
54
(deftest loop.8.10
 
55
  (loop with (a b) of-type (fixnum fixnum) = '(3 4) return (+ a b))
 
56
  7)
 
57
 
 
58
(deftest loop.8.11
 
59
  (loop with a of-type fixnum return a)
 
60
  0)
 
61
 
 
62
(deftest loop.8.12
 
63
  (loop with a of-type float return a)
 
64
  0.0)
 
65
 
 
66
(deftest loop.8.13
 
67
  (loop with a of-type t return a)
 
68
  nil)
 
69
 
 
70
(deftest loop.8.14
 
71
  (loop with a t return a)
 
72
  nil)
 
73
 
 
74
(deftest loop.8.15
 
75
  (loop with a t and b t return (list a b))
 
76
  (nil nil))
 
77
 
 
78
(deftest loop.8.16
 
79
  (loop with (a b c) of-type (fixnum float t) return (list a b c))
 
80
  (0 0.0 nil))
 
81
 
 
82
(deftest loop.8.17
 
83
  (loop with nil = nil return nil)
 
84
  nil)
 
85
 
 
86
;;; The NIL block of a loop encloses the entire loop.
 
87
 
 
88
(deftest loop.8.18
 
89
  (loop with nil = (return t) return nil)
 
90
  t)
 
91
 
 
92
(deftest loop.8.19
 
93
  (loop with (nil a) = '(1 2) return a)
 
94
  2)
 
95
 
 
96
(deftest loop.8.20
 
97
  (loop with (a nil) = '(1 2) return a)
 
98
  1)
 
99
 
 
100
(deftest loop.8.21
 
101
  (loop with b = 3
 
102
        and (a nil) = '(1 2) return (list a b))
 
103
  (1 3))
 
104
 
 
105
(deftest loop.8.22
 
106
  (loop with b = 3
 
107
        and (nil a) = '(1 2) return (list a b))
 
108
  (2 3))
 
109
 
 
110
;;; The NIL block of a loop encloses the entire loop.
 
111
 
 
112
(deftest loop.8.23
 
113
  (loop
 
114
   with a = 1
 
115
   and  b = (return 2)
 
116
   return 3)
 
117
  2)
 
118
 
 
119
;;; Error cases
 
120
 
 
121
;;; The spec says (in section 6.1.1.7) that:
 
122
;;; "An error of type program-error is signaled (at macro expansion time)
 
123
;;;  if the same variable is bound twice in any variable-binding clause
 
124
;;;  of a single loop expression. Such variables include local variables,
 
125
;;;  iteration control variables, and variables found by destructuring."
 
126
;;;
 
127
;;; This is somewhat ambiguous.  Test loop.8.error.1 binds A twice in
 
128
;;; the same clause, but loop.8.error.2 binds A in two different clauses.
 
129
;;; I am interpreting the spec as ruling out the latter as well.
 
130
 
 
131
(deftest loop.8.error.1
 
132
  (signals-error
 
133
   (loop with a = 1
 
134
         and  a = 2 return a)
 
135
   program-error)
 
136
  t)
 
137
 
 
138
(deftest loop.8.error.2
 
139
  (signals-error
 
140
   (loop with a = 1
 
141
         with a = 2 return a)
 
142
   program-error)
 
143
  t)