[nem-en] Late Binding in Nemerle

Snaury snaury at gmail.com
Sat Jul 1 16:33:42 CEST 2006


Hi everyone,

I was trying to grok nemerle's macros for some time when an idea
suddenly popped in my mind how I could do late binding aka dynamic
typing aka duck typing in a pretty simple and (maybe?) rich way. So I
wrote a macro for this, source code here:
http://www.furry.ru/kitsu/nemerle/Kitsu.LateBindingMacro.n.txt

It allows to use late binding on (I think) any expression, you just
have to wrap it with late, and use like this:

  late(expr).CallMe(param1, param2, param3).CallOtherMe(param, param,
param).Property[param, param, param] = value

It also supports ref/out and named parameters:

  late(expr).CallMe(namedparameter = ref variable, out variable, and
the like...)

though one needs to be very careful with named parameters, because
when you name a parameter, other (unnamed) parameters might get
shifted, for example in function:

  public void SomeFunc(a : int, b : int) : void

when you use

  late(obj).SomeFunc(v1, a = v2)

SomeFunc will be called as SomeFunc(v2, v1), i.e. it won't produce any
errors, it would just silently accept it.

Also, there's not much error checking there (and to be honest I don't
even know how I can do more error checking from within a macro), and
if something goes wrong, you'll probably won't even know where exactly
error happend, none the less I was extremely amazed at WHAT I could do
with Nemerle's macro syntax so I though I'd share it with other people
like me, who might really need to use late binding in their programs.
=^_^=

Now I can say it even more: Nemerle Rocks!

P.S.
If someone can help me to improve it, help in form of patches would be
greatly appreciated :)

P.P.S.

When I was searching the net on any info about duck typing in Nemerle
I occasionaly found this particular statement:

http://nemerle.org/irc/nemerle-2006-01-09
13:50 <malekith> the main differences between boo and nemerle is that
we do not allow dynamic typing to sneak at without notice, we have
better support for metaprogramming (quotations) and compiler written
in Nemerle (booc is in C#)

After reading it I'm even a little scared if my idea of dynamic typing
would be met with knifes and banished like something evil. All I'm
trying to do is to give power when one needs it, especially when one
*really* needs it. x_x



More information about the devel-en mailing list