On Sat, Jun 19, 2010 at 6:32 AM, Rich Hickey <richhic...@gmail.com> wrote: > Really? It seems tedious to me. Don't you get tired of saying int i = 42 in > Java, when you know full well the compiler knows 42 is an int? I do, and > Clojure is competing with languages that infer the right types without the > redundancy.
In this case, the question isn't so much whether Clojure can figure out that 42 is a primitive or boxed integer. The question is whether the programmer wants to insist that, upon recurrence, the primitiveness must match the initial binding. Right now, Clojure makes the determination about what the recurrence needs to be based on the initial binding, so it becomes paramount for the programmer to understand the type of that initial binding. But conceivably there are other ways that Clojure could make a determination about what kind of loop/recur behavior you want other than the type of the initial binding. So an alternative way to think about this is to relax the restriction that a recur must match the primitiveness of the loop binding, but allow the programmer to somehow control whether they want this primitive-matching behavior or not. Ideally, the behavior of recur should be readily apparent from inspection of the code. Unfortunately, the type of the initial binding is not always clear, which suggests to me that another scheme would be preferable. Sadly, I don't have any idea right now on how to cleanly specify the desired loop/recur behavior other than something that looks a lot like type annotations. But thinking of it in this way opens up the possibility of other solutions (such as a loop' construct), so maybe brainstorming along these lines will be useful. I agree with another poster that the holy grail would be if loop/recur automagically gave performance benefits when recurring with a primitive that matched the initial binding, but if you recur with something else, it just gracefully rolls over to a boxed version of the whole loop. Given that Java has no way of expressing that something can be a primitive or an Object, this seems unlikely to be possible, but perhaps with that ideal in mind, some approximation can be found. > Again, it is a matter of defaults, the non-default is going to have to be > explicit, and you can just as easily be explicit that you want the loop > argument to be an Object, either with (loop [^Object i 42] ...), (loop [i > (num 42)] ...) or your (loop' [i 42] ...) idea. Agreed, but with a default of boxing, it is possible to write all code without ever using an annotation -- it will just be a bit slower than it could be. With a default of primitives, there is ordinary code that won't work properly unless you dig deeper into Clojure and learn all about explicit boxing and figure out when and where to use it. I prefer the default where I can ignore tedious type annotations and my code "just works". -- 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