I'm not sure. I guess we're stuck with tagging locals at that point?

Thanks,
Ambrose


On Tue, Jun 18, 2013 at 1:38 AM, Jim - FooBar(); <jimpil1...@gmail.com>wrote:

>  OK now I'm confused! If you are using an unnamed  fn form there is only
> one place to put the return type-hin,t and that is between the 'fn' and the
> '[...]'
> ...but, you've just demonstrated that this causes reflection...where else
> can we put it?
>
> Jim
>
>
> On 17/06/13 18:33, Ambrose Bonnaire-Sergeant wrote:
>
> Seems like there's some trickery involved with using Vars.
>
>  This example seems to use reflection.
>
>  user=> (.length ((fn ^String [^String s] (.substring s 0 (.length s)))
> "a"))
> Reflection warning, NO_SOURCE_PATH:1:1 - reference to field length can't
> be resolved.
> 1
>
>  Thanks,
> Ambrose
>
>
> On Tue, Jun 18, 2013 at 1:15 AM, Ambrose Bonnaire-Sergeant <
> abonnaireserge...@gmail.com> wrote:
>
>> Yes, it did. That's interesting. I have no idea where the .length method
>> is being inferred from in the last example.
>>
>>  Carry on :)
>>
>>  Ambrose
>>
>>
>> On Tue, Jun 18, 2013 at 1:10 AM, Jim - FooBar(); <jimpil1...@gmail.com>wrote:
>>
>>>  so how about this then?
>>>
>>>
>>> nREPL server started on port 43830
>>> REPL-y 0.2.0
>>> Clojure 1.5.1
>>>     Docs: (doc function-name-here)
>>>           (find-doc "part-of-name-here")
>>>   Source: (source function-name-here)
>>>  Javadoc: (javadoc java-object-or-class-here)
>>>     Exit: Control+D or (exit) or (quit)
>>>
>>> user=> (set! *warn-on-reflection* true)
>>> true
>>> user=> (defn foo [^String s] (.substring s 0 (.length s)))
>>> #'user/foo
>>> user=> (foo "jim")
>>> "jim"
>>> user=> (.length (foo "jim"))
>>> *Reflection warning, NO_SOURCE_PATH:1:1 - reference to field length
>>> can't be resolved.*
>>> 3
>>> user=> (defn foo ^String [^String s] (.substring s 0 (.length s)))
>>> #'user/foo
>>> user=> (.length (foo "jim"))
>>> 3
>>> user=> (defn ^String  foo [^String s] (.substring s 0 (.length s)))
>>> #'user/foo
>>> user=> (.length (foo "jim"))
>>> 3
>>>
>>>
>>> it worked both times didn't it?
>>>
>>> Jim
>>>
>>>
>>>
>>>
>>>
>>> On 17/06/13 17:59, Ambrose Bonnaire-Sergeant wrote:
>>>
>>> After some investigation, the before-the-arglist syntax only seems
>>> useful for defining fn's that return primitive types.
>>> They don't seem to help resolve reflection calls.
>>>
>>>  (require '[clojure.tools.analyzer :refer [ast]])
>>>
>>>  ; this creates a double-emitting fn
>>>
>>>  (ast (fn (^double [^double a] a)))
>>> ; =>
>>>  ;{:op :fn-expr,
>>> ; ...
>>> ; :methods
>>>  ; ({:op :fn-method,
>>> ;   ...
>>> ;   :arg-types (#<Type Ljava/lang/Object;>),
>>>  ;   :return-type #<Type D>}),   ;double return type here
>>> ;  ...
>>> ; :tag nil}  ; no tag
>>>
>>>   ; this creates a regular old fn
>>>
>>>  (ast (fn (^String [a] 1)))
>>> ; =>
>>> ;{:op :fn-expr,
>>>   ; ...
>>> ; ({:op :fn-method,
>>> ;   ...
>>> ;   :arg-types (#<Type Ljava/lang/Object;>),
>>> ;   :return-type #<Type Ljava/lang/Object;>}),  ;object return type
>>> ; ...
>>> ; :tag nil}  ; no tag
>>>
>>>  ; this creates a String-hinted fn
>>>
>>>   (ast ^String (fn a [a] 1))
>>>  ;{:op :meta,
>>> ; ...
>>>  ; :expr
>>> ; {:op :fn-expr,
>>> ;  ...
>>> ;  :methods
>>> ;  ({:op :fn-method,
>>> ;    :arg-types (#<Type Ljava/lang/Object;>),
>>>  ;    :return-type #<Type Ljava/lang/Object;>}),
>>> ;  ...
>>> ;  :tag String}}
>>>
>>>  I don't see where before-the-arglist is useful outside of primitive
>>> fns.
>>>
>>>  Thanks,
>>> Ambrose
>>>
>>> On Mon, Jun 17, 2013 at 7:59 PM, Jim - FooBar(); 
>>> <jimpil1...@gmail.com>wrote:
>>>
>>>> Hi all,
>>>>
>>>> It seems to me that return type-hints can go either right after "defn",
>>>> or after the doc-string. I generally, put the return type-hints right
>>>> before the argument vector and it seems to get rid of reflection. However,
>>>> I just had a look at core.contrib.strutils2 and the author(s) put the type
>>>> hint right after 'defn' (before the var about to be defined) and again it
>>>> gets rid of reflection! Which one is it? both are acceptable?
>>>>
>>>> thanks in advance,
>>>>
>>>> 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 unsubscribe from this group and stop receiving emails from it, send
>>>> an email to clojure+unsubscr...@googlegroups.com.
>>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>>
>>>>
>>>>
>>>  --
>>> --
>>> 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 unsubscribe from this group and stop receiving emails from it, send
>>> an email to clojure+unsubscr...@googlegroups.com.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>>>
>>>
>>>
>>>    --
>>> --
>>> 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 unsubscribe from this group and stop receiving emails from it, send
>>> an email to clojure+unsubscr...@googlegroups.com.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>>>
>>>
>>
>>
>  --
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
>
>  --
> --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to