aaaaaaaaa.....A moment of enlightment!!!! thank you so so much...
so what you're saying is that there is no confusion as to what object
(record) to call setLocation on. The confusion arises when trying to
decide which one of the 2 methods to invoke (there are indeed 2 and I
knew it from the start - that is why I've put the little comment there)
thanks a lot Ben...I do know i n advance which one of the 2 to call (the
one accepting doubles) so I'll type-hint accordingly :-)
Jim
On 10/06/12 18:43, Ben Smith-Mannschott wrote:
On Sun, Jun 10, 2012 at 7:04 PM, Jim - FooBar();<jimpil1...@gmail.com> wrote:
Hi again (busy day eh?),
well this doesn't make any sense either! Why is a record with type-hinted
arguments still using reflection?
I've got the following example record:
--------------------------------------------------------------------------------------------------
(defrecord CheckersPiece [^java.awt.Color color
^java.awt.Point position
rank]
Piece
(update-position [this np] ;mutable state inside Point!
(. position setLocation ;can accept ints or doubles
(first np) (second np))) ;np should be [x, y]
"can accept ints or doubles"
How is the Clojure compiler to know wether to compile a call to
Point.setLocation(double,double) or Point.setLocation(int,int)?
I think you need to tell the compiler the types of (first np) and
(second np), which means -- of course -- that you'll need to know
what they are statically.
I'm a little rusty on my type hinting, but have you tried something
like:
(.position setLocation ^double (first np) ^double (second np))
or
(.position setLocation ^int (first np) ^int (second np))
// ben
(die [this] (vary-meta this assoc :dead true)) ;communicate death
through meta-data
(promote [this] (make-checker color position :rank 'prince)) ; a checker is
promoted to prince
(getGridPosition [this] (vector (.getX position) (.getY position)))
(getListPosition [this] (translate-position (first (.getGridPosition
this))
(second (.getGridPosition
this)) board-mappings-checkers))
(getPoint [this] position)
(getMoves [this] nil) ;TODO
Object
(toString [this]
(println "Checker (" rank ") at position:" (.getListPosition this) " ->"
(.getGridPosition this))) )
---------------------------------------------------------------------------------------------------------------------------
and whenever i call update-position it complains that setLocation cannot be
resolved. setLocation is a method in java.awt.Point so i don't see why this
happens!
any suggestions?
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
--
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