[nem-en] expresion level macro to define methods

Kamil Dworakowski kamil.dworakowski at googlemail.com
Fri Nov 17 19:41:58 CET 2006


It works fine except that it ignores attributes I define for my method. 
I want the method to have [Test] attribute, but it gets lost somehow. Why?

 def a_test = <[
            decl: [Test] public testSth(): void  {
                Assert.IsTrue(false);
            }
        ]>;
        Nemerle.Macros.ImplicitCTX().CurrentType.Define(a_test);

Kamil Dworakowski


Kamil Skalski wrote:
> Yes,
>
> macro MarkWithMy (expr) {
>  Nemerle.Macros.ImplicitCTX().CurrentType.Define ( <[ decl:
>     public MyGeneratedMethod (x : int) : int {
>         x + $expr
>     }
>  ]>);
>  <[ () ]>
> }
>
> but probably if you tried using this method in compilation of current
> class/method (for other classes it might be even more indeterministic
> ;) ), like
>
> macro MarkWithMy (expr) {
>  Nemerle.Macros.ImplicitCTX().CurrentType.Define ( <[ decl:
>     public MyGeneratedMethod (x : int) : int {
>         x + $expr
>     }
>  ]>);
>  <[ MyGeneratedMethod(1) ]>
> }
>
> you might get strange problems...
>
> On 11/17/06, Kamil Dworakowski <kamil.dworakowski at googlemail.com> wrote:
>> Is it possible for an expresion lvl macro to define a method on the
>> enclosing class?
>>
>> Kamil Dworakowski
>>
>> _______________________________________________
>> https://nemerle.org/mailman/listinfo/devel-en
>>
>
>




More information about the devel-en mailing list