本文介绍了Clojure函数 - 返回在最后一条语句之前计算的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些测试用clojure写的。这是一个简单的例子:

I have some tests written in clojure. This is a simple example:

(defn test1
  []
  (start-server)
  (run-pvt-and-expect "PVT-0")
  (stop-server)
 )

我想返回run-pvt-and-expect的结果,但是我需要在它之后执行其他函数。我如何在clojure中以功能的方式(不使用像let这样的结构)?感谢。

I would like to return the result of "run-pvt-and-expect", but I need to execute other functions after it. How can I do this in clojure in a functional way (without using constructs like "let")? Thanks.

注意:我阅读了
相关部分是:

Here is the relevant doc page.The releavant part is:

另一个选项是编写一个类似于open的宏,以在返回正确的结果时启动和停止服务器。虽然这只是将问题移到了你如何写宏,因为它需要使用let或者try finally结构上面。

Another option would be to write a macro like with-open to start and stop your server while returning the right results. Though that just moves the problem to how do you write the macro, since it would either need to use a let or the try finally construct above.

这篇关于Clojure函数 - 返回在最后一条语句之前计算的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 11:29
查看更多