【问题标题】:Clojure: How to Check if Input is Only One Sequence Long? [closed]Clojure:如何检查输入是否只有一个序列长? [关闭]
【发布时间】:2020-03-07 22:12:32
【问题描述】:
(defn recursive_function

 [total]                   ;let's say total is: (why you(piece of(poop)))

  (cond                    ;if there is only one parenthesis set left

 (;if only (why you) is left) (System/exit 0)

  )

 (map (fn [i]    
     (cond
       (seq? i) (recursive_function total)

       ;otherwise do things to make total shorter (I did not add this code as it
       ;would make this stack overflow question rather long. But essentially this map
       ;will eventually recursively reduce  (why you(piece of(poop))) to ->  (why you)

       )
   idealreturn) 

)

一旦“total”被简化为单个序列或括号,例如 (why you),我如何编写 Cond 来检查它是否只有一个括号集?

【问题讨论】:

    标签: recursion clojure


    【解决方案1】:

    我不确定我是否正确理解了这个问题。因此,如果您想检查序列是否不包含任何序列作为元素。

    (not-any? seq? '(why you))
    => true
    
    (not-any? seq? '(why you (piece of (poop)))
    => false
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-02-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-24
      • 2013-01-05
      相关资源
      最近更新 更多