如何评估 Clojure 中的一系列不纯函数? [英] How to evaluate a sequence of impure functions in Clojure?

查看:15
本文介绍了如何评估 Clojure 中的一系列不纯函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何评估 Clojure 中的(不纯的)函数列表?例如:

How can I evaluate a list of (impure) functions in Clojure? For instance:

[#(println "1") #(println "2") #(println "3")]

预期的输出是:

1
2
3

有没有办法在不使用宏的情况下实现这一目标?像 (mapevaluate fns-seq) 之类的东西,也许?

Is there a way to achieve this without using macros? Something like (map evaluate fns-seq), maybe?

(我需要它来使用 Clojure.processing API 绘制一些图形.)

(I need this for drawing some graphics using the Clojure.processing API.)

推荐答案

user> (let [fs [#(println "1") #(println "2") #(println "3")]]
         (doseq [f fs] (f)))
1
2
3
nil

这篇关于如何评估 Clojure 中的一系列不纯函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆