Does Scheme/Racket have an enumeration notation equivalent to the [a..b] notation in Haskell?
In Haskell, [1..5] evaluates to a list [1,2,3,4,5].
Asked
Active
Viewed 2,187 times
6

amindfv
- 8,438
- 5
- 36
- 58
-
2The selling point of Lisp is minimal syntax. So instead of special notation, like `[a..b]`, there are functions that accomplish the same thing. – Dan Burton Aug 22 '11 at 16:06
2 Answers
11
(for/list ([i (in-range 1 6)]) i)
(sequence->list (in-range 1 6))
(require srfi/1) (iota 5 1)

Eli Barzilay
- 29,301
- 3
- 67
- 110
4
(for/list ([i 5]) (+ 1 i))
(build-list 5 add1)
Also, (in-range 1 6)
(which is a sequence) by itself is useful in many contexts.

Sam Tobin-Hochstadt
- 4,983
- 1
- 21
- 43
-
To get behavior most like Haskell, use Lazy Racket's `build-list` which is (surprise) lazy. – Dan Burton Aug 22 '11 at 16:09