Rici Lake wrote:
It is true you can always "not hide" a hidden parameter, in which case it's not a hidden parameter "method" call at all, and it would use the colon operator. But Gary Ng's original question was about renaming the hidden parameter in a *colon-defined* function. In that case 'self' is the only allowed name for the truly hidden parameter.Brian Hagerty wrote:Notice that the "hidden" parameter idiom of colon-functions does not provide another place for you to create a different name for that hidden parameter.Sure it does. Just don't hide it. (See below).
That is very useful, and is always an available dot-function idiom. But that doesn't reflect a purely colon-defined instance-method idiom (where the method is implicitly applied to the caller). That dot syntax defines a more generalized (not specifically OO) functional idiom with an arbitrary object as first argument. The original question was whether the colon-defined function syntax was necessary. Dot-defined function examples add to the case for obviating the need for colon-defined functions.Yes, but I could easily write this: function Account.deposit(foo, v) foo.balancer = foo.balance + v end That sort of thing is often useful: you don't always want to call a function with the table it lives in (sometimes you want to call it with another object in the chain, for example.)
// Brian