this, me and __this__

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

Re: this, me and __this__

Franco Ponticelli
I basically need to the above and this must represent my instance of Foo.


It does, what's the problem with that?

Franco 


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

Re: this, me and __this__

Geoffrey Hug
Well then I'll post the code :

public function identify( text : String, image : String, language : String )
    {
        if( this.name == null )
        {   
            trace( text + " : " + image + " " + language );
            this.name = text;
            this.img = image;
            this.lang = language;
           
            try
            {
                trace( this );
            }
            catch( er : Dynamic )
            {
                trace( er );
            }
           
            try
            {
                FruttiServer.join( this );
            }
            catch( e : Dynamic )
            {
                trace( e );
            }
           
           
        }
       
    }

The line "trace( this )" triggers an error but all i get is "PlayerServer.hx:55: null", the line "FruttiServer.join( this )" triggers an error too : "C stack overflow"

If I remove the try catch then I get an error from the "trace( this )" that seem to loop

Called from /usr/lib/haxe/std/neko/_std/String.hx line 26
Called from /usr/lib/haxe/std/neko/_std/Hash.hx line 52
Called from a C function
Called from /usr/lib/haxe/std/neko/_std/Hash.hx line 52
Called from /usr/lib/haxe/std/neko/_std/Hash.hx line 65
Called from /usr/lib/haxe/std/neko/_std/Hash.hx line 26
Called from a C function
Called from /usr/lib/haxe/std/neko/_std/Std.hx line 33
Called from /usr/lib/haxe/std/neko/_std/Hash.hx line 69
Called from /usr/lib/haxe/std/neko/_std/Hash.hx line 26
Called from a C function

The 4 last lines repeat all the time before I get another error ( Invalid field access )

2011/8/1 Franco Ponticelli <[hidden email]>
I basically need to the above and this must represent my instance of Foo.


It does, what's the problem with that?

Franco 


--
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: this, me and __this__

laurence taylor
Looks to me like you've got a circular reference somewhere (FruttiServer), and a recursive call that doesn't null check it's leaves( trace("this") ). Look at the toString() method.

regards,
Laurence

On Tue, Aug 2, 2011 at 10:37 AM, Geoffrey Hug <[hidden email]> wrote:
Well then I'll post the code :

public function identify( text : String, image : String, language : String )
    {
        if( this.name == null )
        {   
            trace( text + " : " + image + " " + language );
            this.name = text;
            this.img = image;
            this.lang = language;
           
            try
            {
                trace( this );
            }
            catch( er : Dynamic )
            {
                trace( er );
            }
           
            try
            {
                FruttiServer.join( this );
            }
            catch( e : Dynamic )
            {
                trace( e );
            }
           
           
        }
       
    }

The line "trace( this )" triggers an error but all i get is "PlayerServer.hx:55: null", the line "FruttiServer.join( this )" triggers an error too : "C stack overflow"

If I remove the try catch then I get an error from the "trace( this )" that seem to loop

Called from /usr/lib/haxe/std/neko/_std/String.hx line 26
Called from /usr/lib/haxe/std/neko/_std/Hash.hx line 52
Called from a C function
Called from /usr/lib/haxe/std/neko/_std/Hash.hx line 52
Called from /usr/lib/haxe/std/neko/_std/Hash.hx line 65
Called from /usr/lib/haxe/std/neko/_std/Hash.hx line 26
Called from a C function
Called from /usr/lib/haxe/std/neko/_std/Std.hx line 33
Called from /usr/lib/haxe/std/neko/_std/Hash.hx line 69
Called from /usr/lib/haxe/std/neko/_std/Hash.hx line 26
Called from a C function

The 4 last lines repeat all the time before I get another error ( Invalid field access )

2011/8/1 Franco Ponticelli <[hidden email]>
I basically need to the above and this must represent my instance of Foo.


It does, what's the problem with that?

Franco 


--
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: this, me and __this__

Geoffrey Hug
FruttiServer creates a new PlayerServer in the initClientApi method and then adds it to the context. When I call my join() function I pass my PlayerServer instance.
Could it be related ?

I'm not sure I understand what you mean by circular reference and a recursive call that doesn't null check it's leaves( trace("this") )
--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: this, me and __this__

Nicolas Cannasse
In reply to this post by Nicolas Cannasse
Le 27/07/2011 21:15, Nicolas Cannasse a écrit :
> Hi list,
>
> An important change that I want to make in haXe is to remove the need to
> declare a "me" variable in order to access "this" in local functions:

r3906 now allows it !

The only transitional error is that if "this" is used in "untyped" mode
inside a local function then you'll have to use either __this__ or "var
me = this"

Enjoy !

Nicolas

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

Re: this, me and __this__

Benjamin Dasnois
Hi,

Great move!

The only problem I see has to do with the drawback you've mentioned. Since it is in an untyped block, the compiler won't be of any help here.
Do you think you could add a warning when people are accessing this inside an untyped block in order to help finding those places?

Regards,

On Fri, Aug 12, 2011 at 10:55 AM, Nicolas Cannasse <[hidden email]> wrote:
Le 27/07/2011 21:15, Nicolas Cannasse a écrit :

Hi list,

An important change that I want to make in haXe is to remove the need to
declare a "me" variable in order to access "this" in local functions:

r3906 now allows it !

The only transitional error is that if "this" is used in "untyped" mode inside a local function then you'll have to use either __this__ or "var me = this"

Enjoy !


Nicolas

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



--
DASNOIS Benjamin
http://www.benjamindasnois.com

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

Re: this, me and __this__

bubblebenj
In reply to this post by Nicolas Cannasse
So now we can do (if using svn build r3906) :
public function() {
Lambda.iter( myIterable, function(x) {
__this__.doSomethingOnThisVar(x);
}
}
instead of
public function() 
{
var me = this;
Lambda.iter( myIterable, function(x) {
me.doSomethingOnThisVar(x);
}
}
?

Ben

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

Re: this, me and __this__

John Plsek
I believe it's actually simpler


public function() {
Lambda.iter( myIterable, function(x) {
this.doSomethingOnThisVar(x);
}
}

from what I understand, __this__ is only required in an untyped block

I could be wrong (I usually am ;) )

J

On 12 August 2011 19:08, benjamin Dubois <[hidden email]> wrote:
So now we can do (if using svn build r3906) :
public function() {
Lambda.iter( myIterable, function(x) {
__this__.doSomethingOnThisVar(x);
}
}
instead of
public function() 
{
var me = this;
Lambda.iter( myIterable, function(x) {
me.doSomethingOnThisVar(x);
}
}
?

Ben

--
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: this, me and __this__

Michiel Crefcoeur
I believe it's actually even simpler-er!
you don't need the ""this." part, right?


2011/8/12 John Plsek <[hidden email]>
I believe it's actually simpler



public function() {
Lambda.iter( myIterable, function(x) {
this.doSomethingOnThisVar(x);
}
}

from what I understand, __this__ is only required in an untyped block

I could be wrong (I usually am ;) )

J

On 12 August 2011 19:08, benjamin Dubois <[hidden email]> wrote:
So now we can do (if using svn build r3906) :
public function() {
Lambda.iter( myIterable, function(x) {
__this__.doSomethingOnThisVar(x);
}
}
instead of
public function() 
{
var me = this;
Lambda.iter( myIterable, function(x) {
me.doSomethingOnThisVar(x);
}
}
?

Ben

--

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: this, me and __this__

Nicolas Cannasse
Le 12/08/2011 11:30, Michiel Crefcoeur a écrit :
> I believe it's actually even simpler-er!
> you don't need the ""this." part, right?

Yes.

Nicolas

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

Re: this, me and __this__

Nicolas Cannasse
In reply to this post by Benjamin Dasnois
Le 12/08/2011 11:01, Benjamin Dasnois a écrit :
> Hi,
>
> Great move!
>
> The only problem I see has to do with the drawback you've mentioned.
> Since it is in an untyped block, the compiler won't be of any help here.
> Do you think you could add a warning when people are accessing this
> inside an untyped block in order to help finding those places?

The compiler knows if we are in an untyped block. It will give an error
only in that case.

Nicolas

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

Re: this, me and __this__

bubblebenj
Ho, nice improvement.

But even if the compilator complain, I still don't in which situation I'll have to use __this__, I mean "what is an untyped block ?".

Ben

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

Got a failing case..

sledorze
In reply to this post by Nicolas Cannasse
This one, using a nested function is failing (me is not created).

class Main {
        function bar() {
        }
       
        public function new() {
                function foo() {
                        return function () {
                                bar();
                        };
                }
                foo()();
        }
       
       
        static function main() {
                new Main();
        }
}
Reply | Threaded
Open this post in threaded view
|

Re: Got a failing case..

sledorze
Oh.. was using latest trunk and JS target.
Reply | Threaded
Open this post in threaded view
|

Re: Got a failing case..

Andreas Mokros
In reply to this post by sledorze
Hi.

On Sat, 13 Aug 2011 01:17:51 -0700 (PDT)
sledorze <[hidden email]> wrote:
> This one, using a nested function is failing (me is not created).

If new() creates the instance, it maybe doesn't exist yet?

--
Mockey

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

Re: Got a failing case..

sledorze
The problem is 
Var me = this;
Is not generated, so the problem is more general, and not related to the constructor example. In addition i would be surprised if this is not bound at this stage.. (highly surprised).

In addition; i am not a big fan of the 'me' name; i think it's better to use already known names from other languages from the past.. Just to make haxe more familiar for the majority.. ( thinking about 'self' or 'thiz' as a conventional 's' by 'z' substitution borrowed from java conventions. Still i prefer the former, and still i prefer it behaves well whatever it's name :) )


Sent from my iPhone

On 13 août 2011, at 15:46, "Andreas Mokros [via Haxe]" <[hidden email]> wrote:

Hi.

On Sat, 13 Aug 2011 01:17:51 -0700 (PDT)
sledorze <[hidden email]> wrote:
> This one, using a nested function is failing (me is not created).

If new() creates the instance, it maybe doesn't exist yet?

--
Mockey

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



If you reply to this email, your message will be added to the discussion below:
http://haxe.1354130.n2.nabble.com/this-me-and-this-tp6627392p6683234.html
To unsubscribe from this, me and __this__, click here.
Reply | Threaded
Open this post in threaded view
|

Re: Got a failing case..

Andreas Mokros
Hi.

On Sat, 13 Aug 2011 07:00:51 -0700 (PDT)
sledorze <[hidden email]> wrote:
> In addition i would be surprised if this is not bound
> at this stage.. (highly surprised).

Hmm, don't know about JS. Might be something wrong with the compiler.
But I played around a bit with this feature in neko. And while this
works:

function test() {
  function foo() return bar;
  foo()();
}

static function main() {
  var m = new Main();
  m.test();
}

this fails:

function new() {
  function foo() return bar;
  foo()();
}

static function main() {
  var m = new Main();
}

with invalid field access: bar (at runtime).
Also:

function new() {
  var foo = function() trace(this);
  foo();
}

traces null.

--
Mockey

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

Re: Got a failing case..

sledorze
Indeed, another try using JS reveals this problem is related to a direct usage in the constructor.
putting the code in another ('init' for instance) method makes the 'var me = this;' code generated properly.

Would have loved to have an error/warning at least..


Reply | Threaded
Open this post in threaded view
|

Re: Got a failing case..

Nicolas Cannasse
Le 15/08/2011 10:52, sledorze a écrit :
> Indeed, another try using JS reveals this problem is related to a direct
> usage in the constructor.
> putting the code in another ('init' for instance) method makes the 'var me =
> this;' code generated properly.
>
> Would have loved to have an error/warning at least..

This was a bug, been fixed on SVN (r3912)

Nicolas

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

Re: Got a failing case..

sledorze
Great! Will be able to remove a lot of boilerplate! :)

Sent from my iPhone

On 15 août 2011, at 10:59, "Nicolas Cannasse [via Haxe]" <[hidden email]> wrote:

Le 15/08/2011 10:52, sledorze a écrit :
> Indeed, another try using JS reveals this problem is related to a direct
> usage in the constructor.
> putting the code in another ('init' for instance) method makes the 'var me =
> this;' code generated properly.
>
> Would have loved to have an error/warning at least..

This was a bug, been fixed on SVN (r3912)

Nicolas

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



If you reply to this email, your message will be added to the discussion below:
http://haxe.1354130.n2.nabble.com/this-me-and-this-tp6627392p6686774.html
To unsubscribe from this, me and __this__, click here.
12