Neko compareMethods behavior

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

Neko compareMethods behavior

David Peek-2
Hi list,

Can anyone explain the following behaviour in neko?

class Main
{
        public static function main()
        {
                trace(Reflect.compareMethods(function(){}, function(){})); // false
                trace(Reflect.compareMethods(getFunction(), getFunction())); // true
        }

        static function getFunction()
        {
                return function(){};
        }
}

I would expect the second compare to trace false as getFunction returns a new method each time you call it.

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

Re: Neko compareMethods behavior

David Peek-2
Even stranger?

class Main
{
        public static function main()
        {
                trace(Reflect.compareMethods(getFunction1(), getFunction1()));
                trace(Reflect.compareMethods(getFunction1(), getFunction2()));
        }

        static function getFunction1()
        {
                return function(){};
        }

        static function getFunction2()
        {
                return function(){};
        }
}

On 09/10/2011, at 8:52 PM, David Peek wrote:

> Hi list,
>
> Can anyone explain the following behaviour in neko?
>
> class Main
> {
> public static function main()
> {
> trace(Reflect.compareMethods(function(){}, function(){})); // false
> trace(Reflect.compareMethods(getFunction(), getFunction())); // true
> }
>
> static function getFunction()
> {
> return function(){};
> }
> }
>
> I would expect the second compare to trace false as getFunction returns a new method each time you call it.
>
> Thanks,
> David
> --
> 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: Neko compareMethods behavior

Skial Bainn
Maybe it is comparing them on type, each function is Void->Void ? Just a guess :)

On Sun, Oct 9, 2011 at 12:00 PM, David Peek <[hidden email]> wrote:
Even stranger?

class Main
{
       public static function main()
       {
               trace(Reflect.compareMethods(getFunction1(), getFunction1()));
               trace(Reflect.compareMethods(getFunction1(), getFunction2()));
       }

       static function getFunction1()
       {
               return function(){};
       }

       static function getFunction2()
       {
               return function(){};
       }
}

On 09/10/2011, at 8:52 PM, David Peek wrote:

> Hi list,
>
> Can anyone explain the following behaviour in neko?
>
> class Main
> {
>       public static function main()
>       {
>               trace(Reflect.compareMethods(function(){}, function(){})); // false
>               trace(Reflect.compareMethods(getFunction(), getFunction())); // true
>       }
>
>       static function getFunction()
>       {
>               return function(){};
>       }
> }
>
> I would expect the second compare to trace false as getFunction returns a new method each time you call it.
>
> Thanks,
> David
> --
> haXe - an open source web programming language
> http://haxe.org


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



--
Skial



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

Re: Neko compareMethods behavior

David Peek-2
That was my first thought too.. or some kind of compilation optimisation. 

But then _all_ the types are the same, so the same type coming from two different methods should also be equal...

Oh, forgot to paste trace output:

trace(Reflect.compareMethods(getFunction1(), getFunction1())); // true
trace(Reflect.compareMethods(getFunction1(), getFunction2())); // false

On 09/10/2011, at 10:05 PM, Skial Bainn wrote:

Maybe it is comparing them on type, each function is Void->Void ? Just a guess :)

On Sun, Oct 9, 2011 at 12:00 PM, David Peek <[hidden email]> wrote:
Even stranger?

class Main
{
       public static function main()
       {
               trace(Reflect.compareMethods(getFunction1(), getFunction1()));
               trace(Reflect.compareMethods(getFunction1(), getFunction2()));
       }

       static function getFunction1()
       {
               return function(){};
       }

       static function getFunction2()
       {
               return function(){};
       }
}

On 09/10/2011, at 8:52 PM, David Peek wrote:

> Hi list,
>
> Can anyone explain the following behaviour in neko?
>
> class Main
> {
>       public static function main()
>       {
>               trace(Reflect.compareMethods(function(){}, function(){})); // false
>               trace(Reflect.compareMethods(getFunction(), getFunction())); // true
>       }
>
>       static function getFunction()
>       {
>               return function(){};
>       }
> }
>
> I would expect the second compare to trace false as getFunction returns a new method each time you call it.
>
> Thanks,
> David
> --
> haXe - an open source web programming language
> http://haxe.org


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



--
Skial


--
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: Neko compareMethods behavior

David Peek-2
Well, I think it boils down to this:

class Main
{
public static function main()
{
trace("inline:" + Reflect.compareMethods(function(){}, function(){})); // false
trace("getFunction1:" + Reflect.compareMethods(getFunction1(), getFunction1())); // true
trace("getFunction2:" + Reflect.compareMethods(getFunction2(), getFunction2())); // false
}

static function getFunction1()
{
return function(){};
}

static function getFunction2()
{
var n = 0;
return function() { n; };
}
}

Which I guess could be the result of some NekoVM optimisation?

Can work around it for now :)

dp

On 09/10/2011, at 10:10 PM, David Peek wrote:

That was my first thought too.. or some kind of compilation optimisation. 

But then _all_ the types are the same, so the same type coming from two different methods should also be equal...

Oh, forgot to paste trace output:

trace(Reflect.compareMethods(getFunction1(), getFunction1())); // true
trace(Reflect.compareMethods(getFunction1(), getFunction2())); // false

On 09/10/2011, at 10:05 PM, Skial Bainn wrote:

Maybe it is comparing them on type, each function is Void->Void ? Just a guess :)

On Sun, Oct 9, 2011 at 12:00 PM, David Peek <[hidden email]> wrote:
Even stranger?

class Main
{
       public static function main()
       {
               trace(Reflect.compareMethods(getFunction1(), getFunction1()));
               trace(Reflect.compareMethods(getFunction1(), getFunction2()));
       }

       static function getFunction1()
       {
               return function(){};
       }

       static function getFunction2()
       {
               return function(){};
       }
}

On 09/10/2011, at 8:52 PM, David Peek wrote:

> Hi list,
>
> Can anyone explain the following behaviour in neko?
>
> class Main
> {
>       public static function main()
>       {
>               trace(Reflect.compareMethods(function(){}, function(){})); // false
>               trace(Reflect.compareMethods(getFunction(), getFunction())); // true
>       }
>
>       static function getFunction()
>       {
>               return function(){};
>       }
> }
>
> I would expect the second compare to trace false as getFunction returns a new method each time you call it.
>
> Thanks,
> David
> --
> haXe - an open source web programming language
> http://haxe.org


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



--
Skial


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

--
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: Neko compareMethods behavior

Nicolas Cannasse
In reply to this post by David Peek-2
Le 09/10/2011 11:52, David Peek a écrit :

> Hi list,
>
> Can anyone explain the following behaviour in neko?
>
> class Main
> {
> public static function main()
> {
> trace(Reflect.compareMethods(function(){}, function(){})); // false
> trace(Reflect.compareMethods(getFunction(), getFunction())); // true
> }
>
> static function getFunction()
> {
> return function(){};
> }
> }
>
> I would expect the second compare to trace false as getFunction returns a new method each time you call it.

That seems quite normal to me : getFunction returns two different
values, but both these values reference the same function (the one
declared in getFunction).

Best,
Nicolas



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

Re: Neko compareMethods behavior

David Peek-2
Normal for neko, maybe, but not consistent with js or swf ;)

How does adding an expression that references a local var change it into a new reference? (see my last email)

dp

On 10/10/2011, at 5:21 AM, "Nicolas Cannasse" <[hidden email]> wrote:

> Le 09/10/2011 11:52, David Peek a écrit :
>> Hi list,
>>
>> Can anyone explain the following behaviour in neko?
>>
>> class Main
>> {
>>    public static function main()
>>    {
>>        trace(Reflect.compareMethods(function(){}, function(){})); // false
>>        trace(Reflect.compareMethods(getFunction(), getFunction())); // true
>>    }
>>
>>    static function getFunction()
>>    {
>>        return function(){};
>>    }
>> }
>>
>> I would expect the second compare to trace false as getFunction returns a new method each time you call it.
>
> That seems quite normal to me : getFunction returns two different values, but both these values reference the same function (the one declared in getFunction).
>
> Best,
> Nicolas
>
>
>
> --
> 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: Neko compareMethods behavior

Nicolas Cannasse
Le 09/10/2011 22:48, David Peek a écrit :
> Normal for neko, maybe, but not consistent with js or swf ;)
>
> How does adding an expression that references a local var change it into a new reference? (see my last email)

Well it was designed to be used to compare _methods_ not actual functions ;)

Best,
Nicolas

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

Re: Neko compareMethods behavior

David Peek-2
OK, fair response :) So, is this just one of those cases where Std will remain not so Std? ;) Will document in wiki if that's the case.

dp

On 10/10/2011, at 8:53 AM, Nicolas Cannasse wrote:

> Le 09/10/2011 22:48, David Peek a écrit :
>> Normal for neko, maybe, but not consistent with js or swf ;)
>>
>> How does adding an expression that references a local var change it into a new reference? (see my last email)
>
> Well it was designed to be used to compare _methods_ not actual functions ;)
>
> Best,
> Nicolas
>
> --
> 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: Neko compareMethods behavior

Nicolas Cannasse

David Peek <[hidden email]> a écrit :

>OK, fair response :) So, is this just one of those cases where Std will
>remain not so Std? ;) Will document in wiki if that's the case.
>
>dp
>
>On 10/10/2011, at 8:53 AM, Nicolas Cannasse wrote:
>
>> Le 09/10/2011 22:48, David Peek a écrit :
>>> Normal for neko, maybe, but not consistent with js or swf ;)
>>>
>>> How does adding an expression that references a local var change it
>into a new reference? (see my last email)
>>
>> Well it was designed to be used to compare _methods_ not actual
>functions ;)
>>
>> Best,
>> Nicolas
>>
>> --
>> haXe - an open source web programming language
>> http://haxe.org
>
>
>--
>haXe - an open source web programming language
>http://haxe.org

Yes

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