If statement Clojure-如果基于某个结果

If statement Clojure-如果基于某个结果,if-statement,clojure,If Statement,Clojure,我想以道歉开始这篇文章,我完全是自吹自擂,这是我的第一个问题,尽管我经常使用Stackoverflow 我想根据某个函数的结果做出决定 (if (= nil (some (partial = (:activeboard (:boards app))) (:otherboards (:boards app)))) (om/transact! (:boards app) :activeboard (fn [_] active))) 我知道some测试可以工作,

我想以道歉开始这篇文章,我完全是自吹自擂,这是我的第一个问题,尽管我经常使用Stackoverflow

我想根据某个
函数的结果做出决定

(if (= nil (some (partial = (:activeboard (:boards app)))
                 (:otherboards (:boards app))))
  (om/transact! (:boards app) :activeboard (fn [_] active)))

我知道
some
测试可以工作,因为我有相同的
some
功能,可以将结果输出到屏幕。但是
if
测试没有。我也试过类似的
案例
condp
。似乎没有任何东西可以评估
某些
函数。
some
函数的结果要么是
nil
,要么是
true
,因此
if
应该评估一下???

if
中评估
some
没有什么特别的,而且据我所知,你的代码很好。看看下面,看看您是否可以构建类似的东西(我们都可以尝试自己运行),并演示问题

情况1,activeboard包含在otherboard中:

(def app {:boards {:activeboard 1 :otherboards [1 2 3]}})

(if (= nil (some (partial = (:activeboard (:boards app))) (:otherboards (:boards app))))
  (println "some returned nil")
  (println "some did not return nil"))
(def app {:boards {:activeboard 1 :otherboards [2 3 4]}})

(if (= nil (some (partial = (:activeboard (:boards app))) (:otherboards (:boards app))))
  (println "some returned nil")
  (println "some did not return nil"))
评估:

>> some did not return nil
>> some returned nil
情况2,activeboard不包括在otherboard中:

(def app {:boards {:activeboard 1 :otherboards [1 2 3]}})

(if (= nil (some (partial = (:activeboard (:boards app))) (:otherboards (:boards app))))
  (println "some returned nil")
  (println "some did not return nil"))
(def app {:boards {:activeboard 1 :otherboards [2 3 4]}})

(if (= nil (some (partial = (:activeboard (:boards app))) (:otherboards (:boards app))))
  (println "some returned nil")
  (println "some did not return nil"))
评估:

>> some did not return nil
>> some returned nil

首先,代码缩进可以在很大程度上帮助您理解自己的代码。我对你的问题进行了编辑,以便至少更清楚一点

第二,考虑使用线程第一操作符(<代码> ->代码>)或<代码>获取在地图中的多个级别中导航。但这只是一种代码风格

您的情况看起来很好,正如@jas已经演示的那样。可能让您陷入麻烦的是,您没有为
if
提供“else”路径。
if
宏需要三个“参数”:条件、“then”块和“else”块。如果您只想测试您的真实情况,请在
时使用


希望这能有所帮助。

谢谢,不过我希望我的代码是错的:-(这会使修复变得更容易。谢谢你的编辑,我试图找出如何将其放入代码块中,但没有一个选项看起来是正确的。我的印象是,你可以只提供一个then选项,而不为“其他”做任何事情块。我会看看什么时候,看到这是一个可能性。你是正确的,<代码>如果< /代码>没有一个“其他”块,但很多人认为使用< < > > > < >代码>的情况下更好。