Yes, thank you for your reply,i total agree with you about why we need
:inline form in meta map.
But my problem is that why clojure compiler could not use the body form as
the :inline value automatically for us instead of writing a duplicate form?
I think below codes is more suitable:
(defn pos?
"Returns true if num is greater than zero, else false"
{
:inline true
:added "1.0"}
[x] (. clojure.lang.Numbers (isPos x)))
Then clojure compiler finds out that we set :inline to be true and captures
the body form as the :inline value automatically,is it not better?
If the function accepts different arguments arities, we can set
:inline-arities value to make compiler captures the body form which
arguments count equals to :inline-arities value as :inline value.
2012/7/16 Aaron Cohen <[email protected]>
> My guess: to allow functions with :inline metadata to still be used as
> higher order (first class) functions.
>
> Note, the fn specified by :inline is more of a macro than a function, it's
> called at compile time.
>
> How would the following work without a function body?
>
> (map pos? [-1 0 1])
>
> definline gives you what you're asking for, a way to define an :inline
> function without repetition.
>
> --Aaron
>
> On Sun, Jul 15, 2012 at 10:43 PM, dennis zhuang <[email protected]>wrote:
>
>> Inline a function in clojure is easy,just define a :inline form to meta
>> map and it will be inlined into the form which calls it.For example,the
>> pos? function in clojure.core:
>>
>> (defn pos?
>>
>> "Returns true if num is greater than zero, else false"
>>
>> {
>>
>> :inline (fn [x] *`(. clojure.lang.Numbers (isPos ~x))*)
>>
>> :added "1.0"}
>>
>> [x] *(. clojure.lang.Numbers (isPos x))*)
>>
>>
>> But i have a question about the usage,why we have to write the body
>> form(Here is *(. clojure.lang.Numbers (isPos ~x))*) twice both in
>> function's body and :inline value? Why :inline form could not just use the
>> form in function's body instead of duplicate definition?
>>
>>
>> --
>> 庄晓丹
>> Email: [email protected] [email protected]
>> Site: http://fnil.net
>> Twitter: @killme2008
>>
>>
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to [email protected]
>> Note that posts from new members are moderated - please be patient with
>> your first post.
>> To unsubscribe from this group, send email to
>> [email protected]
>> 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 [email protected]
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
--
庄晓丹
Email: [email protected] [email protected]
Site: http://fnil.net
Twitter: @killme2008
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en