HaloO Jonathan,

you wrote: (why off-list?)
Hmmmm, and the current actor/owner is $/ which gives the expanded
method call syntax:

  .method   #  really means:   $/.method($_)


You mean $?SELF rather than $/.  $/ is now the match object used in
rules.

I would say *for* rules/methods. $?SELF is a variable that is bound for
the body of the rule/method once. But I'm talking about the outside
general environment. I'm unsure about the rule syntax but wasn't it like

grammar Foo
{
   rule alpha {...}
   rule beta {...}
   rule blahh { <{ if .alpha { say "letters $/" } }> <beta> }
} #                   ^^^^^^^

I wonder how the generic, lexically scoped invocant/owner is called.
I propose to call it $/ and let the former topicalizer become
block owners and $_ the block topic that flows into blocks from
further outside if not explicitly bound with -> like:

   $topic := Some.new;
   $_ := $topic;
   for @objects { .action } # call on $/ from @objects with $_ := $topic
                            # in all loops

   @objects».action;  # same for single action syntax


   # but
   for @objects -> { .action } # means $/.action($/) because
                               # $_ bound to dynamic block owner;
                               # but usefull for methods that don't
                               # use the topic, in particular accessors
                               # and mutators
   # same as sub call
   for @objects -> { action }  # means action($/) because $_ := $/
                               # but $/ is there if action is of
                               # type Method

The only drawback I see is, that the careless method programmer could be
caugth in an endless .action loop if .action invokes .action explicitly
on $_ where $_ := $/ from the outside. The same endless loop could of
course be achieved with a free standing .action but that looks more like
intention.

With the lurking pitfalls an occasional check of $_ =:= $?SELF and
$/ =:= $_ seems advisable and indicates that the invocant wasn't
exchanged midway :)

Same with other topicalizers

  given $x    {...}  # topic untouched, but $/ := $x
  given $x -> {...}  # $_ := $x as well

But

  if $x    {...}   # $/ and $_ untouched
  if $x -> {...}   # $_ := $x (non boolean value)

One more interessting thing is that in exception handlers all three
variables $!, $/ and $_ are in scope. This might allow to resume where
the exception occurred after the cause was fixed e.g. by loading or
generating some code, some revamping or other &DEEP_MAGIC.


Always needs parens?  Even in the simple cases?

        my $foo = $cond ?? $alpha :: $beta;

People who know the parsers better than I do, correct me but I want
this to tokenize as (my $foo = $cond)??($alpha)::($beta) and then
given to the current match state of the parser seperately to produce a
"name lookup" resulting in the above case in three code snippets.
This e.g. allows to define the boolean "type" as

      *::false ::= *::bit::0;
      *::true  ::= *::bit::$_??$_::*false;

or so. And whitespace around ?? and :: doesn't matter!
?? just means skip next lookup if "lookup" fails.

Regards,
--
TSa (Thomas Sandlaß)


Reply via email to