[nem-en] Re: Late Binding in Nemerle

Snaury snaury at gmail.com
Wed Jul 5 14:54:40 CEST 2006


Hi everyone!

After talking yesterday to Kamil, a day of hard work, many trials and
fails, I'm proud to present you new incarnation of late macro :)

binary: http://www.furry.ru/kitsu/nemerle/Kitsu.LateBindingMacro.dll
source: http://www.furry.ru/kitsu/nemerle/Kitsu.LateBindingMacro.n

- did a complete rewrite
- late syntax is now as as simple as:

    late (late-expr)
    late late-expr

  where late-expr can be any nemerle expression
  don't even know how to explain formal syntax here :)

    nolate (expr)
    nolate expr

  useful inside of late-expr, where you don't want something to be latebound:

    late {
      ...
      Console.WriteLine(nolate this.Controls.Length);
      ...
    }

  this.* and base.* are not late bound (* is single action: one
set/get/method call):

    this.SomeMethod()          // SomeMethod() is compile time bound
    this.Property.SomeMethod() // Property is compile time bound,
SomeMethod() is late bound

  actions on types are not late bound as well, so you can this without worries:

    Console.WriteLine(...)

- now this macro exposes some kind of public API, might be useful for
some people
  key methods of interest are:

    LateMacro.transform()
    LateMacro.latebound()

  both accept 'deep' paramether so you can save compiler cycles where
you already know that expression will not go deep or when you don't
want it to go deep. Also, when you know that expression doesn't have
any type casts/etc surrounding it, you can just call
LateMacro.latebound() directly (to save cpu cycles, or even to test if
expression is first class late expression). for example, if someone
wants to generate a proxy class, inside of their macro they just call:

    LateMacro.transform(<[ $(object_name : name) . $(method_name :
name) (.. $args) ]>, false)

  false here prevents latebound() to go deeply inside every arg in
args, most likely it will be just names of arguments anyway, so it
will save args.Length calls to LateMacro.transform

If someone can test it thorougly I'll appreciate it would be very good
(I'm not sure if I didn't screw up with some exotic PExpr-s, or missed
some things where it should go deeper).

Kamil and everyone else, big-big thanks for ideas! :)



More information about the devel-en mailing list