有什么方法可以存储在前提条件下执行的计算结果,以便可以在实际的函数体中使用它。
这太糟糕了(昂贵的计算运行两次):
(defn bar [x]
{:pre [(> (costly-computation x) 1337)]}
(costly-computation x))
我想按照这些思路做一些事情。但这不起作用。
(defn smartbar [x]
(let [res (costly-computation x)]
{:pre [(> res 1337)]}
res))