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

Re: ===, =:=, ~~, eq and == revisited (blame ajs!)

Thread Previous | Thread Next
From:
Yuval Kogman
Date:
July 12, 2006 10:00
Subject:
Re: ===, =:=, ~~, eq and == revisited (blame ajs!)
Message ID:
20060712170029.GP19536@woobling.org
Jedai and I went through some of pugs current implementations. Here's a list of
what we expect the operators to return and what they currently do.

This does not exactly agree with S03 right now, but is our opinion.

Force into a type before comparing values:

	42 == 42 - true, same numeric value

	"42" == 42 - true, same numeric value

	"42" == "42" - true, same numeric value

	" 42 " == "42.0" - true, same numeric value

	" 42 " eq "42.0" - false, different string value

	4 eq "4" - true, same string value

Well typed value comparison:

	42 === 42 - true, the same type

	"42" === 42 - false, not the same type

	"42" === "42" - true, the same type

	" 42 " === "42.0" - false, different value in "natural" type (string values)

	(1, 2, 3) === (1, 2, 3) - true, same value

	([1, 2 ], 3 ) === ([1, 2 ], 3) - true, same value - BROKEN (actually false,
	since refs are not the same). S03 thinks this is actually OK.

	[1, 2, 3] === [1, 2, 3] - true, same value, (S03 says that this is actually
	broken, because references should not be the same (we disagree))

	my @foo = (1, 2, 3); my @bar = @foo; @foo === @bar - true, same value.

	my @foo = ([1, 2], 3); my @bar = @foo; @bar === @foo - true, same value -
	BROKEN (S03 actually agrees with us here, since the ref is the same in this
	case)

Slot/container equality (this is actually up to debate, but this is what we
would expect if it was refaddr($x) == refaddr($y)):

	[ 1, 2, 3 ] =:= [ 1, 2, 3 ] - false, different containers - BROKEN
	(actually true)

	my $foo = [ 1, 2, 3 ]; $foo =:= $foo - true, same container

	my $foo = [ 1, 2, 3 ]; my $bar := $foo; $bar =:= $foo - true, same container

	my $foo = [ 1, 2, 3 ]; my $bar = $foo; $bar =:= $foo - true, ref to same
	container, or false since different container, unsure - currently true

	my @foo = (1, 2, 3); my @bar = @foo; @foo =:= @bar - false, container
	should be different - BROKEN (actually true)

	my @foo = (1, 2, 3); my @bar = @foo; @bar[1] = "moose"; @foo =:= @bar -
	false, container should be different. This actually works like we expected,
	appearantly pugs does some sort of COW

Under := slot semantics the first test should be false, the second should be
true, the third should be true, the fourth should be false, the fifth should be
false, and the sixth should be false.


-- 
  Yuval Kogman <nothingmuch@woobling.org>
http://nothingmuch.woobling.org  0xEBD27418


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About