Autrijus asked me to look into the correct behavior for $pair.kv
yesterday, and I have been doing some spring cleaning of the Pugs test
suite, and found we actually have two conflicting tests for it. So I am
asking here to see what the official word is so that I can correct our
tests.
One tests shows $pair.kv returning an array with two elements (the key
and value of the pair). (This is also how Pugs currently implements
this.)
Another test shows $pair.kv returning an array with one element which
is an array-ref/list which itself has 2 elements (the key and value) in
it.
I tend to think the former is correct, however a comment over the later
one indicated that it was stated to be this way on this list. I looked
though the list, but was unable to find the specific reference.
Thanks,
Stevan
Page 52 of the 2nd Edition Perl6 and Parrot has this:
for %ages.kv -> $name, $age {
print "$name is now $age";
}
That tends to suggest the former interpretation is correct.
Cheers,
Ovid
--
If this message is a response to a question on a mailing list, please send
follow up questions to the list.
Web Programming with Perl -- http://users.easystreet.com/ovid/cgi_course/
The former is certainly correct. When all else fails, consider a pair
to be a one-element hash.
Luke
>
>then the S29 draft (http://www.rodadams.net/Perl/S29.html) needs
>updating, as currently it states:
>
>
>>What is returned at each element of the iteration varies
>>with function. values returns the value of the associated
>>element; **kv returns a 2 element list in (index, value)
>>order**, pairs a Pair(index, value).
>>
>>
>
>Unless, of course, I misunderstand any(S29, Luke) :) --
>Is the following correct?
> my @array = <a b c>;
> my @kv = @array.kv;
> say +@kv; # 6
> say ~@kv; # 0 a 1 b 2 c
>
Yes.
As for S29, in my head, a list of lists is still just a list. An array
of arrays is a different story.
So this behavior is what I meant to say in S29. If it's unclear, I'm
open to suggestions.
-- Rod Adams
(who still needs more time to work on S29. Looks like I'll have some in
a few weeks. In the meantime, if there's someone else out there itching
to work on it, let me know.)