trampoline not compatible with reducers?
Hi everyone, I'm pretty sure i'm using trampoline the right way but still I get this exception: ClassCastException Clondie24.lib.search$search$minimize__3075$fn__3076 cannot be cast to java.lang.Number Clondie24.lib.search/search/minimize--3075 (search.clj:47) here is the code: (defn search The recursive bit of the min-max algorithm. [eval-fn tree depth] (letfn [(minimize ^double [tree d] (if (zero? d) (eval-fn (:root tree) (:direction tree)) #(r/reduce my-min (r/map (fn [child] (maximize (:tree child) (dec d))) (:children tree) (maximize ^double [tree d] (if (zero? d) (eval-fn (:root tree) (:direction tree)) #(r/reduce my-max (r/map (fn [child] (minimize (:tree child) (dec d))) (:children tree)] (trampoline minimize tree (int depth Can anyone shine some light? Is it something that has to do with reducers? Jim ps: it works fine without trampoline and '#' behind 'r/reduce'. -- 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: trampoline not compatible with reducers?
you are declaring the functions return doubles, but in fact returning functions or doubles On Tue, Oct 16, 2012 at 11:06 AM, Jim - FooBar(); jimpil1...@gmail.com wrote: Hi everyone, I'm pretty sure i'm using trampoline the right way but still I get this exception: ClassCastException Clondie24.lib.search$search$minimize__3075$fn__3076 cannot be cast to java.lang.Number Clondie24.lib.search/search/minimize--3075 (search.clj:47) here is the code: (defn search The recursive bit of the min-max algorithm. [eval-fn tree depth] (letfn [(minimize ^double [tree d] (if (zero? d) (eval-fn (:root tree) (:direction tree)) #(r/reduce my-min (r/map (fn [child] (maximize (:tree child) (dec d))) (:children tree) (maximize ^double [tree d] (if (zero? d) (eval-fn (:root tree) (:direction tree)) #(r/reduce my-max (r/map (fn [child] (minimize (:tree child) (dec d))) (:children tree)] (trampoline minimize tree (int depth Can anyone shine some light? Is it something that has to do with reducers? Jim ps: it works fine without trampoline and '#' behind 'r/reduce'. -- 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 -- And what is good, Phaedrus, And what is not good— Need we ask anyone to tell us these things? -- 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: trampoline not compatible with reducers?
On 16/10/12 19:15, Kevin Downey wrote: you are declaring the functions return doubles, but in fact returning functions or doubles yes you're right (my bad) but the same thing happens without the type-hinting - albeit in a different place and different originating function: ClassCastException Clondie24.lib.search$search$maximize__3081$fn__3082 cannot be cast to java.lang.Number clojure.lang.Numbers.lt (Numbers.java:219) 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: trampoline not compatible with reducers?
if you look further down the stacktrace (where it refers to your code instead of clojure.lang.Numbers.lt) it will give you line numbers in your code to look at. you are calling these trampolined functions without trampoline. On Tue, Oct 16, 2012 at 11:24 AM, Jim - FooBar(); jimpil1...@gmail.com wrote: On 16/10/12 19:15, Kevin Downey wrote: you are declaring the functions return doubles, but in fact returning functions or doubles yes you're right (my bad) but the same thing happens without the type-hinting - albeit in a different place and different originating function: ClassCastException Clondie24.lib.search$search$maximize__3081$fn__3082 cannot be cast to java.lang.Number clojure.lang.Numbers.lt (Numbers.java:219) 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 -- And what is good, Phaedrus, And what is not good— Need we ask anyone to tell us these things? -- 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: trampoline not compatible with reducers?
'my-min' and 'my-max' simply wrap core/min core/max. You mean i have to trampoline these calls as well? return something like this? : #(r/reduce (trampoline my-max) ;;was my-max (r/map (fn [child] (minimize (:tree child) (dec d))) (:children tree))) Jim On 16/10/12 20:01, Kevin Downey wrote: if you look further down the stacktrace (where it refers to your code instead of clojure.lang.Numbers.lt) it will give you line numbers in your code to look at. you are calling these trampolined functions without trampoline. On Tue, Oct 16, 2012 at 11:24 AM, Jim - FooBar(); jimpil1...@gmail.com wrote: On 16/10/12 19:15, Kevin Downey wrote: you are declaring the functions return doubles, but in fact returning functions or doubles yes you're right (my bad) but the same thing happens without the type-hinting - albeit in a different place and different originating function: ClassCastException Clondie24.lib.search$search$maximize__3081$fn__3082 cannot be cast to java.lang.Number clojure.lang.Numbers.lt (Numbers.java:219) 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: trampoline not compatible with reducers?
Reducers don't enter into the picture at all: this code is just as broken with clojure.core/reduce and clojure.core/map. The immediate problem that Kevin is trying to draw your attention to is that you are calling (reduce max (map my-fn coll)), where my-fn sometimes returns a number, and sometimes a thunk. Obviously max can't be expected to compare thunks for you, so that's no good. His suggestion is to make sure to trampoline the results of (map my-fn coll) until you get out a list of numbers, and then find the max. But really I don't think trampoline is a very compelling problem- solver here: the primary (only?) gain from trampoline is in reducing stack depth, and I rather doubt that you can calculate minimax for even a few hundred ply. So you're in no danger of a stackoverflow, but are sacrificing readability and a smidge of performance to keep your stack really small instead of not big enough to be a problem. On Oct 16, 12:45 pm, Jim - FooBar(); jimpil1...@gmail.com wrote: 'my-min' and 'my-max' simply wrap core/min core/max. You mean i have to trampoline these calls as well? return something like this? : #(r/reduce (trampoline my-max) ;;was my-max (r/map (fn [child] (minimize (:tree child) (dec d))) (:children tree))) Jim On 16/10/12 20:01, Kevin Downey wrote: if you look further down the stacktrace (where it refers to your code instead of clojure.lang.Numbers.lt) it will give you line numbers in your code to look at. you are calling these trampolined functions without trampoline. On Tue, Oct 16, 2012 at 11:24 AM, Jim - FooBar(); jimpil1...@gmail.com wrote: On 16/10/12 19:15, Kevin Downey wrote: you are declaring the functions return doubles, but in fact returning functions or doubles yes you're right (my bad) but the same thing happens without the type-hinting - albeit in a different place and different originating function: ClassCastException Clondie24.lib.search$search$maximize__3081$fn__3082 cannot be cast to java.lang.Number clojure.lang.Numbers.lt (Numbers.java:219) 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