Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Retrieve function name

 [1/6] from: peter::carlsson::space::se at: 24-Oct-2001 7:55


Hello! 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. Best regards, Peter Carlsson ---------------------------------------------------------------- Peter Carlsson Tel: +46 31 735 45 26 Saab Ericsson Space AB Fax: +46 31 735 40 00 S-405 15 Göteborg Email: [peter--carlsson--space--se] SWEDEN URL: http://www.space.se

 [2/6] from: greggirwin:mindspring at: 24-Oct-2001 11:07


Hi Peter, << 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. >> Check out the recent ML discussion with the topic "accessing your own function signature / context" --Gregg

 [3/6] from: joel:neely:fedex at: 24-Oct-2001 13:35


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! -jn- -- This sentence contradicts itself -- no actually it doesn't. -- Doug Hofstadter joel<dot>neely<at>fedex<dot>com

 [4/6] from: wonko:algonet:se at: 24-Oct-2001 21:43


At 13:35 2001-10-24 -0500, you wrote:
>Hi, Peter, >Peter Carlsson wrote:
<<quoted lines omitted: 31>>
>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

 [5/6] from: al:bri:xtra at: 25-Oct-2001 9:20


> Now I have to explicit write the name for every function. What I would > like is something like:
<<quoted lines omitted: 3>>
> profiler rejoin [ "< " :name-of-function ] > ]
Would something like this help?
>> profiler: func ['f [word!]][
[ print [">" f] [ probe get f [ print ["<" f] [ ]
>> profiler transpose > transpose
func [ "Transposes a Matrix's rows and columns." [catch] Matrix [block!] "The Matrix." /local Rows Columns Transposed][ throw-on-error [ Rows: length? Matrix Columns: length? Matrix/1 Transposed: array reduce [Columns Rows] repeat Row Rows [ repeat Column Columns [ poke pick Transposed Column Row pick pick Matrix Row Column ] ] Transposed ] ] < transpose I hope that helps! Andrew Martin ICQ: 26227169 http://valley.150m.com/

 [6/6] from: peter:carlsson:space:se at: 25-Oct-2001 10:45


At 00:01 2001-10-25 +0200, you wrote: Hello Andrew!
>Would something like this help? > >> profiler: func ['f [word!]][
<<quoted lines omitted: 3>>
>[ ] > >> profiler transpose
I will try this as soon as soon as I have the time. But, my first reaction is that it is not within the profiler function but from the calling function that I need to retreive the name. So unfortunately this is not what I requested. My solution (to explicit write the function name) works but it would be a lot more convenient if what I request would work.
>I hope that helps!
Thanks for ideas! Best regards, Peter Carlsson ---------------------------------------------------------------- Peter Carlsson Tel: +46 31 735 45 26 Saab Ericsson Space AB Fax: +46 31 735 40 00 S-405 15 Göteborg Email: [peter--carlsson--space--se] SWEDEN URL: http://www.space.se

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted