[nem-en] expresion level macro to define methods

Kamil Dworakowski kamil.dworakowski at googlemail.com
Fri Nov 17 20:16:06 CET 2006


Kamil Skalski wrote:
> Which version of compiler are you using? If it is with svn, then you
> should file a bug report.

I used 0.9.3.

I just checked that it works properly with the compiler built from the 
latest source.

> As a workaround you shoud be able to use:
>
> def mem_builder =
> Nemerle.Macros.ImplicitCTX().CurrentType.DefineAndReturn(a_test);
> mem_builder.GetModifiers().AddCustomAttribute (<[ Test ]>);

That didn't help; still no attribute on the method. But, as I wrote 
above, it is all fine with the compiler from the latest revision.

Kamil Dworakowski
>
> On 11/17/06, Kamil Dworakowski <kamil.dworakowski at googlemail.com> wrote:
>> 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
>> >>
>> >
>> >
>>
>>
>> _______________________________________________
>> https://nemerle.org/mailman/listinfo/devel-en
>>
>
>




More information about the devel-en mailing list