Re: Don't Laugh - How to Get the Name of an Anonymous Function

2017-10-24 Thread Alex Miller
Just to chime in and second what others have said, functions do not encode 
their name in an accessible way. The best option right now is to use 
clojure.repl/demunge on the class name. 

This is a best-effort function as the transformation from Clojure function 
name to Java class class name is not unambiguously reversible (both - and _ 
become _ in the Java name, so this is a lossy transformation). A related 
ticket is http://dev.clojure.org/jira/browse/CLJ-1278.

On Tuesday, October 24, 2017 at 7:36:56 AM UTC-5, Sean Corfield wrote:
>
> No need to import the compiler. Use clojure.repl/demunge
>
>
>

-- 
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/d/optout.


Re: Don't Laugh - How to Get the Name of an Anonymous Function

2017-10-24 Thread Sean Corfield
No need to import the compiler. Use clojure.repl/demunge

Sean Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/

"Perfection is the enemy of the good."
-- Gustave Flaubert, French realist novelist (1821-1880)
_
From: Ravindra Jaju >
Sent: Tuesday, October 24, 2017 01:51
Subject: Re: Don't Laugh - How to Get the Name of an Anonymous Function
To: clojure >


It's a good start.

You could next import clojure.lang.Compiler and call the static method demunge 
like so on the output "cool_func_BANG_"
(Compiler/demunge "cool_func_BANG_") ; => "cool-func!"

On Tue, Oct 24, 2017 at 11:27 AM, Shantanu Kumar 
> wrote:
Not sure whether you can deterministically recover the exact name at all times, 
but the following can get you started:

(re-matches #".*\$(.*)__.*" (.getName (class (fn cool-func! [] (println 
"hi")

I have altered the name to `cool-func!` on purpose to show where it may break.


Shantanu


On Tuesday, 24 October 2017 10:35:12 UTC+5:30, Nick Mudge wrote:
Let's say I have this anonymous function:

(fn cool [](println "hi"))

How can I extract the name from it?

Obviously the name of the function is stored with the function. How can I get 
to it?



--
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 
toclojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
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 
toclojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


-- 
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/d/optout.


Re: Don't Laugh - How to Get the Name of an Anonymous Function

2017-10-24 Thread Ravindra Jaju
It's a good start.

You could next import clojure.lang.Compiler and call the static method
demunge like so on the output "cool_func_BANG_"
(Compiler/demunge "cool_func_BANG_") ; => "cool-func!"

On Tue, Oct 24, 2017 at 11:27 AM, Shantanu Kumar 
wrote:

> Not sure whether you can deterministically recover the exact name at all
> times, but the following can get you started:
>
> (re-matches #".*\$(.*)__.*" (.getName (class (fn cool-func! [] (println
> "hi")
>
> I have altered the name to `cool-func!` on purpose to show where it may
> break.
>
>
> Shantanu
>
>
> On Tuesday, 24 October 2017 10:35:12 UTC+5:30, Nick Mudge wrote:
>>
>> Let's say I have this anonymous function:
>>
>> (fn cool [] (println "hi"))
>>
>> How can I extract the name from it?
>>
>> Obviously the name of the function is stored with the function. How can I
>> get to it?
>>
>>
>> --
> 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/d/optout.
>

-- 
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/d/optout.


Re: Don't Laugh - How to Get the Name of an Anonymous Function

2017-10-24 Thread Beau Fabry
If I had to guess I'd say the name of the function isn't stored with it

nil
boot.user=> (clojure.reflect/reflect (fn foo [] nil))
{:bases #{clojure.lang.AFunction}, :flags #{:public :final}, :members 
#{#clojure.reflect.Constructor{:name boot.user$eval1530$foo__1531, 
:declaring-class boot.user$eval1530$foo__1531, :parameter-types [], 
:exception-types [], :flags #{:public}} #clojure.reflect.Method{:name 
invoke, :return-type java.lang.Object, :declaring-class 
boot.user$eval1530$foo__1531, :parameter-types [], :exception-types [], 
:flags #{:public


On Monday, October 23, 2017 at 10:57:42 PM UTC-7, Shantanu Kumar wrote:
>
> Not sure whether you can deterministically recover the exact name at all 
> times, but the following can get you started:
>
> (re-matches #".*\$(.*)__.*" (.getName (class (fn cool-func! [] (println 
> "hi")
>
> I have altered the name to `cool-func!` on purpose to show where it may 
> break.
>
>
> Shantanu
>
> On Tuesday, 24 October 2017 10:35:12 UTC+5:30, Nick Mudge wrote:
>>
>> Let's say I have this anonymous function:
>>
>> (fn cool [] (println "hi"))
>>
>> How can I extract the name from it?
>>
>> Obviously the name of the function is stored with the function. How can I 
>> get to it?
>>
>>
>>

-- 
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/d/optout.


Re: Don't Laugh - How to Get the Name of an Anonymous Function

2017-10-23 Thread Shantanu Kumar
Not sure whether you can deterministically recover the exact name at all 
times, but the following can get you started:

(re-matches #".*\$(.*)__.*" (.getName (class (fn cool-func! [] (println 
"hi")

I have altered the name to `cool-func!` on purpose to show where it may 
break.


Shantanu

On Tuesday, 24 October 2017 10:35:12 UTC+5:30, Nick Mudge wrote:
>
> Let's say I have this anonymous function:
>
> (fn cool [] (println "hi"))
>
> How can I extract the name from it?
>
> Obviously the name of the function is stored with the function. How can I 
> get to it?
>
>
>

-- 
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/d/optout.


Don't Laugh - How to Get the Name of an Anonymous Function

2017-10-23 Thread Nick Mudge
Let's say I have this anonymous function:

(fn cool [] (println "hi"))

How can I extract the name from it?

Obviously the name of the function is stored with the function. How can I 
get to it?


-- 
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/d/optout.