equality testing?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

equality testing?

Raoul Duke
hi,

i haven't found info on how equality is tested in haxe syntax. other
than that the physical equality tests were removed in 2.0. where might
i find specs on how things are done, both for syntax and semantics?
apologies if i'm just missing it right in front of me somewhere :-}

thanks.

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: equality testing?

Raoul Duke
On Mon, Aug 22, 2011 at 9:12 AM, Raoul Duke <[hidden email]> wrote:
> i haven't found info on how equality is tested in haxe syntax. other

ah, well, google does better than bing.

== != > < >= <= : perform normal or physical comparisons between two
expressions sharing a common type. Returns Bool.

still, that leaves questions :-) like what "normal or physical" means
and how i'd implement my own?

tx.

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: equality testing?

Pimm Hogeling
Physical equality refers to two references to the same object.

class Apple {
    /**
     * The weight of the apple in grams.
     */
    public var weight:Float;
    public function new(weight:Float):Void {
        this.weight = weight;
    }
}
var firstApple = new Apple(150);
var secondApple = new Apple(150);
var otherReferenceToSecondApple = secondApple;
trace(firstApple == firstApple); // Traces true. Same apple.
trace(secondApple == otherReferenceToSecondApple); // Traces true, as well, still the same apple.
trace(firstApple == secondApple); // Traces false. Same weight; not the same apple.

You can implement structural equality as well.

class Apple {
    /**
     * The weight of the apple in grams.
     */
    public var weight:Float;
    public function new(weight:Float):Void {
        this.weight = weight;
    }
    public inline function determineEquals(candidate:Apple):Bool {
        return candidate.weight == weight;
    }
}
var firstApple = new Apple(150);
var secondApple = new Apple(150);
trace(firstApple.determineEquals(firstApple)); // Traces true. Same weight.
trace(firstApple.determineEquals(secondApple)); // Traces true, as well. Same weight.

2011/8/22 Raoul Duke <[hidden email]>
On Mon, Aug 22, 2011 at 9:12 AM, Raoul Duke <[hidden email]> wrote:
> i haven't found info on how equality is tested in haxe syntax. other

ah, well, google does better than bing.

== != > < >= <= : perform normal or physical comparisons between two
expressions sharing a common type. Returns Bool.

still, that leaves questions :-) like what "normal or physical" means
and how i'd implement my own?

tx.

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: equality testing?

Nicolas Cannasse
In reply to this post by Raoul Duke
Le 22/08/2011 18:12, Raoul Duke a écrit :
> hi,
>
> i haven't found info on how equality is tested in haxe syntax. other
> than that the physical equality tests were removed in 2.0. where might
> i find specs on how things are done, both for syntax and semantics?
> apologies if i'm just missing it right in front of me somewhere :-}

Basic types are tested with normal equality : String, Int, Float, Bool
Other types are tested with physical equality.

Nicolas

--
haXe - an open source web programming language
http://haxe.org