On 8/16/06, David Green wrote:
   $a=[1, 2, [EMAIL PROTECTED];
   $c=[1, 2, [EMAIL PROTECTED];
   $d=[1, 2, [EMAIL PROTECTED];

        $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, [EMAIL PROTECTED] and [EMAIL PROTECTED] 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(@[EMAIL PROTECTED], 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

Reply via email to