From: Larry Wall [EMAIL PROTECTED]
> Perhaps there should be a way 
> to declare a parameter to be pass-by-value, producing a 
> modifiable variable that does not affect the caller's value. 
> But I'm not sure saving one assignment in the body is worth 
> the extra mental baggage. 

.... and later he said ...

> The default is pass-by-reference, but non-modifiable.  If
> there's a pass-by-value, it'll have to be specially requested
> somehow.
> 
> This is a minimal difference from Perl 5, in which everything
> was pass-by-reference, but modifiable.   To get pass-by-value,
> you just do an assignment.  :-)

Thesis: there should be an option for pass-by-value-modifiable without
requiring a new assignment or new variable.

Reason 1: Pass-by-value-non-modifiable *is* a significant change from
Perl5.  I know this doesn't quite mesh with the technical facts, but from
the how-people-actually-use-it perspective, there's a big change.  Yes,
Perl5 is pass-by-reference-modifiable, but in practice most people don't
use it that way.  Except for short 1-3 line functions, most subs start by
creating named variables and copying them from @_, like one of these lines:

        my $self = shift;
        my ($tag) = @_;

That is, they actually use it like pass-by-value-modifiable.  Now, Perl6
will give us a slicker way to get well-named variables as subroutine
arguments:

        sub mysub ($name, $email) { ... }

Ah, but that's where a bait-and-switch problem comes in.  It feels like the
param list is taking the place of "my ($tag) = @_;", but the new-improved
named arguments don't act the same way.  Suddenly they're not modifiable. 
That's different.


Reason 2: Enforced non-modifiable arguments are a pain. PL/SQL does not
allow you to modify pass-by-value arguments to functions, and most PLSQL
programmers I've talked to hate that.  It requires you to create a named
argument, then another variable with an almost-same-name that can be
modified.  My PLSQL is cluttered with variables named v_email and p_email,
instead of just email.  I would hate to see Perl go down that road.

Resolution: Use whatever default seems good, but provide the freedom to get
pass-by-value-modifiable, perhaps something like this:

        sub mysub ($name is m, $email is m) { ... }

-Miko

--------------------------------------------------------------------
mail2web - Check your email from the web at
http://mail2web.com/ .


Reply via email to