Function name as text

Jarrett Billingsley kb3ctd2 at yahoo.com
Wed Dec 5 14:39:02 PST 2007


"Bill Baxter" <dnewsgroup at billbaxter.com> wrote in message 
news:fj76f5$7ou$2 at digitalmars.com...
> Craig Black wrote:
>> OK I think it's possible with mixins but the syntax is ugly.  It would be
>>
>> Event event = mixin(dispatch("&foo.bar"));
>>
>> Which leads me to an idea that has probably been proposed before.  It 
>> would be nice if I could shorten this to simply
>>
>> Event event = dispatch(&foo.bar);
>>
>> There may be reasons why this syntax would be difficult to achieve, but I 
>> think it would be worthwhile if we could.
>>
>> Thoughts?
>
> My understanding is that that is exactly what macros are going to do. 
> Define dispatch as a macro, then its arguments get passed as strings.  I 
> think the main issue is just working out the grammar and all the various 
> compiler bits to make it work.
>
> --bb

Ooooh.

macro dispatch(&x.y)
{
    Event(y.stringof, &x.y)
}

Or something like that.  Then

Event e = dispatch(&foo.bar);

turns into

Event e = Event("Foo.bar", &foo.bar);

Heck, you could remove the requirement for the ugly ampersand.

macro dispatch(x.y)
{
    Event(y.stringof, &x.y)
} 





More information about the Digitalmars-d mailing list