[nem-en] [macro] building setter body
Kamil Skalski
kamil.skalski at gmail.com
Thu Mar 8 20:53:56 CET 2007
I guess the problem is that implicit 'value' parameter is a fresh
variable name, which cannot be used by "external" (that is not defined
in the same macro execution as that parameter) symbol you have in
attribute.
Try specifying body of setter as:
<[ def $("value" : usesite) = value;
when ($(args.Nth(0)))
$setter_body; ]>;
It works and is in a way reasonable... but I agree, it is not very
user friendly. Just consequence of symbol hygiene.
2007/3/8, Sergey Shishmintzev <sergey.shishmintzev at gmail.com>:
> Hi,
> I want to enhance Accessor macro. Here sample for test case:
> // code:
> [Nemerle.MacroUsage (Nemerle.MacroPhase.BeforeInheritance,
> Nemerle.MacroTargets.Field,
> Inherited = false, AllowMultiple = true)]
> macro PropertyBuilder (current_type : TypeBuilder, storage_field :
> ParsedField, params args : list [PExpr])
> {
> def evnt_name = storage_field.Name+"_Changed";
> mutable setter_body = <[ $(evnt_name : dyn)(); ]>;
> unless (args.IsEmpty)
> setter_body =
> <[ when ($(args.Nth(0)))
> $setter_body; ]>;
> def prop = <[ decl:
> public $(storage_field.Name+"_Prop" : dyn) : $(storage_field.ty)
> {
> set { $setter_body }
> }
> ]>;
> current_type.Define (prop);
> }
>
> // usage:
> public class Model2
> {
> [PropertyBuilder(field2 != value)]
> public mutable field2 : string;
> public field2_Changed() : void {};
> }
>
> Problem:
> ncc.exe says "error: unbound name `value'"
>
> Any solutions?
> --
> Serg
>
> _______________________________________________
> https://nemerle.org/mailman/listinfo/devel-en
>
--
Kamil Skalski
http://nazgul.omega.pl
More information about the devel-en
mailing list