On 12/06/12 19:41, Alan Malloy wrote:
It's not just less convenient, but genuinely incorrect to use dot-
notation for protocol functions. Not every class that satisfies the
protocol will be implementing the interface directly, and so dot-
notation will fail on them. The interface generated by defprotocol
exists primarily to allow the compiler to optimize certain cases, not
because it's an interface your application should be using.

Hmmm...that sort of makes sense but i wasn't planning on implementing the protocol outside the current namespace - only consuming its implementors. Perhaps from a java program - that is why I gave java-like names to my methods and overrode toString from object on my records. The original confusion arose from the fact that I wanted to pass IPiece as argument to avoid reflection which is not needed after all!

Within the definition of a record is it again recommended to call methods without the dot? for example is this completely wrong? (notice "(.getGridPosition this)" and (.getListPosition this))

(defrecord ChessPiece [^java.awt.Image image
                       ^java.awt.Point position
                        rank ^Integer value]
 Piece
 (update-position [this np] ;mutable state inside Point!
   (.setLocation position   ;can accept ints or doubles
    ^double (first np) ^double (second np))) ;np should be [x, y]
(die [this] (vary-meta this assoc :dead true)) ;communicate death through meta-data (promote [this] (make-chessItem image position :chess? true :rank 'queen)) ;a pawn is promoted to a queen
 (getGridPosition [this] (vector (.getX position) (.getY position)))
(getListPosition [this] (translate-position (first (.getGridPosition this)) (second (.getGridPosition this)) (chess :mappings)))
 (getPoint [this] position)
 (getMoves [this] nil) ;TODO
 Object
 (toString [this]
(println "ChessItem (" rank ") at position:" (.getListPosition this) " ->" (.getGridPosition this))) )


Thanks everyone for your precious time...


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

Reply via email to