> >   meth foo {
> >      $_.meth; # defaults to the invocant
> >      .meth; # operates on $_ which defaults to the invocant
> >      $^.meth;  # is the invocant
> >      $^1.meth; # is the first invocant
> >      $^2.meth; # is the second invocant
>
> I'm starting to get confused at the "need" for all these special
> variables. I vote that we steal from prior art in numerous other
> languages and just auto-set $SELF or $THIS or whatever and call it done.

The problem is that there is no globally safe name to use that uses letters 
only.  Also there is a certain line noise problem (which may not really be a 
problem - but looks like one once we have a more concise alternative):

method foo {
   $SELF.prop = $SELF.meth($SELF.get_foo, $SELF.get_bar);
   $SELF.say("Hello " ~ $SELF.prop);
}

That looks considerably more messy than:

method foo {
   $.prop = .meth(.get_foo, .get_bar);
   .say("Hello " ~ $.prop);
}

Perl syntax is wonderful for being able to say as much as possible without 
losing meaning - assuming you can read perl.  The short identifiers are able 
to express a lot in a little space.

> Having .method assume $SELF is an added nicety, but if it introduces
> added parsing problems then it's hardly worth it.

The .method problem isn't about parsing - it is about knowing which variable 
it applies to.

Current syntax would do:

method foo ($self:) {
   return grep { $self.is_ok( .value ) } $self.info_pairs;
   # .value called on the topic $_
}

Proposed syntax previous to this thread

method foo {
   return grep { .is_ok( $_.value ) } .info_pairs;
   # .is_ok called on invocant not the topic
}

Proposed syntax in this thread (among various others)

method foo {
  return grep { $^.is_ok( .value ) } $^.info_pairs;
  # .value called on the topic
}

The goal is to be able to be concise yet intuitive - so that you could do:

my @good_objects = grep { .is_ok } @candidate_objects;

> OR, choose $^ and don't set $SELF (or $?SELF or whatever), but having
> dup short and long names is a waste, since people will always chose the
> short one (who uses English in Perl 5, really?)

That is the goal - to find some nice variable that looks vaguely usable and 
that people won't rebel against using.

Paul

Reply via email to