Re: Closures versus objects
"Spencer Schumann" <[email protected]>
| Newsgroups | gmane.comp.lang.lightweight |
|---|---|
| Message-ID | <[email protected]> |
>
> What do you mean by "module system"? Don't C++'s namespaces fit the
> bill?
You've called my bluff. :)
My point, though, is that the namespace control provided by objects
has a lot in common with the namespace control provided by
modules/namespaces. The method dispatch mechanisms provided by
objects take namespace control one step further, which is often very
useful; in Ruby:
s = "abcd"
s.length
a = [1, 2, 3]
a.length
seems much more elegant to me than Scheme's
(let ((s "abcd")
(ls '(1 2 3)))
(string-length s)
(length ls))
Of course, Ruby is not as elegant as Scheme when dealing with
anonymous functions. In Ruby,
{|x| print x}("wrong")
does not work. It has to be done in a more object-oriented manner:
lambda {|x| print x}.call("correct")
- Spencer