-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

i tried using letfn insteaf of defn for inner functions.

(def open 0)
(def p1 1)
(def p2 2)
(def emptyfield [open open open open open open open open open])

(defn indexOf [x y] (+ x (* y 3)))

(defn withmove [x,y,player,field]
  (assoc field (indexOf x y) player))

(defn winner [field]
  (letfn [(rowOwnedBy [row player]
            ((let [beginIndex (indexOf 0 row)
                   currow (subvec field beginIndex (+ 3 beginIndex))]
               (= [player] (distinct currow)))
              ))
          (colOwnedBy [col player]
            ((let [beginIndex (indexOf col 0)
                   curcol (take-nth 3 (drop beginIndex field))]
               (= [player] (distinct curcol)))
              ))
          (winPred [player]
            ((loop [cnt 0]
               (if (= cnt 3) false (or (rowOwnedBy cnt player)
(colOwnedBy cnt player) (recur (inc cnt)))))))]
    ((let [winnerIfExists (filter winPred [p1 p2])]
       (if (empty? winnerIfExists) open (first winnerIfExists))))))


(let [moves [[0 0 p1] [1 0 p1] [2 0 p1]]]
  (defn fold [field nextmove]
    (withmove (nth nextmove 0) (nth nextmove 1) (nth nextmove 2) field))
  (let [endstate (reduce fold emptyfield moves)]
    (println (winner endstate))))


i'm getting an exception:
Caused by: java.lang.RuntimeException: java.lang.ClassCastException:
java.lang.Boolean cannot be cast to clojure.lang.IFn

in this line:
(= [player] (distinct currow)))

why does clojure want to cast the result to IFn?


Am 04.09.2011 19:57, schrieb Sergey Didenko:
> Dennis, may I suggest you to read this great article on Clojure: 
> http://java.ociweb.com/mark/clojure/article.html
> 
> 
> 
> -- 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


- -- 

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.14 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQIcBAEBAgAGBQJOZhuaAAoJENRtux+h35aGaF0P/1xnMYA/gUuvGsBnmM5VmGBQ
ncU9+3E8h4EKClatl0rdo+B4BLObYsyg7Xb3IPVdGCf5lofQVOneX2Uk41tVvM/Q
E98uxotCMUjVcaOuEtLUMNBOQCy0q31erOzdKlaaecQ2KTY+GvBRRxpAbo33uqmP
DaGmSiyzTGkVp9PhKcMzEjneSOagEA6oG0cOOInarfQS8Q7gQXP6Wir63kVcps72
yhtNuJmhyTOQQ7H2c+j/+mawk12YHPmD4TmLLg2/cG3ZEeaGdWS2DeWL8FVKuZ4/
grYnP1PldaOCTsrcDDCEwkM/eNxCSVqopz3LIS7oyhr8eEp9j1/Gkko56YZZYWhL
ITHE083+QZ7gi/F+kQmz3Yrd8ZCeoWW7mL18d8qMppRZYlrtywwhKnFARU24VYvB
hh+9Twtv22oqBnQmP3Xf2kisaFGHaf8ke1yz1upvB2L996xo/wRI7rirxWQUZtOi
XLYZIowcPRf27gpTpSFplqO+92awA4pcvOgpqUuIb3FYBmSuIQI9MatQ3IzaHh9T
tlF6hqFWvgkzR98CBnM2RpgE//qb0sM/DC0/lth5jUoULRN3rmpMUiSIvdwDS8TH
60ipp6IG/m8Ou+rqlEF33oPQU8DKVF26DmS5X7zWB/36VioqmuD/STov3qIabAfx
Pw4JDW8nmQwcDb4gSjPI
=Pw61
-----END PGP SIGNATURE-----

-- 
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

Reply via email to