In summary, I am proposing that one marks
variables that are to be automatically
passed from sub to sub with 'is yours'
where appropriate.

An example of what I'm suggesting follows.
Code with brief comments first then explanation.

  {
    my $_;              # $_ can't be touched
                        # unless it is passed
                        # to a sub explicitly.

    my $foo;            # same for $foo

    my $baz is yours;   # $baz will automatically
    $baz = 10;          # be passed to /directly/
                        # called subs that "ask"
                        # explicitly for $baz.

    &waldo($foo);
  }

  sub waldo ($b ; $baz is yours)
            { print $baz; &emer; }

  sub emer  (;$baz is yours(no))
            { print $baz; &qux; }

  sub qux   { ... }

Running this prints '1010'. Here's why:

A property exists that can mark any lexical
as "yours". When a variable is marked yours
it is automatically passed to any directly
called sub (not nested subs) that mentions
it appropriately.

The "automatic" $_ (available without
declaring with a 'my') is marked "yours"
by default.

All other (ie declared) lexicals are, by
default, not yours, hence guaranteed to be
private lexicals unless explicitly passed
to a sub. This is safer than the current
perl 6 design in which use of $CALLER::,
and even builtins and subs that merely
use the topic, might accidentally clobber
one of my lexicals at any time.

Once execution reaches the body of waldo,
there is a new lexical called $baz that is
bound to the lexical with the same name in
the body of the caller.

The C<is yours> in waldo's sig has two
effects:

1. It requires that any /caller/ has a
   variable of the same name marked as
   yours or must pass a variable/value
   using the named arg syntax for that
   arg name;

2. It propogates the marking of $baz as
   a yours marked variable for any sub
   called from this, the body of waldo.

Once execution reaches the body of emer,
there is a new lexical called $baz that is
bound to the lexical from waldo which is in
turn bound to the lexical within qux.

The '(no)' at the end of the C<is yours>
means that $baz is private to emer -- it
will not be passed to called subs by the
yours mechanism.

In summary, you mark variables that are
to be automatically passed from sub to
sub with 'is yours' where appropriate.

--
ralph

Reply via email to