Template instantiation syntax

Christopher Wright dhasenan at gmail.com
Sat Oct 11 07:28:07 PDT 2008


Jason House wrote:
> Walter Bright Wrote:
> 
>> We seem to have reached a dead end on finding a significantly better 
>> alternative than foo!(bar).
>>
>> All is not lost, though. Andrei is working on an emacs module that will 
>> parse D code and replace foo!(bar) with foo«bar» for display only when 
>> the editor is in D mode, the underlying text will still be foo!(bar). 
>> (This doesn't affect D at all, only its display in Emacs.)
>>
>> Also, we're going to try using ! for single argument syntax, as in:
>>
>> foo!bar  is same as   foo!(bar)
>> foo!10   is same as   foo!(10)
>>
>> etc. 0 arguments or more than 1 argument or arguments that are more than 
>> one token long will still require !( ). We'll see how that works. I 
>> think it looks rather nice.
> 
> Couple of comments/questions
> 
> The tool!lathe syntax doesn't look visually distinct enough for me. The @ syntax seems nicer on the eyes. I'm not trying to push changes. @() looks ugly to me, and having matching template syntax is desirable.
> 
> Is it ok to chain!nested!templates?  Gramatically, it's unambiguous.

One!Two!Three -- is this One!(Two!(Three)) or One!(Two)!(Three)?

You can disambiguate using the context, at least sometimes, but that 
adds complexity to the grammar.

struct Thing (T)
{
	static int opCall (U)() {}
}

template One (T)
{
	alias Thing!(T) One;
}

One!Thing!int thing; // variable declaration, Thing!(Thing!(int))

struct Thing (T)
{
	static int opCall (U)() {}
}

template One (T)
{
	alias Thing!(char) One;
}

int i = One!Thing!int(); // Thing!(Thing!(char))!(int).opCall



More information about the Digitalmars-d mailing list