Re: Name of a function

2015-02-15 Thread Cecil Westerhof
2015-02-14 20:23 GMT+01:00 Steve Miner : > Clojure doesn't give you direct access to the name of the function you're > defining. However, you could use a macro to get that. Here’s one way. > This macro binds the strange symbol %0 to the symbol naming the current > function. > > ;; %0 is bound t

Re: Name of a function

2015-02-14 Thread Cecil Westerhof
2015-02-14 20:21 GMT+01:00 Jony Hudson : > Unless I'm mistaken, in the output you show: > > Exception ERROR: round [:high|:low|:normal] user/round > (repl-startup.clj:30)​ > > > "user/round" is the name of the function, as desired. > ​You are right: I was not looking correctly. :-( In a way it

Re: Name of a function

2015-02-14 Thread Shantanu Kumar
You can probably omit try and throw to achieve the same effect. (let [ste# (aget (.getStackTrace (Exception.)))] ..) Shantanu On Sunday, 15 February 2015 00:58:28 UTC+5:30, Shantanu Kumar wrote: > > See if you can put this to any use (implies no warranty) - applicable to > the JVM only: > > (

Re: Name of a function

2015-02-14 Thread Shantanu Kumar
See if you can put this to any use (implies no warranty) - applicable to the JVM only: (defmacro whereami [] `(try (throw (Exception.)) (catch Exception e# ;; (.printStackTrace e#) ; uncomment this line to inspect stack trace (let [ste# (aget (.getStackTrace e#) 0

Re: Name of a function

2015-02-14 Thread Steve Miner
Clojure doesn't give you direct access to the name of the function you're defining. However, you could use a macro to get that. Here’s one way. This macro binds the strange symbol %0 to the symbol naming the current function. ;; %0 is bound to the function's symbolic name within the function

Re: Name of a function

2015-02-14 Thread Jony Hudson
Unless I'm mistaken, in the output you show: Exception ERROR: round [:high|:low|:normal] user/round (repl-startup.clj:30)​ "user/round" is the name of the function, as desired. Jony On Saturday, 14 February 2015 19:09:53 UTC, Cecil Westerhof wrote: > > 2015-02-14 20:03 GMT+01:00 Jony Huds

Re: Name of a function

2015-02-14 Thread Herwig Hochleitner
Well, one of the many reasons, that clojure is faster than bash is, that during compilation, code is divorced from the original source symbols. That means you can only access information about the original source that you, or some library code you use, put in there for you. Jony stated correctly,

Re: Name of a function

2015-02-14 Thread Cecil Westerhof
2015-02-14 20:03 GMT+01:00 Jony Hudson : > Ah, I see. I don't know how to do that. But, the function name should be > in the stack trace associated with the exception. Is there a particular > reason you also want to put it in the message? > ​Well if I enter in the REPL: (round :dummy 12.4) I

Re: Name of a function

2015-02-14 Thread Jony Hudson
Ah, I see. I don't know how to do that. But, the function name should be in the stack trace associated with the exception. Is there a particular reason you also want to put it in the message? Jony On Saturday, 14 February 2015 18:45:12 UTC, Cecil Westerhof wrote: > > > > 2015-02-14 18:58 GMT+

Re: Name of a function

2015-02-14 Thread Cecil Westerhof
2015-02-14 18:58 GMT+01:00 Jony Hudson : > There might be a neater way, but > > (name (:name (meta (var reduce > > => "reduce" > ​That is not what I meant. I have the following function: (defn round ([x] (round :normal x)) ([mode x] (let [fn (case mode

Re: Name of a function

2015-02-14 Thread Jony Hudson
There might be a neater way, but (name (:name (meta (var reduce => "reduce" Jony On Saturday, 14 February 2015 16:11:48 UTC, Cecil Westerhof wrote: > > In Bash I use the following construct: > printf "${FUNCNAME} needs an expression\n" > > In this way I do not have to change the print

Name of a function

2015-02-14 Thread Cecil Westerhof
In Bash I use the following construct: printf "${FUNCNAME} needs an expression\n" In this way I do not have to change the print statement when the name of the function changes. Is something like this also possible in clojure? -- Cecil Westerhof -- You received this message because you are