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

[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 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
>> 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