p5-MOP syntax improvements

I spent much of the last few days working on some syntactic improvements to the p5-mop. I had originally went with a fairly straightforward method for specifying things like inheritance, role composition, etc. It basically looks like this:

class Foo (extends => 'Bar', with => ['Baz', 'Gorch']) {}

This works well because it is basically just using a simple Perl list to pass in information to the underlying meta-objects. My only issue with this is that everything is a string, which is no different then what we have now using base or @ISA, but I wanted to see if I could improve this a little.

After wrestling with Devel::Declare for a while (yes, I know it is evil, but it is just for the prototype, the real version will not use it), I was able to get the following syntax to work.

class Foo extends Bar with Baz, Gorch {}

I like this because in general I feel it is cleaner and as a bonus saves a bunch of typing of quotes and other symbols (read: reduces "line noise"). The best part about this is that it really just desugars down to the old form, meaning I didn't have to add any complexity to the MOP, only to the syntax parser.

Currently this code resides in a branch as I want to do some more parser stress tests before I put it into master, but so far it is working quite well.

11 Comments

Thank you for continuously updating about this. :)

It's wonderful seeing a p5-mop becoming a reality feature by feature. Who needs reality tv? :)

Exciting! Please keep us posted :D

That second example is nice. Also enjoying the regular updates.

This looks great! I'm very happy that you've returned to this. It's something Perl has needed for a long time and I can't think of anyone more qualified than yourself to do it.

could we name this perl7? ;)
great work!

If you're just prototyping, I wonder if source filters would let you be more experimental with less effort.

Stevan++ this is wonderful work I hope that you get adoption of those features in p5 core and that you don't lose interest on it.

Do you plan to use Devel::Declare in the final version of p5-mop? Part of me thinks that there should be a better way or at least a formalized API to hack into the compiler.

I just wanted to thank you for your work.

Leave a comment

About Stevan Little

user-pic I blog about Perl.