Looking for a macro API to extract free variables from an expression?

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

Looking for a macro API to extract free variables from an expression?

sledorze
has anyone done it already?

Thanks,
Stephane
Reply | Threaded
Open this post in threaded view
|

Re: Looking for a macro API to extract free variables from an expression?

Cauê W.
what do you mean with free variables?

2011/11/2 sledorze <[hidden email]>
has anyone done it already?

Thanks,
Stephane


--
View this message in context: http://haxe.1354130.n2.nabble.com/Looking-for-a-macro-API-to-extract-free-variables-from-an-expression-tp6955161p6955161.html
Sent from the Haxe mailing list archive at Nabble.com.

--
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: Looking for a macro API to extract free variables from an expression?

Juraj Kirchheim
It's a concept from lambda calculus. Given haXe's syntax it's a bit
less clear than in Lisp for example.
Consider the following expression:

{
     var a;
     function b() return b+x;
     b(a);
     b(y);
     for (i in z) b(i);
     b(i);
}

In that example x,y and z are free, while a,b are bound. As for i, it
is bound within the body of the for loop, but not in the last
statement of the block.

Basically a variable is free within a given scope, if it is "undefined".

Given haXe's relatively rich syntax compared to lambda expressions
(meaning those in lambda calculus) and given that in haXe an
identifier is not necessarily a variable, this concept has to be bent
a little to be applied to haXe.

On Wed, Nov 2, 2011 at 3:43 PM, Cauê Waneck <[hidden email]> wrote:

> what do you mean with free variables?
>
> 2011/11/2 sledorze <[hidden email]>
>>
>> has anyone done it already?
>>
>> Thanks,
>> Stephane
>>
>>
>> --
>> View this message in context:
>> http://haxe.1354130.n2.nabble.com/Looking-for-a-macro-API-to-extract-free-variables-from-an-expression-tp6955161p6955161.html
>> Sent from the Haxe mailing list archive at Nabble.com.
>>
>> --
>> 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: Looking for a macro API to extract free variables from an expression?

sledorze
In reply to this post by Cauê W.
I think Juraj explained it well.. :)

Intuitively;
They're the identifiers with the name of the parameters of the function with which you need to wrap the expression so that the compiler would not complain about unbound identifiers.
(as you just bound them by introducing them into the scope via the parameters).

like that:

given this body:

var x = y + 5;

=>

function (y) { // this body had one free variable; y.
  var x = y +5;
}

So? got that in your libraries?
Reply | Threaded
Open this post in threaded view
|

Re: Looking for a macro API to extract free variables from an expression?

Cauê W.
In reply to this post by Juraj Kirchheim
oh I've done exactly this at http://code.google.com/p/hxmessages/source/browse/trunk/src/haxe/async/Yield.hx#317

just change "y.changeVar" for your desired code when an unbound var is found. By the way, I've just realized I missed two cases there: for(x in y) , x is declared, and function(x) x is also declared. Anyway, it's quite easy to change

2011/11/2 Juraj Kirchheim <[hidden email]>
It's a concept from lambda calculus. Given haXe's syntax it's a bit
less clear than in Lisp for example.
Consider the following expression:

{
    var a;
    function b() return b+x;
    b(a);
    b(y);
    for (i in z) b(i);
    b(i);
}

In that example x,y and z are free, while a,b are bound. As for i, it
is bound within the body of the for loop, but not in the last
statement of the block.

Basically a variable is free within a given scope, if it is "undefined".

Given haXe's relatively rich syntax compared to lambda expressions
(meaning those in lambda calculus) and given that in haXe an
identifier is not necessarily a variable, this concept has to be bent
a little to be applied to haXe.

On Wed, Nov 2, 2011 at 3:43 PM, Cauê Waneck <[hidden email]> wrote:
> what do you mean with free variables?
>
> 2011/11/2 sledorze <[hidden email]>
>>
>> has anyone done it already?
>>
>> Thanks,
>> Stephane
>>
>>
>> --
>> View this message in context:
>> http://haxe.1354130.n2.nabble.com/Looking-for-a-macro-API-to-extract-free-variables-from-an-expression-tp6955161p6955161.html
>> Sent from the Haxe mailing list archive at Nabble.com.
>>
>> --
>> 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


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

Re: Looking for a macro API to extract free variables from an expression?

sledorze
oh tanks! I'll check that a little later today (after work job) :)

2011/11/2 Cauê W. [via Haxe] <[hidden email]>
oh I've done exactly this at http://code.google.com/p/hxmessages/source/browse/trunk/src/haxe/async/Yield.hx#317

just change "y.changeVar" for your desired code when an unbound var is found. By the way, I've just realized I missed two cases there: for(x in y) , x is declared, and function(x) x is also declared. Anyway, it's quite easy to change

2011/11/2 Juraj Kirchheim <[hidden email]>

It's a concept from lambda calculus. Given haXe's syntax it's a bit
less clear than in Lisp for example.
Consider the following expression:

{
    var a;
    function b() return b+x;
    b(a);
    b(y);
    for (i in z) b(i);
    b(i);
}

In that example x,y and z are free, while a,b are bound. As for i, it
is bound within the body of the for loop, but not in the last
statement of the block.

Basically a variable is free within a given scope, if it is "undefined".

Given haXe's relatively rich syntax compared to lambda expressions
(meaning those in lambda calculus) and given that in haXe an
identifier is not necessarily a variable, this concept has to be bent
a little to be applied to haXe.

On Wed, Nov 2, 2011 at 3:43 PM, Cauê Waneck <[hidden email]> wrote:
> what do you mean with free variables?
>
> 2011/11/2 sledorze <[hidden email]>
>>
>> has anyone done it already?
>>
>> Thanks,
>> Stephane
>>
>>
>> --
>> View this message in context:
>> http://haxe.1354130.n2.nabble.com/Looking-for-a-macro-API-to-extract-free-variables-from-an-expression-tp6955161p6955161.html
>> Sent from the Haxe mailing list archive at Nabble.com.
>>
>> --
>> 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


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


To unsubscribe from Looking for a macro API to extract free variables from an expression?, click here.



--
Stéphane Le Dorze