试图在Clojure中创建空集

试图在Clojure中创建空集,clojure,set,Clojure,Set,我有一个名为not消去的函数,它接受一个参数并应用not推断规则,该规则声明:(not(not x))推断x。例如,如果我的参数是“(not(nota)),那么#{a}将是我的输出。示例2,参数:'(不是(不是)(不是))输出:#{(不是)} 我遇到的问题是,我的参数是“(而不是x),它应该返回{}(空集),但我得到了下面的错误。你知道问题出在哪里吗 Execution error (IllegalArgumentException) at microproject2.core/not-

我有一个名为not消去的函数,它接受一个参数并应用not推断规则,该规则声明:(not(not x))推断x。例如,如果我的参数是“(not(nota)),那么#{a}将是我的输出。示例2,参数:'(不是(不是)(不是))输出:#{(不是)}

我遇到的问题是,我的参数是“(而不是x),它应该返回{}(空集),但我得到了下面的错误。你知道问题出在哪里吗

    Execution error (IllegalArgumentException) at microproject2.core/not-elimination (core.clj:7).
Don't know how to create ISeq from: clojure.lang.Symbol
我的代码:

(ns microproject2.core)

(defn not-elimination [expression]
  (if(not-empty expression)
  (if (= (nth expression 1) "x" )
    (set {})
   (sorted-set-by > (last (last expression))))
  (println "The list is empty")))

下面是一个有效的示例,包括一些单元测试:

(ns tst.demo.core
  (:use tupelo.core tupelo.test))

(defn not-elimination
  [expr]
  (if (not-empty? expr)
    (if (= (symbol "x") (second expr))
      #{}   ; and empty set, could use `(hash-set)`
      (sorted-set-by > (last (last expr))))
    :the-list-is-empty))

(dotest
  (is= #{} (hash-set)) ; both are equivalent

  (is= :the-list-is-empty (not-elimination '()))
  (is= (hash-set 'x) (not-elimination '(not (not x))))
  (is= #{ '(not x) } (not-elimination '(not (not (not x)))))
  )

它基于。

(last(last)(不是x))
是您的问题。还有为什么
(不是(不是x))
(不是x)
,但是
(不是x)
不是
(不是x)
?我实际上还发现了另一个问题。我的第二个if语句的计算结果永远不会为true。为了回答您的问题,它返回为空,因为我们无法推断任何东西。我们可以推断“(不是x)”,因为在(不是(不是x)),前两个不是根据逻辑规则相互抵消,所以我们剩下的不是x就像一个符咒,谢谢!!我现在知道我的错误了