shouting versus dotting

Denis Koroskin 2korden at gmail.com
Sun Oct 5 08:40:09 PDT 2008


On Sun, 05 Oct 2008 17:45:21 +0400, Andrei Alexandrescu  
<SeeWebsiteForEmail at erdani.org> wrote:

> Michel Fortin wrote:
>> On 2008-10-05 01:14:17 -0400, Andrei Alexandrescu  
>> <SeeWebsiteForEmail at erdani.org> said:
>>
>>> I don't favor "." any more than the next guy, but I am glad there is  
>>> awareness of how unfit a choice "!" is. If you have any ideas, please  
>>> post them! Ah! I! Exclaimed! Again!
>>  Hum, I don't think we have much choice, it'll have to be something in  
>> this lot:
>>      Positive!(real)(joke);
>>     Positive.(real)(joke);
>>     Positive#(real)(joke);
>>     Positive@(real)(joke);
>>     Positive&(real)(joke);
>>     Positive`(real)(joke);
>>     Positive´(real)(joke);
>>     Positive^(real)(joke);
>>     Positive¨(real)(joke);
>>     Positive\(real)(joke);
>>  Anything else I forgot?
>>  Or we could use special delimiter characters:
>>      Positive<real>(joke);
>>     Positive“real”(joke);
>>     Positive«real»(joke);
>>     Positive#real@(joke);
>>  Each having its own problem though.
>>  My preference still goes to "!(".
>
> There was also Positive{real}(joke), with which I couldn't find an  
> ambiguity.
>
>> - - -
>>  The ".(" syntax makes me think more of something like this:
>>      void func(T, alias methodOfT, A...)(T obj, A args)
>>     {
>>         obj.(methodOfT)(args);
>>     }
>>  which I which I could do. If methodOfT was a string, I suppose I could  
>> use string mixins, but it pushes diagnostics about misnamed methods  
>> further in the template and requires adding quotes to the template  
>> parameter when instanciating.
>
> Given that methodOfT is an alias, there is no need for the parens.
>
>
> Andrei

Hmm... Is this syntax supported, for mixins in particular? I thought it is  
not implemented (it wasn't a few versions ago, because I run into the  
problem) and was about to propose it...

Added: no, it isn't as this code shows

template IntrusiveSNode(T) 	// intrusive single-linked node
{
	alias T ItemType;
	ItemType next;
}

class Item
{
	mixin IntrusiveSNode!(Item) ListOneStorable;
	mixin IntrusiveSNode!(Item) ListTwoStorable;
}

class IntrusiveSList(alias NodeType)		// intrusive single-linked list
{
	alias NodeType.ItemType ItemType;

	void add(ItemType item)	// no allocation is needed to put element to the  
list
	{
		if (tail is null) {
			head = item;
		}

		tail.NodeType.next = item; // fails
		tail = item;
		tail.NodeType.next = null; // fails	
	}

	ItemType head = null;
	ItemType tail = null;
}

void main()
{
	auto listOne = new IntrusiveSList!(Item.ListOneStorable);
	auto listTwo = new IntrusiveSList!(Item.ListTwoStorable);

	Item item = new Item();
	listOne.add(item);
	listTwo.add(item);
}

So, here is the proposal: allow this (for mixins as well)! :)



More information about the Digitalmars-d mailing list