On Sat, Mar 15, 2003 at 06:46:21PM -0800, mlazzaro wrote:
: Luke Palmer wrote:
: 
: > The idea is that positional parameters are always a contiguous
: > sequence in the argument list.  If it looked like this:
: >
: >     sub foo($x, ?$y, +$k, [EMAIL PROTECTED]) {...}
: >
: > Then one might presume to call it like:
: >
: >         foo($x,  $y,  $k, 1, 2, 3);
: >
: > Which they can't.  So it makes sense to have everything positional up
: > front, while things that can go anywhere (but must be labeled) in the
: > back.
: 
: I guess.  The most confusing part is this:
: 
:     sub foo($x, +$k, [EMAIL PROTECTED]) {...}    # (1) WRONG
:     sub foo($x, [EMAIL PROTECTED], +$k) {...}    # (2) OK
: 
:     sub foo($x, +$k, *%h) {...}    # (3) OK(?)
:     sub foo($x, *%h, +$k) {...}    # (4) WRONG(?)
: 
: Not only are (1) and (4) wrong, but they're always wrong... AFAICT, there's
: no possible way to get $k correctly if you use those two forms.  (Or maybe
: it's (1) and (3) that are wrong, or maybe both (3) and (4) are OK and only
: (1) is wrong;  it depends on whether *%h is considered 'positional' or
: 'named'.  I'm not even remotely sure.)
: 
: So I would emphatically hope that (1) and (4) produce compile-time errors,
: at minimum.  If we wanted to silently accept (1) and (4) as synonyms for
: (2) and (3), that would be OK too.
: 
: But PLEASE, PLEASE make them compile-time errors if they aren't going to
: work!

Depends on what you mean by "work".  Those are all perfectly good
declarations.  But only (2) allows you to tack the slurpy list
positionally to the end of the positional parameters.

:     sub foo($x, +$k, [EMAIL PROTECTED]) {...}    # (1) WRONG

Not wrong.  It says you must set $k using named notation.  If you
want a list, it goes after "k => $x".  If you don't want to pass k,
you should use <== to mark the variadic transition.  (I suspect some
style guides will require <== on all list operators.  Something to
be said for that.)

:     sub foo($x, [EMAIL PROTECTED], +$k) {...}    # (2) OK

Fine, you can set @a using positional notation, like push(), in
addition to the notations available to (1).  But if you set "k =>",
it has to be before the list, unless you pass the list explicitly as
a "*@" named parameter.  With the exception of [EMAIL PROTECTED] at the front as
in (2), non-positional parameters don't pay any attention to their
order of declaration.

:     sub foo($x, +$k, *%h) {...}    # (3) OK(?)

Says bind "k => $x" to $k, then put any other named parameters in %h
(and maybe k's pair too, depending on implementation).

:     sub foo($x, *%h, +$k) {...}    # (4) WRONG(?)

Says exactly the same as (3).  Non-positional parameters don't care
what order they're declared.

Larry

Reply via email to