Front page | perl.perl6.language |
Postings from August 2006
Re: === and array-refs
Thread Previous
|
Thread Next
From:
David Green
Date:
August 16, 2006 22:16
Subject:
Re: === and array-refs
Message ID:
a06230900c109478fb223@[172.27.1.7]
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
here).
Actually, my previous example which Larry said was correct was:
$a=[1, 2, \@x];
$c=[1, 2, \@x];
$d=[1, 2, \@y];
$a =:= $c; #false, different variables
$a === $c; #true, same elements make up $a and $c
$a eqv $c; #true, same elements therefore same values
$a === $d; #false, \@x and \@y are different refs
So $a, $c, and $d may all have the same *value* (or "snapshot", when
evaluated all the way down through nesting and references), i.e. they
might be eqv, but only $a and $c are === because they have the same
contents [unevaluated contents] and $d doesn't.
Which is what makes sense to me, but S03 says "[1,2]!===[1,2]". My
position is that even if they are different "objects", that
difference is fairly useless, and should therefore be hidden (same as
it is for objects that are strings).
>First of all, in Perl 6, there are no separate "arrays" and "array
>refs"; we simply have the 'Array' type, which is treated as a lump
>on its own.
>More generally, there are no "reference" types in Perl 6.
I thought there were, just not as conspicuously. There are
"captures" anyway, which are supposed to be like P5-refs, and beyond.
(However, I admit to being a bit fuzzy on exactly how Signatures and
Captures work -- if anyone could write an Exegesis on the subject, I
know I'm not the only one who would appreciate it.)
[...]
>The difference between === and eqv is that, if you have 2 symbols,
>$a and $b, and $a === $b returns true, then that result is
>guaranteed to be eternal if you don't assign to either symbol
>afterwards. For a mutable type like an Array, === returns false on
>2 containers because it can't guarantee that someone else holding
>another symbol for either container won't change its content, and so
>$a or $b could change after we made the === test, without us causing
>that to happen, and so for mutable types, === only returns true for
>2 aliases, because that is the most it can guarantee that they will
>be the same.
So, given mutable types, $a===$b if and only if $a=:=$b? That
doesn't sound right, otherwise === seems superfluous. The thing is
if $a=[1,2] and $b=[1,2], then arrays or not, nothing can change $a
or $b except by changing $a or $b. [Or aliases bound to same, of
course.] So there's no reason for $a===$b to be false. (If they
look the same, and they act the same, then they're ducks. Er, or
something.)
(Hoping the 'eternal' stuff hasn't thrown me off and resulted in my
completely misinterpreting what you were trying to say.)
-David
Thread Previous
|
Thread Next
-
===, =:=, ~~, eq and == revisited (blame ajs!)
by Yuval Kogman
-
Re: ===, =:=, ~~, eq and == revisited (blame ajs!) -- Explained
by Yuval Kogman
-
Re: ===, =:=, ~~, eq and == revisited (blame ajs!) -- Explained
by David Green
-
Re: ===, =:=, ~~, eq and == revisited (blame ajs!) -- Explained
by Larry Wall
-
Re: ===, =:=, ~~, eq and == revisited (blame ajs!) -- Explained
by Smylers
-
Re: ===, =:=, ~~, eq and == revisited (blame ajs!) -- Explained
by Charles Bailey
-
Re: ===, =:=, ~~, eq and == revisited (blame ajs!) -- Explained
by Jonathan Lang
-
Re: ===, =:=, ~~, eq and == revisited (blame ajs!)
by Darren Duncan
-
Re: ===, =:=, ~~, eq and == revisited (blame ajs!)
by Aaron Sherman
-
Re: ===, =:=, ~~, eq and == revisited (blame ajs!)
by Yuval Kogman
-
Re: ===, =:=, ~~, eq and == revisited (blame ajs!)
by Yuval Kogman