www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Macro syntax limitations?

reply Johan Granberg <lijat.meREM OVE.gmail.com> writes:
Broken out from another thread

Walter Bright wrote:
 There's a way to do this using specialization:
 
 macro foo(somevec : somevec+=othervec+somevec, othervec)
 
 which will only match for parameters of the form:
 
 foo( a += b + a);
 

Seeing this syntax i think it is fair to that macros can be made to look like function calls but will we be able to emulate other constructs to? and what are the limitations? some examples that might be nice to be able to do unless(condition) statement; statement that could be a block or a single line like in if and StaticClass Foo { void bar(){} } that would be a macro that creates a completely static class by marking a fields and methods static. Don't focus to muck on the usefullness of the examples but more if it will be possible with D's macros. ps. The macros look real promissing keep up the good work :)
Mar 19 2007
parent Walter Bright <newshound digitalmars.com> writes:
Johan Granberg wrote:
 Broken out from another thread
 
 Walter Bright wrote:
 There's a way to do this using specialization:

 macro foo(somevec : somevec+=othervec+somevec, othervec)

 which will only match for parameters of the form:

 foo( a += b + a);

Seeing this syntax i think it is fair to that macros can be made to look like function calls but will we be able to emulate other constructs to? and what are the limitations? some examples that might be nice to be able to do unless(condition) statement; statement that could be a block or a single line like in if

Probably wouldn't work unless statement; had { } around it.
 and
 
 StaticClass Foo
 {
         void bar(){}
 }
 
 that would be a macro that creates a completely static class by marking a
 fields and methods static.

Probably not.
 Don't focus to muck on the usefullness of the examples but more if it will
 be possible with D's macros.
 
 ps. The macros look real promissing keep up the good work :)

Mar 19 2007