Aaron wrote:

   > Several questions come up.
   >
   >    * If $.foo is "like" the Perl5 $self->{foo},

Except (as I'm sure you know) that Perl 6 class instantiations aren't
hashes, and their attributes aren't hash entries.


   >      how do I do the Perl5 $self->foo?

.foo()


   >    * Is "foo" in this context an auto-quoted key, or an
   >      actual entry in the namespace? I ask because I'm
   >      trying to find out how this interacts with Perl's
   >      (un)reserved words.
   >
   >            print $.if 1; # comes to mind

This is:

         print ${'.if'} 1;      # syntax error

not:

         print $. if 1;



   >    * Do you always have to use parens now for method invocation?

No.


   > >         class Demo {
   > >
   > >             my $foo;
   > >
   > >             method foo is lvalue {
   > >                 return $foo;
   > >             }
   > >         }
   >
   > Hmmm... I'm trying really hard to get my head 'round this.
   >
   > So, a class is a scope which creates a new closure every time it's
   > instantiated?

That's the effect, yes. Though probably not the implementation.

I prefer to think of it like this: a class is a template for the lexical
scope in which each object lives and moves and has its being.


   > This is intriguing. Certainly it removes any question
   > of unauthorized member access.

Yep! ;-)


   > I'm quite curious to see what the initialization syntax will be like.

        class Demo {
                my $foo;
                my $bar;

                method INIT ( $fooval, $barval) {
                        $foo = $fooval;
                        $bar = $barval;
                }

                method foo is lvalue {
                        return $foo;
                }
        }


        my $demo = Demo->new(bar=>'sheep', foo=>'fighter');



> Will there be a special initialization method, or will we have something
> like a BEGIN block inside the class?

The former. The name is TBA though, since it's probably too confusing
to have INIT blocks and INIT initializers with no real relationship
between them.


> How would this play with constants?


        class Demo {
                my $threshold is const = 100;

                ...

        }


> Seriously, it would be nice to have a BNF somewhere, even if it changed
> every day, and had a few "alternates" sections... I'd be interested
> in starting this if no one else has their heart set on doing it. Perhaps
> I could get it into a CVS archive so that we can all edit it on our
> own branches.
>
> I'm not proposing anything super-useful for actually cranking out
> Perl6's perly.y, but just a high-level view of the operators and
> essential syntax.

I'm planning to write a Perl6::Classes module as a proof-of-concept to
accompany my proposal.

Damian

Reply via email to