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

Re: Question about pairs

4 views
Skip to first unread message

Steve Peters

unread,
Feb 21, 2005, 9:08:49 AM2/21/05
to Damian Conway, perl6-l...@perl.org
On Mon, Feb 21, 2005 at 09:33:33PM +1100, Damian Conway wrote:
> Steve Peters wrote:
>
> >While looking into Perl 6 and pugs, I noticed a problem with Pairs pretty
> >quickly. Although pairs look like a very useful data type, I could find
> >in the "Perl 6 and Parrot Essentials" or any Apocolypse or other document
> >on how to get the key or value from a pair. I was thinking .key and
> >.value seemed logical (and Autrojus implemented them in pugs faster than I
> >could
> >even spit out the names), but that doesn't make them "official".
>
> They're official. See Exegesis 3:
>
> A parameter by any other name
>
> ...
>
> In Perl 6, C<< => >> is a fully-fledged anonymous object constructor --
> like C<[...]> and C<{...}>. The objects it constructs are called "pairs"
> and they consist of a key (the left operand of the C<< => >>), and a
> value
> (the right operand). The key is still stringified if it's a valid
> identifier, but both the key and the value can be any kind of Perl data
> structure. They are accessed via the pair object's C<key> and C<value>
> methods...
>
>

Great! I figured I was just missing something. As a followup, is there
someplace where the raw Pod for the Apocalypses, Exegeses, and Synopses live.
The Pod versions would be much easier to search in bulk than going through
the web pages one by one.

Steve Peters
st...@fisharerojo.org

Steve Peters

unread,
Feb 20, 2005, 10:00:37 AM2/20/05
to perl6-l...@perl.org
Sorry if this email is nearly duplicated, but I may have had the wrong email
address on the firt email I sent.

While looking into Perl 6 and pugs, I noticed a problem with Pairs pretty
quickly. Although pairs look like a very useful data type, I could find
in the "Perl 6 and Parrot Essentials" or any Apocolypse or other document
on how to get the key or value from a pair. I was thinking .key and .value
seemed logical (and Autrojus implemented them in pugs faster than I could
even spit out the names), but that doesn't make them "official".

Steve Peters
st...@fisharerojo.org

Damian Conway

unread,
Feb 21, 2005, 5:33:33 AM2/21/05
to Steve Peters, perl6-l...@perl.org
Steve Peters wrote:

> While looking into Perl 6 and pugs, I noticed a problem with Pairs pretty
> quickly. Although pairs look like a very useful data type, I could find
> in the "Perl 6 and Parrot Essentials" or any Apocolypse or other document
> on how to get the key or value from a pair. I was thinking .key and .value
> seemed logical (and Autrojus implemented them in pugs faster than I could
> even spit out the names), but that doesn't make them "official".

They're official. See Exegesis 3:

A parameter by any other name

...

In Perl 6, C<< => >> is a fully-fledged anonymous object constructor --
like C<[...]> and C<{...}>. The objects it constructs are called "pairs"
and they consist of a key (the left operand of the C<< => >>), and a value
(the right operand). The key is still stringified if it's a valid
identifier, but both the key and the value can be any kind of Perl data
structure. They are accessed via the pair object's C<key> and C<value>
methods...


Damian

Juerd

unread,
Feb 21, 2005, 9:26:52 AM2/21/05
to Steve Peters, perl6-l...@perl.org
Steve Peters skribis 2005-02-21 8:08 (-0600):

> Great! I figured I was just missing something. As a followup, is there
> someplace where the raw Pod for the Apocalypses, Exegeses, and Synopses live.
> The Pod versions would be much easier to search in bulk than going through
> the web pages one by one.

http://dev.perl.org/perl6/synopsis/S01.html
s/html/pod/


Juerd
--
http://convolution.nl/maak_juerd_blij.html
http://convolution.nl/make_juerd_happy.html
http://convolution.nl/gajigu_juerd_n.html

Larry Wall

unread,
Feb 21, 2005, 12:52:23 PM2/21/05
to perl6-l...@perl.org
On Mon, Feb 21, 2005 at 07:50:12PM +0800, Autrijus Tang wrote:
: On Mon, Feb 21, 2005 at 09:33:33PM +1100, Damian Conway wrote:
: > In Perl 6, C<< => >> is a fully-fledged anonymous object constructor --

: > like C<[...]> and C<{...}>. The objects it constructs are called "pairs"
: > and they consist of a key (the left operand of the C<< => >>), and a
: > value
:
: By the way, is $pair.keys simply ($pair.key)?

I think so--a pair can always pretend to be a very small hash.

: What is %hash.key? Type error?

Looks like "no such method" to me.

Larry

Osfameron

unread,
Feb 21, 2005, 9:07:10 AM2/21/05
to perl6-l...@perl.org
> In Perl 6, C<< => >> is a fully-fledged anonymous object constructor --
> like C<[...]> and C<{...}>. The objects it constructs are called
> "pairs"
> and they consist of a key (the left operand of the C<< => >>), and a
> value
> (the right operand).

Can pairs also be used to create linked lists?

my $x = 1=>2=>3=>4

$x.key = 1
$x.value = 2=>3=>4

--
osfameron

Larry Wall

unread,
Feb 21, 2005, 2:32:16 PM2/21/05
to perl6-l...@perl.org
On Mon, Feb 21, 2005 at 02:07:10PM +0000, osfameron wrote:
: > In Perl 6, C<< => >> is a fully-fledged anonymous object constructor --

Yep, certainly--as any Lisp programmer knows, pairs can be used to create
linked lists. But we were hoping nobody would notice that. :-)

In any event, we haven't optimized the pair notation to be the standard
list notation. (But then, almost nobody actually uses dot notation
much in Lisp either...)

On the gripping hand, lists in Perl have historically been optimized
to be in contiguous memory rather than in linked lists, so standard
list notation in Perl is not based on pair semantics as it is in Lisp.
It would be possible to come up with a linked list notation for Perl 6
and install it via some kind of grammatical munge. Bare S-expressions
won't work in standard Perl, of course, unless you make "(foo"
parse like some kind of reserved word for a known set of "foo".
I'm sure if you did that someone would consider it perverse.

Larry

Steve Peters

unread,
Feb 21, 2005, 10:37:02 PM2/21/05
to perl6-l...@perl.org

Just to clarify then, are the following two equivolent?
my $x = 1 => 2 => 3 => 4;
my $x = 1 => (2 => (3 => 4));

Steve Peters
st...@fisharerojo.org

Larry Wall

unread,
Feb 22, 2005, 3:20:35 AM2/22/05
to perl6-l...@perl.org
On Mon, Feb 21, 2005 at 09:37:02PM -0600, Steve Peters wrote:

That seems right to me. Or at least right associative. :-)

In any event, right associativity seems more useful in this case.

Larry

Autrijus Tang

unread,
Feb 22, 2005, 8:07:27 AM2/22/05
to perl6-l...@perl.org
On Tue, Feb 22, 2005 at 12:20:35AM -0800, Larry Wall wrote:
> That seems right to me. Or at least right associative. :-)
>
> In any event, right associativity seems more useful in this case.

Okay, implemented as such.

Of the "non-chaining binaries" in S06:

=> but does cmp <=> .. ^.. ..^ ^..^

How many are similarily right associative? I was listing everything
as non-associative, but it seems that "but" and "does" is left-assoc?

Thanks,
/Autrijus/

Larry Wall

unread,
Feb 22, 2005, 11:57:24 AM2/22/05
to perl6-l...@perl.org
On Tue, Feb 22, 2005 at 09:07:27PM +0800, Autrijus Tang wrote:

I think the case for associativity is much weaker for "but" and "does",
and the direction not intuitively obvious. So let's force people to
parenthesize those by keeping them non-associative, I think. Plus
it decreases cognitive load to have a consistent rule. (Except for the =>,
which makes me wonder if it's at the wrong precedence now. Maybe it
should move down to assignment precedence, and then it would naturally
be right-associative.)

Larry

0 new messages