[REBOL] Re: Retrieve function name
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