[英]Trying to create an empty set in Clojure
I have this function called not-elimination which takes an argument and applies the not inference rule which states: (not (not x)) infer x.我有一个名为 not-elimination 的函数,它接受一个参数并应用 not inference 规则,该规则指出:(not (not x)) infer x。 So for example if my argument is '(not (not a)) then #{a} would be my output.
因此,例如,如果我的参数是 '(not (not a)) 那么 #{a} 将是我的输出。 Example 2, Argument: '(not (not (not a))) Output: #{(not a)}
示例 2,参数:'(not (not (not (not a)))) 输出:#{(not a)}
The problem I am running into is the case where my argument is '(not x) which is supposed to return #{} (empty set), but I am getting the error below.我遇到的问题是我的参数是 '(not x) ,它应该返回 #{} (空集),但我收到以下错误。 Any ideas on what the problem is?
关于问题出在哪里的任何想法?
Execution error (IllegalArgumentException) at microproject2.core/not-elimination (core.clj:7).
Don't know how to create ISeq from: clojure.lang.Symbol
My code:我的代码:
(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")))
Here is an example that works, including some unit tests:这是一个有效的示例,包括一些单元测试:
(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)))))
)
It is based on this template project .它基于这个模板项目。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.