On Mon, Mar 07, 2005 at 05:37:53PM -0800, David Storrs wrote:
: On Mon, Mar 07, 2005 at 04:58:29PM -0800, Larry Wall wrote:
: > 
: > In fact, we really haven't specified what happens when you say
: > 
: >     my Int @a is shape(3) := [1,2];
: >     my Int @b is shape(3) := [1,2,3,4];
: > 
: [...]
: > But I also have this nagging feeling that the user wouldn't have
: > specified shape(3) unless they actually meant it.  But I suspect
: > that in the typical case, they really do want a 3-element vector,
: > nothing more, nothing less.
: 
: I agree that this is undoubtedly what they meant.  I wonder though, if
: there is then any way to explicitly leave off an element.  Can I do
: this:
: 
:       sub foo( Int @a is shape(3) ) { ... }
:       foo(1, 2, undef);

That's illegal unless you either * the @a or [] the list.  By itself an
@a declaration is always looking to bind a single parameter.  Arguably,
1,2,undef could be interpreted as a single parameter, forcing the
scalar comma to auto-enreference a [1,2,undef] as it does when you say

    $foo = (1,2,undef);

but then we lose argument count checking on any sig ending in an
array, and the meaning of comma subtly changes without warning at
a place other than the expected scalar/variadic boundary.  So we
require splats to make that clear.  I'd also note that

    foo((1,2,undef))

would work in this case because parens in scalar context make all the args
into one arg.  (In list context they would flatten, as they do in Perl 5.)
However, it's a lot clearer to say

    foo([1,2,undef])

if that's what you mean.

Larry

Reply via email to