[REBOL] Re: Retrieve function name
From: wonko:algonet:se at: 24-Oct-2001 21:43
At 13:35 2001-10-24 -0500, you wrote:
>Hi, Peter,
>
>Peter Carlsson wrote:
> >
> > Is it possible to retrieve the name of the function from
> > within the function itself? I would appreciate a little
> > example if that is possible.
> >
>
>Can you add more detail about what you need to do? The
>reason for my dumb question is that functions don't really
>have names; one can have anonymous functions, and one can
>have many words bound to the same function as their value.
>
>For example,
>
> >> do func [x] [x * x] 3
> == 9
>
>which had no name, or
>
> >> smallpowers: reduce [
> [ func [x] [x]
> [ func [x] [x * x]
> [ func [x] [x * x * x]
> [ func [x] [x * x * x * x]
> [ ]
> == [func [x][x] func [x][x * x] func [x][x * x * x]
> func [x][x * x * x * x]]
>
>which don't have "normal" names, but have accessible references
>
> >> smallpowers/3 5
> == 125
>
>and, finally,
>
> >> cube: third smallpowers
> >> to-the-third: third smallpowers
> >> cube 2
> == 8
> >> to-the-third 2
> == 8
>
>which now has multiple "names" (sort of).
>
>HTH!
Hello Joel!
Maybe you remember that I yesterday asked about a profiler for REBOL?
I was told that there was one but it seems that it needed REBOL/Core/Pro.
So, I thought I should write my own simple profiler.
My first try looks like:
first-function: func [] [
profiler "> first-profiler"
do som stuff here...
profiler "< first-profiler"
]
The profiler function is then responsible for calculating the time it
takes from first profiler call to the second and also count how many
times the function is called.
This works pretty well, except that parent calls will also include
the time within child functions.
Back to my question...
Now I have to explicit write the name for every function. What I would
like is something like:
first-function: func [] [
profiler rejoin [ "> " :name-of-function ]
do som stuff here...
profiler rejoin [ "< " :name-of-function ]
]
Hope this explanation clarify the problem.
Best regards,
Peter Carlsson