Does Scheme/Racket have an enumeration operation?

天大地大妈咪最大 提交于 2019-12-07 05:38:53

问题


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


回答1:


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

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

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




回答2:


  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.



来源:https://stackoverflow.com/questions/7144248/does-scheme-racket-have-an-enumeration-operation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!