Will macros work with expressions?
Bill Baxter
dnewsgroup at billbaxter.com
Mon Sep 3 00:04:29 PDT 2007
Xinok wrote:
> Bill Baxter wrote:
>> A question about the upcoming macros:
>> Will they work for expressions as well as statements?
>>
>> The examples in WalterAndrei.pdf all show complete statements,
>> like
>> macro foo(e) { e=3; }
>>
>> But will it be possible to have:
>> macro foo(e) { e+3 }
>>
>> I hope expressions will be allowed. Not for things like e+3 but for
>> making local shortcuts where aliases don't cut it:
>>
>> macro call_func( arg ) {
>> $this.some_member.a_really_long_named_template_member(arg);
>> }
>> ...
>> writefln(call_func(1));
>> writefln(call_func("hi"));
>>
>> And I'm sure there'd be any number of other uses for expression macros.
>>
> I agree that macro expressions should be allowed. However, I think a
> better syntax would be:
>
> macro foo(e) = e + 3;
>
I like that. But what about an expression with a few preliminary
statements setting up temp variables and such?
--bb
More information about the Digitalmars-d
mailing list