stevan / p5-mop-redux

A(nother) MOP for Perl 5
139 stars 36 forks source link

Twigil exclamation mark ! #77

Closed yuki-kimoto closed 11 years ago

yuki-kimoto commented 11 years ago

I think twigil exclamation mark ! is a little difficult to read.

In Perl, ! mean "deny". And ! is often used.

if (!$!title) {

}

What about other mark?

if (!$:title) {

}
stevan commented 11 years ago

We are following what Perl 6 does here. Also I don't think that $:foo could be a valid twigil.

yuki-kimoto commented 11 years ago

p5-mop is Perl5 project, not Perl6. I don't understand the meaning that "We are following what Perl 6 does here".

stevan commented 11 years ago

Yuki - the idea is to keep as much compatibility with Perl 6 as possible.

yuki-kimoto commented 11 years ago

OK.

By the way, Dose twigil work well in Perl5? For example, Dose the following code work well?

"$!title"

$! is special variable. How to distinguish these cases?

stevan commented 11 years ago

Right now the twigil module is a bit of a hack with the parser, it basically finds $! and then looks ahead to see if there is a bareword after it, if there is, it interprets it as a twigil. If it becomes part of the core, then it will most certainly become a proper part of the parser.

yuki-kimoto commented 11 years ago

If it don't work in lexical scope, backward compatible is broken. The change maybe denied from core team. Can twigil work in only lexical scope?

stevan commented 11 years ago

Yes, it works in lexical scope (as well as our and state scope). If the change is denied by the core team we will go back to regular variables ($foo as opposed to $!foo).

yuki-kimoto commented 11 years ago

If attribute foo is private variable, we can also use the name $_foo to prevent crash variable names. If attribute name crash lexical variable, we can use accessor.

has $x is rw;
has $_y;
method foo {

   my $x;
   my $y;
   if ($x eq $self->x) {

   }

    if ($_y eq $y) {

    }
}

I think even if twigil is denied, mop don't have big trouble. And you can also think twigil as next step of mop.

stevan commented 11 years ago

Yes, these are the techniques I used when I ported Plack, but honestly they are not nearly as nice as the twigil.