develooper Front page | perl.perl6.language | Postings from August 2006

Re: === and array-refs

Thread Previous | Thread Next
Darren Duncan
August 17, 2006 00:00
Re: === and array-refs
Message ID:
At 11:16 PM -0600 8/16/06, David Green wrote:
>On 8/15/06, Darren Duncan wrote:
>>At 2:51 PM -0600 8/15/06, David Green wrote:
>>You are right, but we have both Seq and Array types, so depending 
>>which one you use, you want either the === or eqv operators to do 
>>what you want.  There is no reason that === should say 2 Array are 
>>equal; we have eqv for that, or use 2 Seq instead of 2 Array if you 
>>want === to return true on the same values.
>Is Seq vs Array the right distinction here?  A Seq is immutable, so 
>I can't change its size, for instance, which is not what I want.  I 
>just want [1,2] to be === to [1,2], or [1,2, \@x] to be equal to 
>[1,2, \@x] but !=== [1,2, \@y] -- eqv won't work in the latter case 
>(regardless of Seq vs. Array -- I didn't think it made a difference 

As a lead-in, I should say that Synopsis 3 has a good and complete 
explanation of these matters and has had it for several weeks, in my 

Since you are wanting to compare two mutable Array, just use the eqv 
operator, which will do everything you want in a terse and easy to 
understand manner.

Generally speaking, the direct use of === is more for specialized 
purposes, somewhat like the direct use of =:= is.  If one can't tell 
the difference between === and eqv, they most likely want snapshot 
semantics anyway, and so might as well forget === exists, and just 
use eqv everywhere.

There's no point arguing that === should deeply compare mutable types 
when you already have eqv to do that.  Continuing on like you appear 
to be is like saying that the + operator should be useable to 
concatenate two Str, when we have the ~ operator for that.  Arguing 
that === should deeply compare mutable types is like arguing that + 
should contactenate two Str.

-- Darren Duncan

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About