for宏惰性求值记录
来源:互联网 发布:淘宝异地客服在家兼职 编辑:程序博客网 时间:2024/05/22 06:47
如下代码
(defn create-new-user-folder [username] (let [user-root-path (join-path-parts username) user-root-folder (File. user-root-path)] (if-not (.exists user-root-folder) (do (.mkdirs user-root-folder) (doall (for [tmp-dir (seq one-level-folders)] (let [tar-file (File. (str user-root-path File/separator tmp-dir))] (if-not (.exists tar-file) (.mkdirs tar-file)))))))))
在REPL里测试一切正常,可以通过WEB访问就无法创建文件夹,纠结了好久,最后突然意识到可能是惰性序列的原因,在for外层加个doall,果然解决掉了
for宏的说明文档如下
formacroUsage: (for seq-exprs body-expr)List comprehension. Takes a vector of one or more binding-form/collection-expr pairs, each followed by zero or more modifiers, and yields a lazy sequence of evaluations of expr. Collections are iterated in a nested fashion, rightmost fastest, and nested coll-exprs can refer to bindings created in prior binding-forms. Supported modifiers are: :let [binding-form expr ...], :while test, :when test.(take 100 (for [x (range 100000000) y (range 1000000) :while (< y x)] [x y]))Added in Clojure version 1.0
0 0
- for宏惰性求值记录
- 惰性求值?
- 惰性编程和惰性求值
- javascript中的惰性求值
- js实现惰性求值
- 惰性求值-Lazy evaluation
- 『惰性求值』初探
- 惰性求值的简单介绍
- 惰性求值和yield-Python
- Python学习之惰性求值
- scala_严格求值和惰性求值
- 关于Python的惰性求值与惰性序列
- 惰性求值与形式化的一些联系
- 惰性求值与尾递归的关系
- 【JavaScript】实现一个数组惰性求值库
- Java 8 中的惰性求值 -- Supplier
- 惰性求值与尾递归的关系2
- 你应该更新的Java知识之惰性求值
- 二叉树的非递归遍历与重建
- 关于未来网站访问速度及后台查询速度的优化建议
- 牛顿迭代算法求平方根
- win732位 + QT4.8.6 + QT CRETER 环境配置的搭建
- iOS 之 MVC 开发模式 理解怎么传递值和更新View
- for宏惰性求值记录
- JAVA的远程调用
- 深入浅出 消息队列 ActiveMQ
- iOS 使用AFNetworking
- iOS工程如何支持64-bit
- 实体类之间的复制
- 图数据挖掘浅析
- 深浅拷贝的理解
- linux操作命令