Will macros just be syntactic sugar? [EXAMPLE]
Don Clugston
dac at nospam.com.au
Wed Apr 25 08:10:37 PDT 2007
Davidl wrote:
> Nice work!
> The compiler now is damned powerful :)
>
> Though I still prefer less string operation in compile time,
Yes. I think that's the key improvement to make.
any idea of
> improving the
> macro syntax I posted? You see, D is going to bring AST macro in future
> releases. Let's
> discuss the syntax it will use?
To the user, we should eliminate the quotes, and the mixin().
My example was a bit specific. Let's consider lazy evaluation.
void logging(bool bLog, lazy char [] msg);
which shouldn't evaluate msg unless bLog is true.
With my method, it would be:
bool bActive=true;
mixin(logging(`bActive, getFromDatabase("db", "downtime", event)`));
Obviously, we want to get rid of the mixin() and the ``. But that's
probably the only thing we need to do, outside of library code.
Once we get rid of the ``, we have the requirement that all macro
arguments must be syntactically valid D code. This makes things like
your := impossible.
Then we have:
macro logging(char [][] args)
{
return `if (` ~ args[0].stringof ~ `) printf("%s", ` ~
args[1].stringof ~ `);`;
}
(macros always return a char [], which is mixed in).
But that will look pretty awful if you want to do more than a single
function call. OTOH, if we just get rid of the ``, we lose the ability
to make decisions at compile time.
What then??
More information about the Digitalmars-d
mailing list