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

> Michel Fortin wrote:
>> On 2008-10-05 01:14:17 -0400, Andrei Alexandrescu <SeeWebsiteForEmail@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)! :)
October 05, 2008
It just occured to me ..

if we're rethinking template syntax anyway, we could redefine the comma operator in 2.0 to create tuples.

Then the "of" keyword could be used for templates:

"(Vector of 2, int)[] veclist; "

I don't think it gets more understandable than that :D

 --downs
October 05, 2008
downs, el  5 de octubre a las 23:49 me escribiste:
> It just occured to me ..
> 
> if we're rethinking template syntax anyway, we could redefine the comma operator in 2.0 to create tuples.
> 
> Then the "of" keyword could be used for templates:
> 
> "(Vector of 2, int)[] veclist; "
> 
> I don't think it gets more understandable than that :D

Now we are talking!

PS: Nice way to finally introduce tuple syntax to the language ;)

-- 
Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/
----------------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145  104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------------
I can't watch TV for four minutes without thinking
I have five serious diseases.
Like: "Do you ever wake up tired in the mornings?"
Oh my god I have this, write this down. Whatever it is, I have this.
October 06, 2008
downs wrote:
> It just occured to me ..
> 
> if we're rethinking template syntax anyway, we could redefine the comma operator in 2.0 to create tuples.
> 
> Then the "of" keyword could be used for templates:
> 
> "(Vector of 2, int)[] veclist; "
> 
> I don't think it gets more understandable than that :D

+1!!!  Pure genius!  Hey, looks like something I saw in Python...  oh well, Python is a good language, why not try and learn a few things from it?


October 06, 2008
Personally I don't think that we should just change the symbol ! to . because it will break a load of libraries for purely an ascetic change. 
 Its difficult to argue that . is better then ! as it depends on the person reading the code.  However if a template change allows for more functionality then it might be worth considering.

Anyway extending a previous suggestion.  What about using ;?

Foo(int T, alias X; T val, X val2);


One clash I can think of is that it might get mixup with a for loop, however I imagine that's easily detectable.  Also its slightly harder to make a distinction between the template args and the value however on the positive side its less typing.

-Joel
October 07, 2008
Janderson wrote:
> 
> Personally I don't think that we should just change the symbol ! to . because it will break a load of libraries for purely an ascetic change. 
>  Its difficult to argue that . is better then ! as it depends on the person reading the code.  However if a template change allows for more functionality then it might be worth considering.
> 
> Anyway extending a previous suggestion.  What about using ;?
> 
> Foo(int T, alias X; T val, X val2);
> 
> 
> One clash I can think of is that it might get mixup with a for loop, however I imagine that's easily detectable.  Also its slightly harder to make a distinction between the template args and the value however on the positive side its less typing.
> 
> -Joel

This is the first suggestion which really interests me. It's really short, and there is some precedent for the use of ; as a separator from for/foreach.

But what do you do for non-function templates, which is really the problem case? I think you end up with a bunch of ;);), which maybe looks a bit odd.

auto v = new Vector!(Stack!(Tuple!(Positive!(real), Matrix!(real))))(3, 3));

becomes:
auto v = new Vector(Stack(Tuple(Positive(real), Matrix(real;););); 3, 3);

October 07, 2008
Don wrote:
> Janderson wrote:
>>
>> Personally I don't think that we should just change the symbol ! to . because it will break a load of libraries for purely an ascetic change.  Its difficult to argue that . is better then ! as it depends on the person reading the code.  However if a template change allows for more functionality then it might be worth considering.
>>
>> Anyway extending a previous suggestion.  What about using ;?
>>
>> Foo(int T, alias X; T val, X val2);
>>
>>
>> One clash I can think of is that it might get mixup with a for loop, however I imagine that's easily detectable.  Also its slightly harder to make a distinction between the template args and the value however on the positive side its less typing.
>>
>> -Joel
> 
> This is the first suggestion which really interests me. It's really short, and there is some precedent for the use of ; as a separator from for/foreach.
> 
> But what do you do for non-function templates, which is really the problem case? I think you end up with a bunch of ;);), which maybe looks a bit odd.
> 
> auto v = new Vector!(Stack!(Tuple!(Positive!(real), Matrix!(real))))(3, 3));
> 
> becomes:
> auto v = new Vector(Stack(Tuple(Positive(real), Matrix(real;););); 3, 3);

It does look winky though :o).

Andrei
October 12, 2008
Andrei Alexandrescu wrote:
> Don wrote:
>> Janderson wrote:
>>>
>>> Personally I don't think that we should just change the symbol ! to . because it will break a load of libraries for purely an ascetic change.  Its difficult to argue that . is better then ! as it depends on the person reading the code.  However if a template change allows for more functionality then it might be worth considering.
>>>
>>> Anyway extending a previous suggestion.  What about using ;?
>>>
>>> Foo(int T, alias X; T val, X val2);
>>>
>>>
>>> One clash I can think of is that it might get mixup with a for loop, however I imagine that's easily detectable.  Also its slightly harder to make a distinction between the template args and the value however on the positive side its less typing.
>>>
>>> -Joel
>>
>> This is the first suggestion which really interests me. It's really short, and there is some precedent for the use of ; as a separator from for/foreach.
>>
>> But what do you do for non-function templates, which is really the problem case? I think you end up with a bunch of ;);), which maybe looks a bit odd.
>>
>> auto v = new Vector!(Stack!(Tuple!(Positive!(real), Matrix!(real))))(3, 3));
>>
>> becomes:
>> auto v = new Vector(Stack(Tuple(Positive(real), Matrix(real;););); 3, 3);

That's a good point.  I think the ; should be optional for cases when there's no parameters (would that still work?).

auto v = new Vector(Stack(Tuple(Positive(real), Matrix(real))); 3, 3);

Also I think that any nested template syntax will be hard to read, that's why I prefer to use typedef/alias.

> 
> It does look winky though :o).
> 
> Andrei

When I write code I want it to smile back at me :)

-joel
Top | Discussion index | About this forum | D home