Objects and Closures
Timely observations by Steve Dekorte:
A language that uses objects on the bottom can use them for everything, but a language with closures on the bottom needs other types or “atoms” for things like numbers, lists, etc and then scatter around functions for operating on those other types. If you care about simplicity, consistency and organization, this is a big difference.
Beginning with Nu-0.2.0, Nu includes full support for Lisp-style closures.
(function make-accumulator (n)
(do (i) (set n (+ n i))))
Paul and other Lispers are dismissive of object-oriented programming. I think they are right when they point out that there’s a lot of junk in most object-oriented systems. But part of the argument seems to be that since objects can be implemented with closures, closures are the superior feature.
That cuts both ways: closures can be implemented with objects. In a followup piece, Paul showed examples of this from a variety of languages. Read them and see many embarrassing contortions (C++, Haskell, Erlang, Python, ...).
To be fair, we should also look at the contortions required to implement objects with closures. But for now, let’s waive that objection and consider Steve’s deeper point: you have to build your language out of something. So why not build it out of objects?
Nu is a Lisp where everything is an object. If you want to build higher-level object systems out of closures, you can, but at the bottom, you’ll find the consistency, simplicity, and organization that I came to appreciate using Ruby.
Comments (0) post a reply