CTM on OO

jjore on 2007-07-09T04:49:30

I started reading Concepts, Techniques, and Models of Computer Programming because it spends a bunch of time discussing concurrency and constraint programming. I was wowwed this weekend when I got to the OO section. I didn't expect anything particularly interesting from this part. Not so.

It solved the allomorphism problem as a "oh, by the way." I just was totally blindsided by it. You can get confused method resolution when your method head is just a string or other atom. This is what happens in perl and just about every OO language I'm familiar with. In the book's pet language, your method head is often a string but isn't required to be. If the head is a "name," an unforgeable identity then it can only be invoked by call sites that have been given the method head.

I suppose this is just a side effect of having first class classes and methods. If you haven't given your method object to a call site, it can't be invoked. This is obvious, right? Still... it's neat and unperly.

Parrot's pdd 15 says methods are invoked by name. Classes, methods, and objects are PMCs though. I can get first class methods in Parrot, right?


First Class Methods in Parrot

chromatic on 2007-07-09T06:19:06

I can get first class methods in Parrot, right?

Yes, but be sure that when you invoke them, you have a valid invocant in the appropriate place. (I thought it was P5, but it looks as if that place has moved.)

Ambiguous Method Resolution?

Ovid on 2007-07-09T08:25:31

You can get confused method resolution when your method head is just a string or other atom. This is what happens in perl and just about every OO language I'm familiar with.

I'm just guessing as to your meaning, but are you referring to the following problem?

  if $obj.can('fribble') {
    my BadPoet $jibbet = $obj.fribble('repeatedly');
  }

Just because $obj.can('fribble') doesn't mean that fribble() accepts a string or returns a BadPoet instance. I asked about this on the P6 language list in late April/early May and a variety of solutions were suggested, including this, by Larry:

    if $obj.&fribble:(Str --> BadPoet) { ... }

Or did you mean something totally different?

Re:Ambiguous Method Resolution?

slanning on 2007-07-09T09:44:52

if $obj.&fribble:(Str --> BadPoet) { ... }

Is that, *gulp*, really Perl6?

I'm just.... Is the point to shock people into not using it? I really need to learn Python or something.

Re:Ambiguous Method Resolution?

Ovid on 2007-07-09T09:49:15

No, that was just one suggestion. The problem is that many popular OO programming languages don't really make introspection terribly easy when it comes to determining method dispatch.

If you can suggest a cleaner, unambiguous syntax which solves the same problem, I'm sure that Perl 6 folk would welcome it. It's also worth pointing out that this isn't something you'd be using a huge amount. Generally it would be shielded from users of your code.

Re:Ambiguous Method Resolution?

Aristotle on 2007-07-09T14:23:05

this isn’t something you’d be using a huge amount. Generally it would be shielded from users of your code.

Famous last words…

Re:Ambiguous Method Resolution?

chromatic on 2007-07-09T18:14:17

Is the point to shock people into not using it?

I could loan my four year old nephew Gravity's Rainbow, but I think I'll wait until he's a better reader. The fact that as a thirty-something I had to read The Crying of Lot 49 first doesn't put me off from English altogether.

Re:Ambiguous Method Resolution?

slanning on 2007-07-10T08:03:01

Condescending as always. If your point is that it's confusing to read something when you don't know the language - I know Perl. If Perl6 is so different that I can no longer comprehend it, then it could be called something else like Emerald or Jade or simply Rock.

Re:Ambiguous Method Resolution?

chromatic on 2007-07-10T17:12:37

If Perl6 is so different that I can no longer comprehend it, then it could be called something else like Emerald or Jade or simply Rock.

None of the goals of Perl 6 were "Perl 5 programmers should be able to understand perfectly all code written in Perl 6 without learning anything new."

Heck, I know Perl 5 pretty well by now and there's plenty of code I don't understand immediately.

Re:Ambiguous Method Resolution?

Aristotle on 2007-07-10T19:50:48

If Perl6 is so different that I can no longer comprehend it

How do you change Perl 5 only so much that it requires no learning to comprehend the new features?

Re:Ambiguous Method Resolution?

jjore on 2007-07-09T15:50:50

To my eyes "

fribble:(Str --> BadPoet)
" ought to be a pattern. It isn't entirely clear what all the components you'd like to express things about, perhaps just everything that fits into a method head. In Perl 5, this is just its name. In Perl 6, you've also got the type signature for what the method accepts and returns.

Is there more data available to match against? Perhaps methods can also be "branded" by having something like "tags" attached to it. Imagine a tag swarm for your methods, *grin*!