How do I get name of current object?
[1/2] from: edanaii:cox at: 22-Feb-2003 9:24
If I create an object called "Conscious", how do I get it to know its name? Something like:
>> Concious: Make Object! [ >> Identity: Func  [ >> Get In Self Me >> ] >> ] >> Concious/Identity
== 'Conscious Is there a function that will do this? -- Sincerely, | This is the worst kind of discrimination! The Ed Dana | kind against me! Software Developer | -- Bender, Futurama. 1Ghz Athlon Amiga |
[2/2] from: joel::neely::fedex::com at: 22-Feb-2003 11:37
Hi, Ed, Ed Dana wrote:
> If I create an object called "Conscious", how do I get it to > know its name? >
Objects don't have names. Words do. One could define an object which attempts to find any global words that reference itself, as in: narcissus: make object! [ whoami: func [/local result] [ result: copy  foreach item first system/words [ error? try [ if self = get to-word item [ insert tail result to-word item ] ] ] result ] ] after which
== [narcissus] Of course, the answer isn't necessarily unique!
>> glorp: blodge: spadge: narcissus >> spadge/whoami
== [blodge glorp narcissus spadge] And there doesn't even necessarily exist an answer to that particular question!
>> geefle: make object! [
[ gubbidge: make narcissus  [ speak: func  [gubbidge/whoami] [ ]
>> wugga: reduce [
[ make narcissus  [ make narcissus  [ make narcissus  [ ] == [ make object! [ whoami: func [/local result][ result: copy  foreach item first system/wo...
==  However, this isn't answering your original question, but changing it into another question that may have zero, one, or more answers. AFAICT, REBOL objects don't have names, any more than strings or integers do. -jn-