Day 104: ./juerd('rocks!')

autrijus on 2005-05-15T17:28:11

Yesterday's punctuation dilemma was fixed by Juerd's nice proposal, namely using ./method as a shorthand for $?SELF.method. Larry calls it terminally cute, and I promptly implemented it in Pugs. Juerd++!

Lots of OO works were done today after I got my laptop back:

  • Inheritance in the form of class Foo is Bar { ... }
  • Private method definition with method :foo { ... }
  • Private method invocation with .:method
  • Private attributes now generates private accessor methods: has $:attr
  • Method interpolation in strings no longer eats up trailing whitespace, e.g. the space in "$obj.hello() World".
  • Parameterised return types is now parsed: method foo returns Hash of Int. I need to ask about how to define such parameterised classes some day...
  • Dereferencing: @{...} and %$foo etc.
  • Finally, I tweaked both wizards.p6 and Locale::KeyedText to use the new syntax.

Much thanks to Stevan, eric256, Darren and chromatic for their early adoption of Pugs OO. I'm happy to see that Locale::KeyedText, the first non-core Perl 5 module ported to Perl 6, is back to ext/ as it works now. Was it really only two months ago? :-)

In other news, in non-embedded mode (such as on Win32, by neccessity), Pugs 6.2.3 spawns one Parrot process for each Perl 6 rule match, which is horribly slow. I've written some more PIR so only one Parrot process is kept now.

Juerd helpfully informed me that the use of infix:<!> to construct none() junctions has been denied, so it's gone from Pugs.

eric256 p6ified life.p6 a bit, but notes that it's still slow. Well, that's what the Prarot compilation backend is for. Speak of which...

...Much to my delight, jhorwitz started hacking Pugs's Parrot codegen in earnest, in order to get mod_pugs working in mod_parrot. Hrm, should we call Pugs/Parrot people lambdabirds? :-)

scook0 and bsb diligently added more Haddock to Prim, Run and Monads modules. skew begins looking into the type tree implementation in Context.hs; hopefully we'll making it a proper directed graph some day to facilitate faster queries.

Stevan started writing tests for Test::Builder, which is dangerously close to fully functional now. He also updated meta_meta_classes.pod with a snippet of discussion between gaal and him, to explain the raison d'être of MetaMetaModels.

The ever-inventive iblech implemented an IRC log to HTML converter in Perl 6. It's not huge -- 300ish lines -- but neatly shows how real world Perl 6 scripts looks like.

Oh, and I submitted two talks to Euro OSCON today: Perl 6 in the Real World, and Learning Haskell. I think I may be a bit overboard on the description for the latter:

What's faster than C++, more concise than Perl, more regular than Python, more flexible than Ruby, more typeful than C#, more robust than Java, and has absolutely nothing in common with PHP? It's Haskell!

Tired of writing unit tests to cover corner cases? Let the computer write them for you with QuickCheck. Find regex-based parsing unmaintainable? Learn how to write a complete parser for Perl 6's grammar in 15 minutes with Parsec. Stuck in deadlocks and race conditions? STM solves all your concurrency woes. XS and SWIG gives you headaches? FFI lets you embed C code quickly and safely.

Haskell is an emerging general-purpose functional language, with unique features that enables extremely rapid development of bug-free, concise and maintainable code. This talk shows how to apply Haskell to day-to-day tasks, tips for integrating it with other languages, and secrets for boosting your productivity by an order of magnitude.

I blame the poignant why the lucky stiff for the influence. :-)


meta-meta-classes

tyan on 2005-05-15T23:16:26

I am not so sure about meta-meta-classes, or at least not that name.

Suppose you have a class Book. You refer to the class as Book, and instances of the class as Books. The same name is used interchangeably without confusion. I think that the same should apply to 'meta-class'. Just as Books are instances of the Book class, I think meta-classes are instances of the meta-class class.

AFAIK The C<Class> class is the meta-class class in perl 6, and meta-classes are instances of C<Class> (what you get when you call the C<meta> method). Maybe it is just me, but I find this far less confusing than introducing the term meta-meta-class.

Given the above, a common question might be: why do we not need meta-meta-classes (a class to describe the C<Class> class)? The answer is that we already have the C<Class> class to describe the C<Class> class. For example:

my $camel_book = Book.new;
my $book_class = $camel_book.meta; # $book_class isa Class
my $class_class = $book_class.meta; # $class_class isa Class

Tom

Re:meta-meta-classes

autrijus on 2005-05-16T06:28:35

Hmm, my understanding is that meta-meta-class does not exist in the language per se; it is a concrete implementation of the metaclass in the compiler or interpreter itself. The user would have no way to directly access or manipulate meta-meta-classes -- it is essentially an "out of system" thing of interest only to language implementors.

Re:meta-meta-classes

stvn on 2005-05-16T21:14:38

Tom,

As Autrijus pointed out, the meta-meta-class is not accesible in the "user space", but a language implementation level object. And the reason we are calling it the meta-meta-class is that it actually is not MetaClass itself, but a MetaClass is an instance of the MetaMetaClass. (it's confusing I know)

To expand on your example: the class Book {} can be called "Book". When you call the meta method on Book, you will get an instance of the Class metaclass for Book, not the Class class.

At some point in any object model there needs to be a cycle. In some models that cycle is at Class. So that Class is itself an instance of Class. However in perl6, we need more things that just classes (Roles), so we would need to push the cycle up one more level so that Class and Role themselves are instances of MetaClass. The MetaMetaClass then comes in as the concrete language implementation level element which the MetaClass is an instance of.

Okay, I think I actually confused myself with that reply, hopefully though I have not made it worse for you. Also please note that the documents have actually been updated with improved nomenclature, you might want to read them again.

Stevan

Re:meta-meta-classes

tyan on 2005-05-17T06:57:08

Hi

Thanks for your detailed response and amazing work getting oo going in pugs. Still twisting my brain into the right shape to fit this stuff in :-)

As you say, calling C<meta> on the C<Book> class yields an instance of the C<Class> metaclass that describes the C<Book> class. My example takes this one step further by calling the C<meta> method on this metaclass and (by my assumption) getting an instance of the C<Class> metaclass that describes the C<Class> class. This is based on my assumption that there is a cycle at the Class level. I would have thought that for any class A, A.meta.meta =:= A.meta.meta.meta. Is this not the case (I am only considering how things work at perl6 level)?

Tom

Re:meta-meta-classes

stvn on 2005-05-17T17:18:08

Tom

Let me first say that we are venturing into unspecced territory here. So anything I say is subject to the whim of @larry.

What said you is correct, with one minor adjustment. You said:

My example takes this one step further by calling the meta method on this metaclass and (by my assumption) getting an instance of the Class metaclass that describes the Class class. This is based on my assumption that there is a cycle at the Class level
But you missed a few metas :)
My example takes this one step further by calling the meta method on this metaclass and (by my assumption) getting an instance of the Class metametaclass that describes the Class metaclass. This is based on my assumption that there is a cycle at the MetaClass level
And yes, A.meta.meta =:= A.meta.meta.meta is true, as is A.meta.meta.meta =:= A.meta.meta.meta.meta and on ad infinitum.

Aren't meta-meta-classes fun :)

Haskell for the Masses?

Greg Buchholz on 2005-05-16T18:04:10

Have you ever given consideration to writing a "Haskell in the Trenches" type of book? I don't know how big the market for such a book would be, but I know it would fill a much needed gap. Most Haskell texts seem to be aimed at the novice/beginning programmer. (e.g they spend chapters describing recursion, and devote only two sentences to using arrays). Haskell seems to have enough libraries and users and existing code out there to have progressed beyond the academic language stage. What is missing is the sharing of experiences from someone who has wrestled with non-trivial "Real World" (TM) problems and won. Here's a starter list of chapters to get you started (I'm still in the process of writing unit tests for the book) ;-)
  1. Coping with Laz[iy]ness
    • The ins and outs of making leak-free programs
  2. Faster, Faster, Faster
    • The art of convincing your compiler to emit decent code
  3. List Overload: Other Data Structures
  4. Secrets of the Type-system Wizards
  5. Monads, Schmonads
  6. Beyond IO
    • Knowing when to use ST and other monads
  7. Template Haskell
  8. Debugging: Living in Sin
    • Not that we'll tell our parents about it, but sometimes its nice
  9. Profiling
  10. FFI
  11. GADT's For The Rest of Us
  12. QuickCheck
  13. Software Transaction Memory

Re:Haskell for the Masses?

autrijus on 2005-05-16T21:51:13

This is an interesting idea, but I cannot consider it until Perl 6's release, i.e. by Christmas...