Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Scheme/Racket have an enumeration operation?

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].

like image 550
amindfv Avatar asked Aug 22 '11 07:08

amindfv


2 Answers

  1. (for/list ([i (in-range 1 6)]) i)

  2. (sequence->list (in-range 1 6))

  3. (require srfi/1) (iota 5 1)

like image 132
Eli Barzilay Avatar answered Sep 22 '22 21:09

Eli Barzilay


  1. (for/list ([i 5]) (+ 1 i))

  2. (build-list 5 add1)

Also, (in-range 1 6) (which is a sequence) by itself is useful in many contexts.

like image 30
Sam Tobin-Hochstadt Avatar answered Sep 24 '22 21:09

Sam Tobin-Hochstadt