On Sat, May 27, 2006 at 07:54:47PM +0900, Robert K. wrote:
I’d have guessed that Smalltalk does this. Thanks, Jeremy for the
confirmation. Btw, just out of curiosity: what about common lisp?
Does CLOS also contain a rich set of abstract data types?
Foremost, lisp does have nested lists. If you look closer, you’ll find
lists are made up of cons-boxes, value.pointer, in a singly linked
list style. So (1 2 3) is really (1.(2.(3.nil))).
Common lisp also has a native array with efficient indexed access
operations, and native strings for collections of characters (or maybe
these are arrays too).
Often, simple data structures like sets are just made up with a few
functions that treat lists as sets. Or other functions that treat
“attribute lists” (symbol.value pairs in a list) as simple hashes. A
list is a natural stack too. That’s all quite akin to ruby’s duck
typing. For small amounts of data this just works. For larger amounts,
more elaborate functions that manage deeper nested lists and/or arrays
will do, in a similiar way ruby often nests Array and Hash.
I don’t know what CLOS adds to this mix beside classes which are just
dumb structs with multiple inheritance. The limited amount of CLOS
code I’ve ever seen did not need to use additional collection classes,
but rather kept things simple and used lists and arrays.
To disgress somewhat, CLOS’ power lies in generic functions, aka
methods, forming their own hierarchy with a powerful and customizable
generic function dispatch on all function arguments. For example, you
can specify for method error-p to be called for some object’s class
and all parent classes that implement it, and their results to be
or-ed, without having each of them call the aequivalent of ruby’s
super. Generic functions don’t look nor behave syntactically different
than plain old lisp functions. Compare to Ruby (and Smalltalk, Java,
C++), where method dispatch always depends on the first argument’s
class (which is implicitly self), and the first method implementation
in a search upwards the class hierarchy will be executed.
Finely crafted CLOS code looks awesome in a rails-like way. But I am
not sure if I myself could ever produce such, or just a big mess. I
feel comfortable enough in Ruby’s slightly more restrictive OO