Damian Conway <[EMAIL PROTECTED]>:
>
> This RFC proposes the introduction of a new data type -- the I<pair> -- and
> the co-opting of the => operator to act as a pair constructor. Most existing
> uses of => would be preserved.
>[etc.]
> %hash = ( a=>1, b=>2, 'c', 3 );
>
> does what it does in Perl 5, but works slightly differently.
Yeah; so what's the point? Will hashes being represented internally
as sets of pairs be somehow more efficient? What's the win?
> When a pair reference is assigned (in)to a hash, the pair's key becomes
> the hash entry's key, and the pair's value becomes the entry's value
Wasn't there talk of allowing types other than scalars to be hash keys?
If so, then a pair could not be a hash key, except in the singular
assignment
$hash{ $pair } = $val;
but not in something as trivial as
%hash = ( $pair, $val, $pair2, $pair3 );
I could make a more trivial example, but then I expect you to say
that hash assignment will be smarter about inferring an even number
of values in the rhs.
> =head2 Pairs and multiway comparisons
>
> Pairs also provide a clean way of implementing multiway comparisons.
>
> It is proposed that when a pair is evaluated in a boolean context, it
> would evaluate to the truth value of its key. But when evaluated as the left
> operand of a comparison operator, it would evaluate to its value,
> I<but> would short-circuit if its key were false.
Has anyone checked how Icon does this?
(Yeah, I know, I should do it myself.)
Here's a counter-proposal: throw out hashes as a separate internal
data type, and in its place define a set of operators which treat
(properly constructed) arrays as associative arrays. It's the
operators that do all the work anyway; the semantic benefit of
a distinct data type is miniscule. And away with pairs: use
arrays instead. Perhaps, along with constant scalars, we should
be able to declare arrays as having a constant size; and a "pair"
would be a predefined alias for "array with constant size = 2".
One benefit is this allows any type to be the "key" of an assoc. array,
with no extra support required in the core; deep and special-case
comparisons can be supplied by the user.
--
John Porter
Aus tiefem Traum bin ich erwacht.