Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Question about $pair.kv

4 views
Skip to first unread message

Stevan Little

unread,
Apr 9, 2005, 10:03:31 PM4/9/05
to perl6-l...@perl.org
Hello all,

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

Ovid

unread,
Apr 9, 2005, 11:51:00 PM4/9/05
to Stevan Little, perl6-l...@perl.org
--- Stevan Little <ste...@iinteractive.com> wrote:
> Autrijus asked me to look into the correct behavior for $pair.kv
> 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.

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/

Luke Palmer

unread,
Apr 10, 2005, 12:16:02 AM4/10/05
to Stevan Little, perl6-l...@perl.org
Stevan Little writes:
> 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.

The former is certainly correct. When all else fails, consider a pair
to be a one-element hash.

Luke

Ingo Blechschmidt

unread,
Apr 10, 2005, 6:52:31 AM4/10/05
to perl6-l...@perl.org
Hi,

Luke Palmer <luke <at> luqui.org> writes:
> Stevan Little writes:
> > 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.)
>
> The former is certainly correct. When all else fails, consider a pair
> to be a one-element hash.

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

FYI, before your post, my assumption was:
my @array = <a b c>;
my @kv = @array.kv;
say +@kv; # 3
say ~@kv[0]; # 0 a
say ~@kv[1]; # 1 b
say ~@kv[2]; # 2 c
# That means, @kv = ([0, a], [1, b], [2, c])


--Ingo

--
Linux, the choice of a GNU | Life would be so much easier if we could
generation on a dual AMD | just look at the source code.
Athlon! | -- Dave Olson

Rod Adams

unread,
Apr 10, 2005, 1:48:16 PM4/10/05
to perl6-l...@perl.org
Ingo Blechschmidt wrote:

>
>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.)

0 new messages