[nem-en] usesite

Kamil Skalski kamil.skalski at gmail.com
Tue Feb 13 18:56:33 CET 2007


It makes the created name bind to fields in class, breaking hygiene of
macro generated expressions. This makes compiler look at the name as
it was created plainly in contex of macro use-site.  For example
following should not work (though I'm not really sure this feature
survived till now):

class X {
  x : int;
  bar () : void {
     WriteLine (m ())
  }
}

macro m () {
  <[ x ]>
}

but following should:

macro m () {
   <[  $(x : usesite) ]>
}


The hygiene of macros is most of the time used to prevent mixing macro
defined variables with variables defined in normal code. It is less
clear how it should behave if the symbol is not defined as local
variable but available more or less "globally"  (a field, or type name
visible in the context).

So, in the snippet  "usesite" is a default way of referencing to
things, if you want to be sure that the reference won't be "isolated"
by compiler.

2007/2/13, Vladimir Reshetnikov <V.Reshetnikov at gmail.com>:
> What does 'usesite' mean here (core.n):
>
>   [Nemerle.MacroUsage (Nemerle.MacroPhase.WithTypedMembers,
>                        Nemerle.MacroTargets.Class,
>                        Inherited = false, AllowMultiple = false)]
>   macro StructuralHashCode (t : TypeBuilder) {
>     def flds = t.GetFields (BindingFlags.Public %| BindingFlags.NonPublic %
> |
>                             BindingFlags.Instance %| BindingFlags.DeclaredOnly);
>
>     def body =
>       List.FoldLeft (flds, <[ 0 ]>, fun (x : IField, acc) {
>         <[ $acc %^ $(x.Name : usesite).GetHashCode () ]>
>       });
>     t.Define (<[ decl:
>       public override GetHashCode () : int {
>         $body
>       }
>     ]>);
>   }
>
>
>
>
> _______________________________________________
> https://nemerle.org/mailman/listinfo/devel-en
>


-- 
Kamil Skalski
http://nazgul.omega.pl



More information about the devel-en mailing list