Lambda the Ultimate

inactiveTopic Apocalypse 12 is out
started 4/16/2004; 6:57:53 PM - last post 4/19/2004; 5:14:21 PM
Keith Devens - Apocalypse 12 is out  blueArrow
4/16/2004; 6:57:53 PM (reads: 562, responses: 17)
Apocalypse 12 is out on Perl.com, and it's enormous! I've been looking forward to this - it's all about Perl 6's OO.

Ehud Lamm - Re: Apocalypse 12 is out  blueArrow
4/17/2004; 5:44:05 AM (reads: 398, responses: 7)
Thanks for the heads up, this article is quite amusing....

I haven't read it carefully yet so I won't go into technical details, but here's one amusing bit.

Of course, the really funny thing is that if you go across a language barrier like that, Perl might just decide to emulate the inheritance with delegation anyway. But that should be transparent to you. And if two languages manage to unify their object models within the Parrot engine, you don't want to suddenly have to rewrite your roles and classes.

And the really, really funny thing is that Parrot implements roles internally with a funny form of multiple inheritance anyway...

Ain't abstraction wonderful.

It seems that the most interesting sections are Dispatch Mechanisms and Class Composition with Roles

andrew cooke - Re: Apocalypse 12 is out  blueArrow
4/17/2004; 5:58:25 AM (reads: 411, responses: 6)
i read that same bit and wondered whether it might not be easier to program parrot directly in whatever intermediate language it uses, rather than use perl (only half-joking here).

is prototype-based oo supported by the way perl does things anyway? of the various words i searched for, prototype got surprisingly few hits.

Keith Devens - Re: Apocalypse 12 is out  blueArrow
4/17/2004; 3:52:06 PM (reads: 386, responses: 3)
That's actually one of the first things I did (search for "prototype"). Perl 6 uses a metaclass scheme. Here're some bits where he writes about the relation of classes to metaclasses:

As in Perl 5, a class is still "just a funny package", structurally speaking. Syntactically, however, a class is now distinct from a package or a module. And the body of a class definition now runs in the context of a metaclass, which is just a way of saying that it has a metaclass instance as its (undeclared) invocant. (An "invocant" is what we call the object or class on behalf of which a method is being called.) Hence class definitions, though apparently declarative, are also executing code to build the class definition, and the various declarations within the class are also running bits of code. By convention classes will use a standard metaclass, but that's just convention. (A very strong convention, we hope.)

Classes may also be used as objects in their own right, as instances of a metaclass, the class MetaClass by default. When you declare class Dog, you're actually calling a metaclass class method that constructs a metaclass instance (i.e., the Dog class) and then calls the associated closure (i.e., the body of the class) as a method on the instance. (With a little grammatical magic thrown in so that Dog isn't considered a bareword.)

The class Dog is an instance of the class MetaClass, but it's also an instance of the type Class when you're thinking of it as a dispatcher. That is, a class object is really allomorphic. If you treat one as an instance of Class, it behaves as if it were the user's view of the class, and the user thinks the class is there only to dispatch to the user's own class and instance methods. If, however, you treat the object as an instance of MetaClass, you get access to all its metaclass methods rather than the user-defined methods. Another way to look at it is that the metaclass object is a separate object that manages the class object. In any event, you can get from the ordinary class object to its corresponding metaclass object via the .meta method, which every object supports.

Sorry to quote so much of it. But, when this came out, one of the first things I wondered is how much Perl 6's OO would be based on prototypes. I don't have a good handle on how having metaclasses is different than having an object system based on prototypes. If someone would like to elaborate on this I'd appreciate it.

Ehud Lamm - Re: Apocalypse 12 is out  blueArrow
4/18/2004; 5:58:49 AM (reads: 356, responses: 0)
I don't have a good handle on how having metaclasses is different than having an object system based on prototypes.

Why are these similar?

Keith Devens - Re: Apocalypse 12 is out  blueArrow
4/18/2004; 11:44:33 AM (reads: 335, responses: 3)
In Perl 6's system, classes are objects (instances of MetaClass), rather than being simply declarative as they are in C++ for instance. In a prototype object system, you make new objects not by instantiating a class that's defined statically, but by making copies of an existing object. So, both treat classes themselves as objects and let you modify the behavior of objects by modifying their parent objects[1]. Though, I may be equivocating on "parent".

To be honest, I don't really grok how metaclasses work. But, if your classes are objects, how is that different than having a class be considered a prototype that its objects are copied from? Or, are having metaclasses and having a prototype-based object system orthogonal to each other?

I apologize if I'm just wasting your time with my ignorance. If I'm just way off base, please say so and I'll go off and find things to read until I get it.

[1] I watched a video demonstration of the Self system a while ago and they had objects dynamically change behavior based on changes made to their parent classes. Though, I'm not sure Perl 6's scheme will be this dynamic.

Ehud Lamm - Re: Apocalypse 12 is out  blueArrow
4/18/2004; 12:20:49 PM (reads: 320, responses: 0)
Think about behaviour: If metaclasses exist (i.e., reified as runtime objects) you can use them to control the way classes behave. Classes are simply object factories, so you'd be able to control allocation, initialization etc. Things get a little more tricky (think about who dispatching) but that's the basic idea.

Some LtU linls: #1, #2 (Python tutorials, Mertz); ST's Behavior

Please keep asking. These are confusing ideas...

Keith Devens - Re: Apocalypse 12 is out  blueArrow
4/18/2004; 12:39:53 PM (reads: 318, responses: 0)
Thanks Ehud. I appreciate the links. (unfortunately, that "Behavior of Behavior" PDF from the last link is down... I hope just temporarily).

andrew cooke - Re: Apocalypse 12 is out  blueArrow
4/18/2004; 12:45:21 PM (reads: 317, responses: 0)
as far as i understand things, a metaclass is code that constructs a class (or the class of an instance that constructs a class), not a template (so there's no reason it should be a class, particularly - could be a function - which might be less misleading if you were thinking it worked like a prototype).

on the other hand, since you have metaclasses (and presumably introspection) you can probably write a metaclass that makes a class by copying from another.

however, i don't know if that's how prototype based systems work. for example, presumably you wouldn't copy methods, but only pointers to them. i don't know what should happen if you modify a method in one instance...

andrew cooke - Re: Apocalypse 12 is out  blueArrow
4/18/2004; 1:38:30 PM (reads: 321, responses: 0)
I apologize if I'm just wasting your time with my ignorance

if i said that every time i posted we'd never get anywhere ;o)

Keith Devens - Re: Apocalypse 12 is out  blueArrow
4/18/2004; 5:42:44 PM (reads: 312, responses: 0)
however, i don't know if that's how prototype based systems work. for example, presumably you wouldn't copy methods, but only pointers to them.

I think this is a good time to link to that Self video I mentioned. A Self object has slots that contain methods or data. If a method call is attempted on an object, it dynamically dispatches to each of its parents (which dispatches to *its* parents if not found, and so on) looking for the method with the right name. If you create a method on an instance that has the same name as an inherited method of its parent, that method is simply found first in the search.

If the method is defined in an instance that you make copies from, the method itself is copied. If you change the method in one object it doesn't affect the other.

That Self video is very cool, btw. If you haven't seen it yet, I'd really recommend checking it out.

Larry Wall - Re: Apocalypse 12 is out  blueArrow
4/19/2004; 9:09:35 AM (reads: 250, responses: 0)
Prototype based behavior would be handled with wildcard delegation in Perl 6.

Chris Rathman - Re: Apocalypse 12 is out  blueArrow
4/19/2004; 12:08:39 PM (reads: 220, responses: 1)
I'm assuming that the changes won't break old code (at least reasonably well behaved code). I see some stuff about versioning, so is this how the backward compatibility will be salvaged? Lot's of time invested in CPAN.

I also wonder if the Perl culture of TIMTOWTDI (or whatever that acronym is), allows the language designers greater flexibility?

Larry Wall - Re: Apocalypse 12 is out  blueArrow
4/19/2004; 3:48:07 PM (reads: 199, responses: 0)
You haven't been paying attention. The whole point of Perl 6 is to break old code. Migration will be accomplished primarily by translation, though we won't require people to translate everything all at once. So we allow calls back and forth between Perl 5 and Perl 6. But Perl 6 modules are distinguished from their corresponding Perl 5 module by more than just version. The full name of a Perl 6 module includes the name of the author, one way or another.

As for TMTOWTDI, it's primarily intended to make things easier for the user of the language. It generally makes things harder for the language designer, in my experience, but is nevertheless worth it.

Chris Rathman - Re: Apocalypse 12 is out  blueArrow
4/19/2004; 5:14:21 PM (reads: 203, responses: 0)
You haven't been paying attention.
Awaiting an updated Camel book to focus my attention. :-)

Speaking of which, after the dust settles, it'd be nice to see a "Design & Evolution of Perl" type book down the road (ala Bjarne). But I guess the Onion tracts kind of give us a real-time glimpse along those lines.

Aaron Sherman - Re: Apocalypse 12 is out  blueArrow
4/22/2004; 1:37:15 PM (reads: 111, responses: 1)
"But, when this came out, one of the first things I wondered is how much Perl 6's OO would be based on prototypes. I don't have a good handle on how having metaclasses is different than having an object system based on prototypes. If someone would like to elaborate on this I'd appreciate it."

Sure.

Perl 6's OO is a sort of hybridization of what P5 had, what other high level languages in Perl's space like Ruby and Python have and something darn-near prototypes.

So, while it's similar I would say that there are significant deviations. For starters, there *is* such a thing as a declaration, it's just that the declaration is represented by an object of type Class, which also has properties (roles in P6 lingo) of type MetaClass. This object is *not* a prototype from which your objects will be constructed, but it is a blueprint, and it will be accessible from your object.

Why is that distinction interesting? Well, for starters, you cannot (as far as I've seen) derive from an object in P6. It would instead be a two-step process (gain access to an object's metaclass, then derive from that). There is a strong "has" relationship between an object and its class, not "is" as in prototyping languages that I have seen.

I'm not making any value judgements here, just laying out what I understand of A12.

As for the comments about not wanting to program in P6 because it sounds too scary (my words), I think everyone is missing a fundamental point here. A12 is a design document, not a reference manual. As such it is covering everything necessary to implement the language. There may be pieces of A12 that are hidden under the hood, or which standard "strict" or "warning" modes produce errors or warnings on for general use. They are there to provide the mechanisms by which the language will be implemented and extended.

For the most part, I don't see P6 programmers using $object.metaclass or altering the delegation model, but certainly both of those things will be required in order to implement the autoloader or dynaloader in P6 itself....

Hope this helps!

Ehud Lamm - Re: Apocalypse 12 is out  blueArrow
4/22/2004; 2:01:39 PM (reads: 107, responses: 0)
As for the comments about not wanting to program in P6 because it sounds too scary (my words), I think everyone is missing a fundamental point here. A12 is a design document, not a reference manual.

Thanks for the clarification. Never seen a design doc before...

(For the sarcasm-impaired: the last sentence was the joke, just like the remark about not wanting to program P6...)

Aaron Sherman - Re: Apocalypse 12 is out  blueArrow
4/22/2004; 2:02:21 PM (reads: 105, responses: 0)
"wondered whether it might not be easier to program parrot directly in whatever intermediate language it uses, rather than use perl"

1. Easier is in the eye of the programmer ;-)

2. You should check out the Parrot sources and give it a whirl. Great docs, though somewhat disorganized.

3. You can use Parrot today (with some caveats), but Perl 6 will not be out for at LEAST another year... you do the math. :)

P6 will be, I think, a very nice language, but if you want to play with some nice features that P6 promises, yeah Parrot is the way to go right now (and the Perl6::* modules for Perl5).