试图在Clojure中创建一个空集



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

我遇到的问题是,我的参数是"(而不是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)))))
)

它是基于这个模板项目。

最新更新