Does Scheme/Racket have an enumeration operation?

2019-05-03 09:20发布

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

2条回答
劫难
2楼-- · 2019-05-03 09:40
  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.

查看更多
孤傲高冷的网名
3楼-- · 2019-05-03 09:44
  1. (for/list ([i (in-range 1 6)]) i)

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

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

查看更多
登录 后发表回答