blob: 908809207980150559a78d66b4a5da5598ecadd7 (
plain)
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
|
# Lisp For Schemers
## iota
### In Scheme
```
scheme@(guile-user)> (iota 12)
$1 = (0 1 2 3 4 5 6 7 8 9 10 11)
```
### In Common Lisp
```
CL-USER: (loop for i below 12 collect i)
(0 1 2 3 4 5 6 7 8 9 10 11)
CL-USER: (macroexpand '(loop for i below 12 collect i))
(BLOCK NIL
(LET ((I 0))
(DECLARE (IGNORABLE I)
(TYPE (AND NUMBER REAL) I))
(SB-LOOP::WITH-LOOP-LIST-COLLECTION-HEAD (#:LOOP-LIST-HEAD-493
#:LOOP-LIST-TAIL-494)
(TAGBODY
SB-LOOP::NEXT-LOOP
(WHEN (>= I '12) (GO SB-LOOP::END-LOOP))
(SB-LOOP::LOOP-COLLECT-RPLACD
(#:LOOP-LIST-HEAD-493 #:LOOP-LIST-TAIL-494) (LIST I))
(SB-LOOP::LOOP-DESETQ I (1+ I))
(GO SB-LOOP::NEXT-LOOP)
SB-LOOP::END-LOOP
(RETURN-FROM NIL
(SB-LOOP::LOOP-COLLECT-ANSWER #:LOOP-LIST-HEAD-493))))))
T
```
#### Using iota from the alexandria library with GNU/Guix:
```
guix shell sbcl sbcl-alexandria rlwrap -- rlwrap sbcl
```
```
CL-USER: (asdf:make "alexandria")
CL-USER: (in-package :alexandria)
CL-USER: (alexandria:iota 12)
(0 1 2 3 4 5 6 7 8 9 10 11)
```
=> https://common-lisp.net/project/alexandria/ alexandria
|