core.logic

fd comparison relations behave strange when used with literals

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Environment:

Description

The fd comparison relations always succeed when used with strings or a string and an integer:

user> (run* [q]
 (<=fd "foo" "bar"))
(_.0)
user> (run* [q]
 (<=fd "foo" 1))
(_.0)
user> (run* [q]
 (<=fd 1 "bar"))
(_.0)

IMHO, they should always fail if one argument is not a integer.

Furthermore, you get an exception when comparing integers and the larger integer is given first.

user> (run* [q]
 (<=fd 1 2))
(_.0)  ;; That's correct, but...
user> (run* [q]
 (<=fd 2 1))
IllegalArgumentException No implementation of method: :member? of protocol: #'clojure.core.logic/ISet found for class: nil  clojure.core/-cache-protocol-fn (core_deftype.clj:533)

I'd expect that comparisons of two integers should always work. You can circumvent this issue by unifying the numbers with some logic variables first, but is that really needed?

user> (run* [q]
 (fresh [a b]
  (== a 1)
  (== b 2)
  (<=fd a b)))
(_.0)
user> (run* [q]
 (fresh [a b]
  (== a 1)
  (== b 2)
  (<=fd b a)))
()

The first issue cannot be circumvented using this approach, though.

user> (run* [q]
 (fresh [a b]
  (== a "foo")
  (== b 2)
  (<=fd b a)))
(_.0)
user> (run* [q]
 (fresh [a b]
  (== a "foo")
  (== b 2)
  (<=fd a b)))
(_.0)
user> (run* [q]
 (fresh [a b]
  (== a "foo")
  (== b "bar")
  (<=fd a b)))
(_.0)
user> (run* [q]
 (fresh [a b]
  (== a "foo")
  (== b "bar")
  (<=fd b a)))
(_.0)

Activity

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: