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

Fwd: ===, =:=, ~~, eq and == revisited (blame ajs!) -- Explained

Thread Previous | Thread Next
Jonathan Lang
July 14, 2006 12:49
Fwd: ===, =:=, ~~, eq and == revisited (blame ajs!) -- Explained
Message ID:
Dave Whipp wrote:
> Darren Duncan wrote:
> > Assuming that all elements of $a and $b are themselves immutable to all
> > levels of recursion, === then does a full deep copy like eqv.  If at any
> > level we get a mutable object, then at that point it turns into =:= (a
> > trivial case) and stops.
>    ( 1, "2.0", 3 ) === ( 1,2,3 )
> True or false?
> More imprtantly, how do I tell perl what I mean? The best I can think of is:
>    [&&] (@a »==« @b)
> Vs
>    [&&] (@a »eq« @b)
> But this only works for nice flat structures.

IIRC, this is because the implicit coercion to number or string gets
in the way.

IMHO, "@a == @b" ought to be synonymous with "all (@a »==« @b)" - it's
far more likely to DWIM.  Likewise with "@a eq @b" and "all (@a »eq«
@b)".  If what you want to do is to compare the lengths of two lists,
you ought to do so explicitly: "+@a == +@b".

Getting back to the notion of immutability: can someone give me an
example of a realistic immutable analog to a list, and then give an
example demonstrating the practical distinction between === and eqv
based on that?  I want to see why it's important to distinguish
between comparing mutable data types and comparing immutable data

(Incidently, I think that a suitable word-based synonym for =:= would be "is".)

Jonathan "Dataweaver" Lang

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