[REBOL] Re: Reflectivity: How a function can know its own name ?
From: rotenca:telvia:it at: 27-Mar-2002 15:13
There are no direct modes, but you could
1) use an hack (look at this thread
http://www.escribe.com/internet/rebol/m18105.html)
2) writing the func to be aware of itself (not of its name), with something
like this:
>> use [self][ext-name: self: func [][print ["mycode is:" mold second
:self]]]
>> ext-name
mycode is: [print ["mycode is:" mold second :self]]
You can do a new func type function with something like:
reflex-func: func [spec body][ use [self] [self: func spec bind body 'self]]
to use in this mode:
>> f: reflex-func [][print mold second :self]
>> f
== [print mold second :self]
or you can use the name 'func itself hidden in a context:
ob: context [func: system/words/func [spec body][ use [self] [self:
system/words/func spec bind body 'self]]]
then:
do bind [
f1: func [][print mold second :self]
f2: func[] [print 7]
] in ob 'self
>> f1
[print mold second :self]
>> f2
7
(i have not tested deeply the code)
---
Ciao
Romano