From: Mathieu Bouchard Date: 2001-08-08T17:40:54+09:00 Subject: [ruby-talk:19362] Re: Perl/Python/Ruby common backend (Parrot, can Ruby play too?) On Wed, 8 Aug 2001, Ned Konz wrote: > On Tuesday 07 August 2001 10:37 pm, Mathieu wrote: > > Ruby has this thing called "mixins" that afaik is not in Python (unless > > I don't understand what you mean. In Perl, the method lookup is first in the > current class, and then depth-first through the @ISA (parent) list. Calling, > say, $self->SUPER::method merely skips the current class (and only works if although method lookup is depth-first, when you call SUPER it does it in the sub-hierarchy of __PACKAGE__ only, and so never backtracks past the point where SUPER was called. > dynamically as I've wanted it to). I could see wanting to do a breadth-first I'm not talking about breadth-first and I wouldn't see the advantage of it. > > Ruby also has metaclasses (singleton classes that inherit from the Class > > class). Perl doesn't even have Class objects. > We've (Toby Everett and I) added a reflection layer to Perl, at least. Not sure what you mean. In Perl you can access the symbol table of a package fairly easily, and then you can access @ISA (the superclass list) even more easily. That's about the same amount of reflection as you have in Ruby. > And added the ability to smoothly make singleton classes, We did this > for Perl also (see Class::Prototyped). Works fine, actually. You can > inherit from these singleton classes and/or regular classes, and > change the inheritance on the fly. Now this is nice. =) I think I recall Damian briefly presenting it at YAPC-NA-2000. (Or else he presented similar stuff) > > Ruby has closures, which allow to modify existing variables of the > > enclosing binding. For closures there is a special slot "&" in every > > message that allows for the #each{} kind of methods. > Perl has closures, of course. Perl doesn't have the "&" slot in its messages; it only has @_ in which $_[0] is the receiver. > You know, I've been meaning to ask how to do this (change the class of an > object). Is there something akin to Smalltalk's "become:" in which two > objects swap identities? That's one way to do this, of course. There isn't, and there could be, although it breaks some assumptions that Ruby code (and especially C code of extensions) may have. > Also, how can one change the superclass of an existing class in Ruby? you can't. You could add this at the C level but you may have to learn Ruby's internal "proxy classes" before (I haven't). It possibly would break also some assumptions. I think though that changing the class of an object and the superclass of a class is of somewhat lesser importance when you have Ruby-style mixins. OTOH they also can be a good complement to Ruby-style mixins, especially if you have Object#unextend and Module#uninclude... matju