[nem-en] A macro-related question

d d at hell.art.pl
Fri Jun 2 22:41:58 CEST 2006


On Jun 2, 2006, at 6:32 PM, Kamil Skalski wrote:

>> Try
>>
>> public RecursiveRename (tc : TypeBuilder, expr : PExpr, from : Name,
>> to : Name) : PExpr
>> or
>>   public TraverseExpr (ctx : option[Typer], expr : PExpr,  
>> in_pattern : bool,
>>                        call : bool * bool * PExpr -> PExpr) : PExpr
>
> Ah, there it is:
> Typer.n
> public AddRedirection (name : PT.Name, subst : PT.PExpr) : void
>
> so in macro you can use:
>
> macro x (y) {
>   def x = Macros.UseSiteSymbol ("tobereplaced");
>   Macros.ImplicitCTX().AddRedirection (x, y);
>   <[ () ]>
> }
>
> and then
>
> x(System.Console.WriteLine ("aa"));
> tobereplaced
>
> would yield printing "aa"
>
> But if you want to replace 'this'... it may be harder. I would try
> mixed approach:
> create redirection (in case somebody use  just 'foo') and replace
> 'this' by using TraverseExpr, so uses like 'this.foo' also gets
> changed.

  There seems to be no documentation for TraverseExpr and some things  
can't really be conjectured from the sources. Like what all the  
arguments are (the function supplied with it's args as well). Could  
you elaborate on that a bit ? AddRedirection and RecursiveRename are  
quite obvious on the other hand. So I'd be grateful for anything  
about TraverseExpr.

thanks,
d

PS. I'm leaving around 5:00 tonight for the weekend, so I'll be quiet  
till Monday..

--
https://hell.art.pl == terror.org.pl == terror.icm.edu.pl/~d/gpg



-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 186 bytes
Desc: This is a digitally signed message part
Url : /mailman/pipermail/devel-en/attachments/20060602/41b491b9/PGP.bin


More information about the devel-en mailing list