On Thu, Jul 30, 2009 at 1:28 AM, John Harrop<jharrop...@gmail.com> wrote:
> user=> (loop [i 0 j (double 1.0)]
>   (if (= i 1) j (recur 1 (+ j j))))
> 2.0
> user=> (loop [i 0 j (double 1.0)]
>   (if (= i 1) j (recur 1 (let [a j b j] (+ a b)))))
> #<CompilerException java.lang.RuntimeException:
> java.lang.IllegalArgumentException: recur arg for primitive local: j must be
> matching primitive (NO_SOURCE_FILE:0)>
> user=> (loop [i 0 j (double 1.0)]
>   (if (= i 1) j (let [a j b j] (recur 1 (+ a b)))))
> 2.0
> So when j is a lowercase-d double, inside (let [a j b j] ... ) a and b are
> lowercase-d doubles, and (+ a b) is a lowercase-d double, but the type of
> the expression (let [a j b j] (+ a b)) is apparently capital-D Double.
> This seems like a bug to me, and could cripple performance in some
> conceivable cases. Primitives should not get boxed when not passed across
> function-call boundaries, and let is not a function.
>

Currently only host expressions and bindings to host expressions of
primitive types can have primitives type. let expressions etc cannot.

One reason is that let etc can have more than one 'type' by containing
conditionals or making calls to polymorphic functions:

;let might have type double or String
(let [j (double 42.0)] (if x j "42"))

Currently there is no analysis to determine that potentially composite
expressions yield a uniform type, which would be required to let a
primitive flow out of a let. It would be a nice enhancement.

Rich

--~--~---------~--~----~------------~-------~--~----~
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