Details
-
Type:
Defect
-
Status:
Resolved
-
Priority:
Minor
-
Resolution: Declined
-
Affects Version/s: None
-
Fix Version/s: None
-
Component/s: None
-
Labels:
-
Environment:[org.clojure/clojure "1.4.0"]
[org.clojure/core.logic "0.8.0-beta2"]
Description
While working on a project I found a somewhat strange behaviour. I reworked the problem in some simple predicate. Let's take this predicate foobad.
(defn foobad
[?bar]
(l/project [?bar]
(l/fresh [?var]
(l/conde
[(l/== true (instance? js/Array ?bar))
(membero ?var (seq ?bar))]))))
When running (l/run* [?f] (foobad 0)) it produces this error:
#<Error: No protocol method ISeqable.-seq defined for type number: 0>
Because 0 is not an instance of Array it should not be entering that conde clause where it tries (seq 0).
With this workaround we get a normal behaviour:
(defn foo
[?bar]
(l/project [?bar]
(l/fresh [?var]
(l/conde
[(l/== true (instance? js/Array ?bar))
(fresh [?s]
(l/== ?s (seq ?bar))
(membero ?var ?s))]))))
Running (l/run* [?f] (foo 0)) gives us (), which is what we expect.
While 0 is clearly not an instance of Array that conde clause is still executed resulting in previous error.