core.logic

Bug in conde (ClojureScript)

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Minor 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.

Activity

Hide
David Nolen added a comment -

I'm assuming this is referring the ClojureScript version of core.logic?

Show
David Nolen added a comment - I'm assuming this is referring the ClojureScript version of core.logic?
David Nolen made changes -
Field Original Value New Value
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.
{quote}
(defn foobad
  [?bar]
  (l/project [?bar]
    (l/fresh [?var]
      (l/conde
        [(l/== true (instance? js/Array ?bar))
          (membero ?var (seq ?bar))]))))
{quote}
When running (l/run* [?f] (foobad 0)) it produces this error:
{quote}#<Error: No protocol method ISeqable.-seq defined for type number: 0>{quote}
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:
{quote}
(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))]))))
{quote}
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.
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.

{code}
(defn foobad
  [?bar]
  (l/project [?bar]
    (l/fresh [?var]
      (l/conde
        [(l/== true (instance? js/Array ?bar))
          (membero ?var (seq ?bar))]))))
{code}

When running (l/run* [?f] (foobad 0)) it produces this error:
{quote}#<Error: No protocol method ISeqable.-seq defined for type number: 0>{quote}
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:

{code}
(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))]))))
{code}

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.
David Nolen made changes -
Summary Bug in conde Bug in conde (ClojureScript)
Hide
David Nolen added a comment -

This is not a bug. Goals do not delay evaluation in this way.

Show
David Nolen added a comment - This is not a bug. Goals do not delay evaluation in this way.
David Nolen made changes -
Resolution Declined [ 2 ]
Status Open [ 1 ] Resolved [ 5 ]
David Nolen made changes -
Status Resolved [ 5 ] Closed [ 6 ]

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: