Larry Wall wrote:

On Mon, Nov 18, 2002 at 08:05:47AM +1100, Damian Conway wrote:
: I still think my original:
: : sub bar(; $foo = $topic) is given($topic) {...}
: : is the appropriate compromise.

Won't fly. Referring to something lexical before it's declared is
a no-no.
I would maintain that that depends on the associativity of C<is given>. ;-)
But you mean in a strict left-to-right parsing sense.


I think we need some other way of indicating the outer topic
if we're gonna use it as a default, and I think we do want that.
I think so too.


Perhaps it's a good time for a real keyword for use in defaults:

    sub bar(; $foo = topic) {...}
That would have to be:

	sub bar(; $foo = topic) is given($whatever) {...}

wouldn't it? Otherwise the topic is C<undef>.


Anyway, I think a C<topic> keyword is NQR.
For a start, it introduces a (rather too) subtle difference between:

	sub bar($foo = topic) is given($whatever) {...}

and:

	sub bar($foo is topic) is given($whatever) {...}

not to mention the pain in continually needing to explain why this is okay:

	sub bar($foo is topic = topic) is given($whatever) {...}

but this is not:

	sub bar($foo = topic is topic) is given($whatever) {...}


Hmmmmm. Given that the topic is in some sense a property of the lexical
scope of the subroutine body, this might be a possibility:

	sub bar($foo is MY.topic) is given($whatever) {...}

But I think there's a better solution. See below.


That would let us work it nicely for arrays too:

    sub bar(*@args = [topic]) {...}

Without the [], people might get confused about what to do with a $_
containing an array reference.  But maybe that means it should really
be a magical variable
Yep.


so we can distinguish

    sub bar(*@args = $<mumble>) {...}	# default to [$_]
    sub bar(*@args = @$<mumble>) {...}	# default to @$_

What <mumble> might be is an interesting, er, topic.
I would argue it ought to be just $_, which is, after all,
the One True Topic. And conveniently lexically predeclared in all scopes.

I would also argue that it ought not be called anything else.
Surely don't want two specially named variables for the topic?

Damian

Reply via email to