Re: Closures versus objects
"Matt Hellige" <[email protected]>
| Newsgroups | gmane.comp.lang.lightweight |
|---|---|
| Message-ID | <[email protected]> |
On 2/16/07, Joe Marshall <[email protected]> wrote: > But Ruby syntax has a major disadvantage! Suppose you wanted to late-bind the > method name? In Scheme you'd do this: > > (let ((method (select-method len first last))) > (method "abcd")) > > but you can't bind the name of a method identifier in Ruby: > > method = select-method (len, first, last) > s = "abcd" > s.method > > won't work. To be fair, the ease of this kind of thing is usually considered a major advantage of Python, Ruby and friends: method = "length" s = "abcd" s.send(method) so the syntax is a bit different, but I'm not sure that's a bad thing, in this case. It's clear to me that literal method names (length) and variables holding method names (method) should appear different in code. It's also clear to me that calling literal method names is so overwhelmingly the norm that there should be convenient syntax for it. It seems to me that Ruby and ilk find a good balance here. Matt