首页 > 其他 > 详细

repeatedly function in Clojure

时间:2014-03-18 11:49:46      阅读:475      评论:0      收藏:0      [点我收藏+]

user=> (doc repeatedly)

clojure.core/repeatedly ([f] [n f]) Takes a function of no args, presumably with side effects, and returns an infinite (or length n if supplied) lazy sequence of calls to it nil

user=> (repeatedly 5 (fn [] 90)) (90 90 90 90 90)

user=> (type (repeatedly 5 (fn [] 90))) clojure.lang.LazySeq

user=> (repeatedly 5 (fn [] (do (println "hi") 75))) (hi hi 75 hi 75 hi 75 hi 75 75) user=> (repeatedly (fn [] 87)) OutOfMemoryError Java heap space java.util.Arrays.copyOf (:-1)

So you can see repeatedly can take a function with/without side effect. But how to return a function with infinite length?

repeatedly function in Clojure,布布扣,bubuko.com

repeatedly function in Clojure

原文:http://www.cnblogs.com/darkmatter/p/3606784.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!