Luke Palmer <[EMAIL PROTECTED]> writes:
> On 8/3/05, Aankhen <[EMAIL PROTECTED]> wrote:
>> On 8/3/05, Piers Cawley <[EMAIL PROTECTED]> wrote:
>> > So how *do* I pass an unflattened array to a function with a slurpy
>> > parameter?
>>
>> Good question. I would have thought that one of the major gains from
>> turning arrays and hashes into references in scalar context is the
>> ability to specify an unflattened array or a hash in a sub call
>> without any special syntax...
>
> Well, you can, usually. This is particularly in the flattening
> context. In most cases, for instance:
>
> sub foo ($a, $b) { say $a }
> my @a = (1,2,3);
> foo(@a, "3");
>
> Passes the array into $a. If nothing flattened by default, then you'd
> have to say, for example:
>
> map {...} [EMAIL PROTECTED];
>
I would assume that the way to implement map is:
multi sub map(&block, @array) { map &block, [EMAIL PROTECTED] }
multi sub map(&block, [EMAIL PROTECTED]) { ... }
If I call map like:
map {...} @a, @b, @c;
then I would expect the block to be called three times with @a, @b and @c as
the respective arguments.
I think the problem I have with this is that unless I missed something, the
default prototype for a block is [EMAIL PROTECTED] If slurpiness works as
described, then
$func = { [EMAIL PROTECTED] }
$func.(@array)
doesn't return the length of the array, but the numification of its first
element.
It seems to me that a slurpy parameter spec should simply say "Grab the
rest of the arguments and stick 'em in this array/hash", a function's caller
should control the flattening of a particular array argument, not the thing it
calls.
One of us has obviously misread the appropriate Apocalypse/Synopsis/Exegesis. I
have the horrible feeling that it's probably me, but I do think that the
interpretation I propose is the least surprising and most useful.
By the way, if flattening that way, what's the prototype for zip? We can after
all do:
zip @ary1, @ary2, @ary3, ... @aryn