fully type-hinted record still uses reflection!
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] (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
Re: fully type-hinted record still uses reflection!
On Sun, Jun 10, 2012 at 1: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] (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! Would (.setLocation position) possibly behave differently maybe? Worth a try? Lars Nilsson -- 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
Re: fully type-hinted record still uses reflection!
On Sun, Jun 10, 2012 at 1:08 PM, Lars Nilsson chamael...@gmail.com wrote: On Sun, Jun 10, 2012 at 1: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] (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! Would (.setLocation position) possibly behave differently maybe? Worth a try? Ehh... With the two arguments I forgot to include in the call obviously.. Lars Nilsson -- 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
Re: fully type-hinted record still uses reflection!
Thanks Lars but there is no difference...when i try to load my namespace I get this output: Clondie24.core= (load-file src/Clondie24/core.clj) #'Clondie24.core/-mainReflection warning, /home/sorted/clooJWorkspace/Clondie24/src/Clondie24/core.clj:104 - call to setLocation can't be resolved. Reflection warning, /home/sorted/clooJWorkspace/Clondie24/src/Clondie24/core.clj:122 - call to setLocation can't be resolved. Reflection warning, /home/sorted/clooJWorkspace/Clondie24/src/Clondie24/core.clj:206 - reference to field getListPosition can't be resolved. Reflection warning, /home/sorted/clooJWorkspace/Clondie24/src/Clondie24/core.clj:251 - call to update_position can't be resolved. Of the 4 warnings only the last 2 can be justified (it is not predetermined what type comes in)...the first 2 refer to 2 different records that do the same thing as far as updating the position goes and setLocation is the culprit again! Jim On 10/06/12 18:09, Lars Nilsson wrote: On Sun, Jun 10, 2012 at 1:08 PM, Lars Nilssonchamael...@gmail.com wrote: On Sun, Jun 10, 2012 at 1: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] (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! Would (.setLocation position) possibly behave differently maybe? Worth a try? Ehh... With the two arguments I forgot to include in the call obviously.. Lars Nilsson -- 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
Re: fully type-hinted record still uses reflection!
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
Re: fully type-hinted record still uses reflection!
a.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
Re: fully type-hinted record still uses reflection!
On 10/06/12 18:43, Ben Smith-Mannschott wrote: 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 Yep, it works...only 2 warnings now! btw, you can't have int primitive type-hinting - only double or long. 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
Re: fully type-hinted record still uses reflection!
You can cast to primitive int with (int ...) On Sun, Jun 10, 2012 at 1:53 PM, Jim - FooBar(); jimpil1...@gmail.comwrote: On 10/06/12 18:43, Ben Smith-Mannschott wrote: 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 Yep, it works...only 2 warnings now! btw, you can't have int primitive type-hinting - only double or long. 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+unsubscribe@**googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/**group/clojure?hl=enhttp://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