On Nov 1, 2005, at 7:57 PM, Trans wrote: >> Something tells me that it will be impossible to have an identical >> syntax for all of: >> >> 1) local variable >> 2) 0-argument method invocation >> 3) formal parameters >> 4) 0-argument Proc#call invocation >> > > What do you mean by #3? Other than that why so you see this as > problem? Right now there are some heuristics that allow the ruby parser to decide how to interpret an identifier with no associated arguments. In particular if it matches the name of a formal argument or it has appeared on the left hand side of an assignment, the parser assumes it is a variable. Otherwise it assumes it is a 0-argument method call. Even with these rules we sometimes have to help the parser out by explicitly indicating that it is a method call: self.attribute = value # to avoid creating a local var 'attribute' You are proposing that there be yet another interpretation that combines the behaviour of a variable with the semantics of a 0-argument method call: magic_id gets interpreted as magic_id.method but only if magic_id happens to be a reference to a particular kind of object (an "anonymous method"). Since there doesn't seem to be a syntactical way to spot an identifier with this magic behavior (indeed I believe you are asserting that the power of the proposal comes from the fact that there is *no* syntactical difference), then you are implying some sort of runtime check each and every time the identifier is evaluated. During this evaluation the "magic" occurs. If the identifier actually references a special type of object then there is an implicit call to an predetermined method that results in a previously defined block/ closure being executed. The value yielded by this block "becomes" the value associated with the identifier. In other words, 'magic_id' gets automatically interpreted as: magic_id.call > If a method and a local var can be the same why not annoynous method > with local var name? I'm not sure I'm understanding your use of the term 'anonymous method'. I *think* it is something between a block/closure and a Proc object but it isn't either? Can you explain how it differs from a standard Proc object or is the difference just in the alternative invocation? > The trick is simplly like that of dealing with > blocks --though I realize now some other symbolization will be needed > to differentiate block from passing first-class lambda object. So you are proposing some manner of reifying a block but you don't want to utilize a Proc object but some other new type of object? > I'm > gogin to use Matz notation here for lack of anything else > (interestingly it actually makes some sense as "dereference") Matz notation is just a way of allowing Proc objects to have the same argument passing semantics/syntax as regular methods. It still ends up creating a Proc object and still requires an explicit invocation of Proc#call to execute the associated block. I wrote: >> It is pretty easy to package up define_method and have a very concise >> way to define methods on demand. You replied: > Sure, but this is very weak by comparision. Your using method_missing > for one, and as you say your defining methods into the singleton > space, > not anonymously. I just used method missing to make the *definition* simpler. The resulting invocation syntax is the same regardless of how it is defined. I'm not sure how your method makes anything anonymous. You are just proposing that a specific method be called under certain conditions in the way #to_proc is called on an argument prefixed with & or in the way #to_a is called when the 'splat' operated is used. #to_proc and #to_a aren't anonymous they are just invoked indirectly according to the syntactical rules of the language. Gary Wright