From: David King Landrith Date: 2004-04-03T07:44:06+09:00 Subject: Re: Variable names On Apr 2, 2004, at 5:22 PM, Jim Weirich wrote: > > David King Landrith said: > >> Let me restate the question: >> >> Whenever a method is called on an object, one and only one symbol is >> used to represent the object. > > That statement is incorrect. Fair enough. Does this work? Whenever a method is called on an object, one and only one expression or symbol has been resolved to used to represent the object. And so: Is there any way to determine which symbol was representing the expression or symbol at the time that the method was invoked? You'll forgive me if I feel like I'm playing twenty questions here. Perhaps I should be asking: There seems to be some "thing" that the interpreter determines refers to an object, and there can only be one of these per method that is invoked. How would we describe this "thing"? > Simple answer: NO I can see that this is also the answer to the restated question I ask above. Just out of curiosity: At what point does the interpreter discard the expression that it been evaluated to represent the object? > Longer answer: Throw an exception and immediately catch it. Ask the > exception for its backtrace and parse the file and line number from the > backtrace (see ri backtrace for details). Then read the file in > question > and find the line number of the caller function. Then parse the line > of > code and guess at the variable name (if there is one). > > If you always call your type checking method in the form > > var.should_be(ClassName) # or whatever format you use > > then parsing the line of code is not a difficult problem. However, in > the > general case it is quite difficult. ------------------------------------------------------- David King Landrith (w) 617.227.4469x213 (h) 617.696.7133 Life is tough. It's even tougher if you're an idiot. --John Wayne ------------------------------------------------------- public key available upon request