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
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
> 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
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
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
Can pairs also be used to create linked lists?
my $x = 1=>2=>3=>4
$x.key = 1
$x.value = 2=>3=>4
--
osfameron
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
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
That seems right to me. Or at least right associative. :-)
In any event, right associativity seems more useful in this case.
Larry
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/
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