On Wed, Sep 14, 2011 at 2:21 PM, Mark Rathwell <mark.rathw...@gmail.com> wrote:
> The distinction is that you type hint function parameters to tell the
> compiler that this function parameter will always be of the specified
> type.  You coerce something that may or may not be of a desired type,
> but is known to cleanly convert to that type.
>
> So:
>
> (defn add-two [^long x]
>  (+ x 2))
> ;=> #'user/add-two
>
> (add-two (long 1.2))
> ;=> 3
>

Should have noted that obviously calling 'add-two' with 1.2 would
coerce to long, but the point is about what the code is saying (if it
could talk).


> On Wed, Sep 14, 2011 at 2:03 PM, Sergey Didenko
> <sergey.dide...@gmail.com> wrote:
>> What is the intended difference between type hinting like "^long" and
>> type coercing like "(long arg)"?
>>
>> For example my gut feeling for this case is to use ^long but it is forbidden:
>>
>> (loop [^long x 0]
>> ...)
>>
>> "Can't type hint a local with a primitive initializer"
>>
>> So I use
>>
>> (loop [x (long 0)]
>> ...)
>>
>> But not quite sure if it's right.
>>
>> --
>> 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

Reply via email to