2015-02-14 20:21 GMT+01:00 Jony Hudson <jonyepsi...@gmail.com>:

> Unless I'm mistaken, in the output you show:
>
> Exception ERROR: round [:high|:low|:normal] <VALUE>  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 is even better, because it also gives the namespace.

The only 'bad' thing is that the function name comes after the parameters,
but with rewriting the error message and becoming used to it, that should
not be a problem.

Still it could be useful for log messages to get the function name. So I
will look into the other replies.

​


> On Saturday, 14 February 2015 19:09:53 UTC, Cecil Westerhof wrote:
>
>> 2015-02-14 20:03 GMT+01:00 Jony Hudson <jonye...@gmail.com>:
>>
>>> 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 only get:
>>     Exception ERROR: round [:high|:low|:normal] <VALUE>  user/round
>> (repl-startup.clj:30)​
>>
>>
>> ​So it is very useful to have it in the message. ;-)
>>
>>
>> On Saturday, 14 February 2015 18:45:12 UTC, Cecil Westerhof wrote:
>>>
>>>>
>>>>
>>>> 2015-02-14 18:58 GMT+01:00 Jony Hudson <jonye...@gmail.com>:
>>>>
>>>>> 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
>>>>                    :high    (static-fn Math/ceil)
>>>>                    :low     (static-fn Math/floor)
>>>>                    :normal  (static-fn Math/round)
>>>>                    (throw (Exception.
>>>>                            "ERROR: round [:high|:low|:normal]
>>>> <VALUE>")))]
>>>>           (long (fn x)))))
>>>>
>>>> I would like to use the function name in the throw. So that when I
>>>> change the function name to round-long, I do not need to change the throw
>>>> statement, because the name of the function is automatically filled.
>>>>
>>>> ​
>>>>
>>>>
>>>>> 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 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 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.

Reply via email to