On Fri, Aug 20, 2004 at 09:04:48AM -0700, Dave Whipp wrote:
: > Parameters are by default constant within the block.  You can
: > declare a parameter read/write by including the "C<is rw>" trait.
: > If you rely on C<$_> as the implicit parameter to a block, then
: > then C<$_> is considered read/write by default.  That is,
: > the construct:
: >
: >     for @foo {...}
: >
: > is actually short for:
: >
: >     for @foo -> $_ is rw {...}
: >
: > so you can modify the current list element in that case.  However,
: > any time you specify the arguments, they default to read only.
: 
: OK, so explicit params are const, and implicit $_ is rw.

There's an implicit C<[EMAIL PROTECTED] is rw> on C<sub {}> too, implying that @_[0] 
etc.
are rw.

: There's another type of implicit arg: placeholders. is $^a "const", or "rw",
: by default? is there any way to control it?

My first inclination is to say that they're "constant" (not "const").
My second inclination is to say that it could depend on how you
use them.  My third inclination is to go back to my first inclination.

Placeholders have to be a very lightweight mechanism.  If you want to do
anything fancy at all, you have to use some other mechanism.

: Is $_ always rw, or only rw when there are no args. I.e.

It's only rw when it's declared rw.  (And when there are no args,
the default declaration is C<$_ is rw>.)

: for @a -> $a {
:   $a ++;   # error: $a is const

"constant".  There ain't no such thing as "const" in Perl.

:   $_++;    # increments $a, because $_ is implicitly bound to the same elem
: as $a?

Nope, error.  $_ is rw only if $a is rw.

:   $^a++;   # Can we mix placeholders with explicit args? Is this also bound
: to $a's element?

Nope, error.  Can't do anything fancy with $^a, including trying to
mix and match with real argument declarations.  As a consequence, it's
impossible even to forward declare a placeholder function.  If you find
yourself wanting to do that, you should be using some other mechanism.

Larry

Reply via email to