Front page | perl.perl6.language |
Postings from August 2006
Re: === and array-refs
Thread Previous
|
Thread Next
From:
David Green
Date:
August 17, 2006 11:19
Subject:
Re: === and array-refs
Message ID:
a06230904c10a4df732bb@[172.27.1.7]
On 8/16/06, David Green wrote:
> $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.
(Actually $a===$c above should be false.) Given
that === answers the question "are these things
the same object", what's the solution for my
original motivation of comparing two items for
their unevaluated contents? "Eqv" evaluates
everything (both references and nested
containers) down to immutable values; I want to
follow nested structures all the way down, but
not evaluate/deref any variable references.
For the one-dimensional $a and $c given above, I could do something like:
?all(@$a==@$c, grep {$^a === $^c} zip(@$a; @$c))
For multidimensional/nested arrays, I could check
that they're the same size with $a.shape eqv
$b.shape, but I believe grep (or map, etc.) work
only one-dimensionally. I don't think using
hyperoperators would work either, because $a
»===« $c would deref the contained @x before
applying ===, right?
Plus hyperops return a nested structure, and I'm
looking for a single bool -- I think hyperising
"all" around the whole result would work....
Hyperops also upgrade dimensions that don't match
between the RHS and LHS, which is not always what
you want.
So perhaps what I'm looking for is more syntactic
sugar for easily traversing nested data
structures in different ways.
-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