February 06, 2013
On 2013-02-05 12:05, Timon Gehr wrote:

> As far as my understanding goes, quasi-quoting is hygienic, and manual
> AST building provides both options.

Yes, that's usually how it works.

> We could provide all nested scopes in an array as part of the context.
>
> macro foo(Context context){
>      return<[
>          context.scopes[0].x++;
>          context.scopes[1].x++;
>      ]>;
> }
> int x = 2;
> void main(){
>      int x=0;
>      foo();
>      assert(x==1 && .x==3);
> }

How would one navigate these scopes. How would one know which one to use? If I recall correctly Nemerle has a way to indicate a symbol should refer to a symbol at the call site which has the closest lexical scope.

We would need a way to introduce a new symbol which does not leak outside the macro and another way to explicitly say the symbol is available outside the macro at call site.

So if I do something like:

int x;

macro foo (Context context)
{
    int y;
    return <[
        x++;
        y++;
    ]>;
}

The above would increment "x" and "y" available in the macro context and not refer to any symbols at the call site?

-- 
/Jacob Carlborg
February 06, 2013
On 2013-02-05 12:12, Timon Gehr wrote:

> Eg:
>
> if ast == <[2*x]>, then the result will be <[x+x]>
> if ast == <[y+2]>, then the result will be <[2+y]>

How does the matching syntax work, like regular expression?

-- 
/Jacob Carlborg
February 06, 2013
On 02/06/2013 08:57 AM, Jacob Carlborg wrote:
> On 2013-02-05 12:12, Timon Gehr wrote:
>
>> Eg:
>>
>> if ast == <[2*x]>, then the result will be <[x+x]>
>> if ast == <[y+2]>, then the result will be <[2+y]>
>
> How does the matching syntax work, like regular expression?
>

Just like pattern matching usually works. '?a' identifiers are matched to subterms. (This is necessary because 'a' will match a symbol.)
February 06, 2013
On 02/06/2013 08:48 AM, Jacob Carlborg wrote:
> On 2013-02-05 12:05, Timon Gehr wrote:
>
>> As far as my understanding goes, quasi-quoting is hygienic, and manual
>> AST building provides both options.
>
> Yes, that's usually how it works.
>
>> We could provide all nested scopes in an array as part of the context.
>>
>> macro foo(Context context){
>>      return<[
>>          context.scopes[0].x++;
>>          context.scopes[1].x++;
>>      ]>;
>> }
>> int x = 2;
>> void main(){
>>      int x=0;
>>      foo();
>>      assert(x==1 && .x==3);
>> }
>
> How would one navigate these scopes. How would one know which one to
> use? If I recall correctly Nemerle has a way to indicate a symbol should
> refer to a symbol at the call site which has the closest lexical scope.
>

That would be looking it up in scopes[0]. (Nested scopes continue symbol lookup in the parent scopes.)

The most important cases are scopes[0] and scopes[$-1], the caller scope and the module scope.

> We would need a way to introduce a new symbol which does not leak
> outside the macro and another way to explicitly say the symbol is
> available outside the macro at call site.
>
> So if I do something like:
>
> int x;
>
> macro foo (Context context)
> {
>      int y;
>      return <[
>          x++;
>          y++;
>      ]>;
> }
>
> The above would increment "x" and "y" available in the macro context and
> not refer to any symbols at the call site?
>

Yes, but it is not clear yet what macro closures are exactly (Probably it would make sense to inject the closed over declarations at the call site, without adding them to the scope.)


February 06, 2013
On 2013-02-06 13:56, Timon Gehr wrote:

> Just like pattern matching usually works. '?a' identifiers are matched
> to subterms. (This is necessary because 'a' will match a symbol.)

I don't know how pattern matching usually works that's why I'm asking. But that syntax doesn't look like the ones I've seen, like in Scala.

-- 
/Jacob Carlborg
February 06, 2013
Am 06.02.2013 13:56, schrieb Timon Gehr:
> On 02/06/2013 08:57 AM, Jacob Carlborg wrote:
>> On 2013-02-05 12:12, Timon Gehr wrote:
>>
>>> Eg:
>>>
>>> if ast == <[2*x]>, then the result will be <[x+x]>
>>> if ast == <[y+2]>, then the result will be <[2+y]>
>>
>> How does the matching syntax work, like regular expression?
>>
>
> Just like pattern matching usually works. '?a' identifiers are matched
> to subterms. (This is necessary because 'a' will match a symbol.)

i think regex (which are by design not nested-able) aren't enough for AST handling - because there is much nesting in ASTs

February 06, 2013
On 2013-02-06 14:05, Timon Gehr wrote:

> Yes, but it is not clear yet what macro closures are exactly (Probably
> it would make sense to inject the closed over declarations at the call
> site, without adding them to the scope.)

It's not clear? We want to be able have a macro referring to utility functions and these should be bind at the macro site and not call site.

-- 
/Jacob Carlborg
February 06, 2013
On 02/06/2013 03:23 PM, Jacob Carlborg wrote:
> On 2013-02-06 14:05, Timon Gehr wrote:
>
>> Yes, but it is not clear yet what macro closures are exactly (Probably
>> it would make sense to inject the closed over declarations at the call
>> site, without adding them to the scope.)
>
> It's not clear? We want to be able have a macro referring to utility
> functions and these should be bind at the macro site and not call site.
>

Of course. What I mean by macro closure is the following:

Ast foo(){
    int x = 0;    // a 'closed over' variable
    return <[x]>; // escaping reference
}

macro counter(){ return $(foo())++; }
February 06, 2013
On 02/06/2013 03:57 PM, Timon Gehr wrote:
> On 02/06/2013 03:23 PM, Jacob Carlborg wrote:
>> On 2013-02-06 14:05, Timon Gehr wrote:
>>
>>> Yes, but it is not clear yet what macro closures are exactly (Probably
>>> it would make sense to inject the closed over declarations at the call
>>> site, without adding them to the scope.)
>>
>> It's not clear? We want to be able have a macro referring to utility
>> functions and these should be bind at the macro site and not call site.
>>
>
> Of course. What I mean by macro closure is the following:
>
> Ast foo(){
>      int x = 0;    // a 'closed over' variable
>      return <[x]>; // escaping reference
> }
>
> macro counter(){ return $(foo())++; }

Actually

macro counter(){ return <[$(foo())++]>; }
February 07, 2013
On 2013-02-06 15:57, Timon Gehr wrote:

> Of course. What I mean by macro closure is the following:
>
> Ast foo(){
>      int x = 0;    // a 'closed over' variable
>      return <[x]>; // escaping reference
> }
>
> macro counter(){ return $(foo())++; }

Aha, you mean like that, I see.

-- 
/Jacob Carlborg
1 2 3 4 5
Next ›   Last »