Hi Marek,
I did what you said and I translated the prolog code to core.logic. Your
2 examples helped a lot and thanks again for that. The versionI've got
now is this:
-----------------------------------------------------------------------------------------------
(defn knight-moves [x y]
(let [xmax 8 ymax 8]
(run* [q] ;bring back all possible solutions
(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])) ;return each solution as a vector [x, y]
)))
----------------------------------------------------------------------------------------------------
However now I get:
ClassCastException java.lang.Boolean cannot be cast to clojure.lang.IFn
on the first clause! Is this what you meant that I need to define my own
"greather than" and "lower than" operators? I'm suspecting that is
exactly what you meant cos there is something definately missing! Why
won't clojure's operators do the job? I'm just checking arithmetic
values...what is the problem?
Jim
On 11/06/12 17:34, David Nolen wrote:
On Mon, Jun 11, 2012 at 12:30 PM, mnicky <markus.mas...@gmail.com
<mailto:markus.mas...@gmail.com>> wrote:
You can probably substitute the "is" operator of Prolog with the
"==" operator of core.logic, but very likely you will have to
define your own "greather than" and "lower than" operators...
Marek.
There is an arithmetic namespace that has these non-relational
operators. I've started working on cKanren extensions again so the
story around arithmetic should improve a lot in the next couple of weeks.
David
--
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
--
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