Larry wrote:

The long and the short of it was that

    my sub foo ($_ := $arg = $_)

is how you might set $arg to be both the "topic" and the "given".
Wow. I'm surprised by how much I don't like that syntax! ;-)

I mean, two entirely different meanings for $_ in the space of one parameter
definition? And both := and = in one parameter definition?

I'd *so* much prefer to have to write:

      my sub foo ($arg is topic = $CALLER::_)

(see below).


In the common case, that comes down to

    my sub foo ($_ = $_)

to just propagate the outer $_ inward.
That only works when $_ can somehow be shoe-horned into the parameter list.
Whereas:

      my sub foo is given($_)

works for *any* parameter list.


So I was thinking it'd be better to use something different to
represent the outer topic, like:

    my sub foo ($_ = $^)
    my sub foo ($_ = $+)
    my sub foo ($_ = $|)
    my sub foo ($_ = $=)
    my sub foo ($_ = $:)
    my sub foo ($_ = $?)
    my sub foo ($_ = $$)
    my sub foo ($_ = $@)

or some such.  That's what I meant by <mumble>.  I kinda like $= at the
moment, presuming it's coming available from formats.  Or maybe $?.
$= as an alias for the caller's $_, I could certainly live with.
It's mnemonically *much* better than $?. And it gets rid of the need
for a separate C<is given> property on the subroutine, since the sub
can just refer to $= if it needs to.

And no, formats aren't going to need $=.


Possibly we have something more evil than that, such as the notion that
$? is a double sigil that pulls a name out of the dynamic context's
lexical scope.  Then we could write $?_ for the outer $_, $?foo for the
outer $foo, @+_ for the outer @_,
Typo on that last one (I hope!)


$?! for the outer $!, etc.  That would
make it

    my sub foo ($arg is topic = $?_)
The only problems I have with this are:

	1. Do we really want to allow every lexical to be accessible anywhere
	   in its dynamic scope? This has many of the same drawbacks as C<local>.
	   $_ is probably a special case (which argues for $= rather than
	   a general mechanism).

	2. If we *do* want to provide that mechanism, do we really want to make
	   it that easy/subtle/short/missable? If we're going to do this,
	   I think $CALLER::_, $CALLER::foo, @CALLER::_, $CALLER::! might be
	   better. At least they're ugly, and scream for special attention. ;-)


I suppose it could be argued that defaulting the outer topic should also
set the inner topic by default, so you could write

    my sub foo ($arg = $?_) {
	when 1 { ... }
	...
    }	
Yeah, I wouldn't have a problem with that
(except for $?_ not being $CALLER::_ ;-)

Though I think:

	my sub foo($arg = $=) {...}

would be even better.

Damian


Reply via email to