I don't understand!!! why would this work and the previous won't? I am
still using [+, -] from clojure.core...
(defn knight-moves [x y]
(let [xmax 8 ymax 8]
(run* [q]
(fresh [a b]
(conde
[(< (+ x 1) xmax) (< (+ y 2) ymax) (== a (+ x 1)) (== b (+ y 2))]
;1st possibility
[(< (+ x 2) xmax) (< (+ y 1) ymax) (== a (+ x 2)) (== b (+ y 1))]
;2nd possibility
[(< (+ x 2) xmax) (>= (- y 1) 0) (== a (+ x 2)) (== b (- y 1))]
;3rd possibility
[(< (+ x 1) xmax) (>= (- y 2) 0) (== a (+ x 1)) (== b (- y 2))]
;4th possibility
[(>= (- x 1) 0) (>= (- y 2) 0) (== a (- x 1)) (== b (- y 2))]
;5th possibility
[(>= (- x 2) 0) (>= (- y 1) 0) (== a (- x 2)) (== b (- y 1))]
;6th possibility
[(>= (- x 2) 0) (< (+ y 1) ymax) (== a (- x 2)) (== b (+ y 1))]
;7th possibility
[(>= (- x 1) 0) (< (+ y 2) ymax) (== a (- x 1)) (== b (+ y 2))]
;8th possibility
)
(== q [a b])))))
the above works like a charm but the one below fails with exception even
without the 'Math/abs'
bit:
(defn bishop-moves [x y]
(let [xmax 8 ymax 8]
(run* [q]
(fresh [a b]
(< a xmax)
(< b ymax)
(= (- x a)
(- y b))
(== q [a b])))))
They are very similar aren't they? same operators, same functions etc etc...
any help/clarification?
Jim
On 07/08/12 11:34, Jim - FooBar(); wrote:
On 07/08/12 11:26, Moritz Ulrich wrote:
You can. Using core logic 0.8 alpha thanks to the newly introduced
cKanren extensions. It's mentioned in the (or another, I'm not sure
at the moment) video.
I just found an answer on SO recommending 'project' for non-relational
arithmetic...could this be exactly what I need (for subtraction at
least)? as far as the 'Math/abs' bit is concerned I really don't know
what to do!
Jim
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en