Front page | perl.perl6.language |
Postings from August 2006
Re: === and array-refs
Thread Previous
|
Thread Next
From:
Audrey Tang
Date:
August 17, 2006 20:53
Subject:
Re: === and array-refs
Message ID:
6FEE40C3-E86C-4364-A99F-4E002896BB47@audreyt.org
在 2006/8/18 上午 3:31 時,Ben Morrow 寫到:
> Just to make sure I've got all this straight:
>
> =:= compares names
> === compares containers
> eqv compares values
=:= evaluates both sides as lvalue -- that's VAR() -- and compare
them with ===.
=== evaluates both sides as rvalue and, for container (mutable)
types, compares their pointer address.
eqv evaluates both sides as rvalue and, for container (mutable)
types, compares their content values.
None of the three coerces their arguments to concatenated List (aka
list flattening, aka slurpy context).
> So given an array @W,
>
> my @X := @W; # @X =:= @W
> my @Y = @W; # @Y === @W but @Y !=:= @W
> my @Z = @W.clone; # @Z eqv @W but @Z !=== @W
Your Array example would be correct with the $ sigil:
my $w = [1,2,3,4]; # Scalar containing Array
my $x := $w; # $x =:= $w
my $y = $w; # $y === $w but $y !=:= $w
my $z = $w.clone; # $z eqv $w but $z !=== $w
However, &infix:<=> when its left-hand side is an array, has an
different signature
(and indeed, different precedence) than when its left-hand side is a
scalar:
my $y = $w; # does not flatten $w
my @Y = @W; # does flatten @w, essentially doing a .clone
my @Z = @W.clone; # same as "my @Z = @W" really.
So the two assignments (@Y and @Z) above turns out to be the same
thing, and neither
will make "===" hold afterwards.
Cheers,
Audrey
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