It would need to be either
def x = newObject("Hello World") with { Foo = "Bar" ; Bar = "Foo" }
or
def x = newObject("Hello World") with ( Foo = "Bar" , Bar = "Foo" )
to play well with the supported syntax in Nemerle.
I have made a macro like this before, so it is possible. My
implementation probably sucks, but it worked for me!
// Object initializer syntax
// Foo() with { Bar = 42; Buz = "hello" }
public macro @with (obj, assignmentExprs)
{
try {
def createTemp = <[ def temp = $obj ]>;
def assignments(xs)
{
| <[ $(name : name) = $value ]> :: xs => <[ temp.$
(Splicable.Name(name)) = $value ]> : PExpr :: assignments(xs);
| [] => [<[ temp ]> : PExpr];
| _ => throw Exception("'with' must be given a
Sequence of assignment statements.");
};
def exprs = match (assignmentExprs)
{
| PExpr.Sequence(elements) => elements;
| _ => throw Exception("'with' must be given a
Sequence of assignment statements.");
};
<[ { .. $( createTemp :: assignments(exprs) ) } ]>
} catch {
| ex => Message.Error(ex.Message); <[ ]>