feature request: __ARGS__ for logging (cf __FILE__, __LINE__, __FUNC___)

Timon Gehr timon.gehr at gmx.ch
Wed Feb 6 05:05:53 PST 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.)




More information about the Digitalmars-d mailing list