[nem-en] Late Binding in Nemerle
Kamil Skalski
kamil.skalski at gmail.com
Thu Jul 20 23:16:26 CEST 2006
MacroCall appears in the parse tree only for macros, which were
recognized by parser, because they were using syntax extension, like
while (x) b ---> MacroCall (whileMacro, x, b)
if (x) y else z ---> MacroCall (ifMacro, x,y,z)
etc.
now if there is a macro just in form of a call:
Nemerle.IO.print (x)
it is recognized only later by typer. But we can ask the compiler if
given expression ('Nemerle.IO.print') is a reference to macro in given
context.
On 7/20/06, Snaury <snaury at gmail.com> wrote:
> Huh?
>
> (after testing) Hmm, I thought these lines:
>
> | _ =>
> def recurse_parm(parm)
> | SyntaxElement.Expression(expr) =>
> SyntaxElement.Expression(recurse(expr))
> | _ => parm
> PExpr.MacroCall(loc, name, ns, parms.Map(recurse_parm))
>
> Would do the job... waiting to see how you'll fix this, then. :)
>
> On 7/21/06, Kamil Skalski <kamil.skalski at gmail.com> wrote:
> > Ok, I will commit it sometime tomorrow. I've also made some
> > improvements to handle static methods and I'm plannig to support
> > macros also:
> >
> > late
> > def x = foo.bar;
> > System.Console.WriteLine (x)
> > Nemerle.IO.print ("$x\n") // print is a macro
> >
> > On 7/20/06, Snaury <snaury at gmail.com> wrote:
> > > It's fine for me. :)
> > >
> > > However, with current implementation it seems one must avoid named
> > > parameters for .NET classes (for ComObjects named parameters work fine
> > > though [on MS.NET, never tested on Mono] and for MarshalByRefObjects I
> > > just didn't test it). DefaultBinder in MS.NET has a horrible bug which
> > > sometimes passes named parameters in wrong order, and Mono's
> > > DefaultBinder doesn't currently support named parameters at all.
> > >
> > > Consider example:
> > >
> > > public class TestClass
> > > public Method(a : int, b : int, c : int = 3) : int
> > > printf("TestClass.Method(%d,%d,%d)\n", a, b, c)
> > > a + b + c
> > >
> > > def t = TestClass()
> > > def o = t : object
> > > def n = late o.Method(c = 1, a = 2, b = 3) :> int
> > > printf("Got result: %d\n", n)
> > >
> > > On MS.NET:
> > > TestClass.Method(3,1,2)
> > > Got result: 6
> > > On Mono:
> > > TestClass.Method(1,2,3)
> > > Got result: 6
> > >
> > > Both are wrong of course (but I must say that MS.NET doesn't *always*
> > > get order wrong, if there are less that 3 named parameters they will
> > > always be correct, btw). Not that I want to scare you, but I just want
> > > to mention it before you put it to nemerle codebase (even though these
> > > are *not* my bugs, but bugs of underlying implementations). To fix
> > > this on both platforms I'd need to implement my own (correct) binder,
> > > which is a huge work, will impact performance, and I'm still weighing
> > > whether I want to code all of this or just wait when both parties fix
> > > their binders...
> > >
> > > Anyway, you're welcome to include it. :) Just in case, because I don't
> > > know what version you currently have, fresh version can be taked from
> > > http://snaury.googlepages.com/Kitsu.Latebinding (old link just
> > > redirects here, though)
> > >
> > > On 7/20/06, Kamil Skalski <kamil.skalski at gmail.com> wrote:
> > > > Well, I played a bit with the late binding macros and they work nice. :-)
> > > > What do you thing about including them into Nemerle standard macros?
> > > >
> > > > For example under namespace Nemerle.Late;
> > >
> > > _______________________________________________
> > > https://nemerle.org/mailman/listinfo/devel-en
> > >
> >
> >
> > --
> > Kamil Skalski
> > http://nazgul.omega.pl
> >
> > _______________________________________________
> > https://nemerle.org/mailman/listinfo/devel-en
> >
>
> _______________________________________________
> https://nemerle.org/mailman/listinfo/devel-en
>
--
Kamil Skalski
http://nazgul.omega.pl
More information about the devel-en
mailing list