Food for thought

Bruno Medeiros brunodomedeiros+spam at com.gmail
Thu Feb 15 06:54:46 PST 2007


Don Clugston wrote:
> Dave wrote:
>> Don Clugston wrote:
>>> Robby wrote:
>>>> The implementation of array methods to me is one of the sexiest, and 
>>>> yet quietest features of D. Probably do to the duh factor, but none 
>>>> the less. (any method that has an array as the first argument can 
>>>> use a shortened syntax)
>>>
>>> IIRC, it's quiet because it was originally a bug. Albeit a very 
>>> popular one. And that's why it only works in a peculiar subset of cases.
>>> Even for arrays, it doesn't work for operator overloading, 
>>> unfortunately.
>>> I wonder if Walter's worked out why it works <g>. (Mind you, the list of 
>>
>> I don't think it was ever unintentional: expression.c, line 4895 (v1.005)
> 
> OK, I've finally begun an Easter egg list <g>.
> 
> http://www.prowiki.org/wiki4d/wiki.cgi?EasterEggs
> 
> 

Hum... I don't think this counts as an easter egg, but I just recently 
found out that 'alias' are like textual macros, and do not actually bind 
to a target code entity. This mean you can alias an overload name, and 
use the overloads through the alias:

--------------
import stdext.stdio;
//import helpers;

template Tpl(T : Object ) {
	const char[] msg = "Object";
}
template Tpl(T : char ) {
	const char[] msg = "char";
}
template Tpl() {
	const char[] msg = "()";
}

void func(Object o) { writeln("func(Object)"); }
void func(int a) { writeln("func(int)"); }

void main(char[][] args) {

	alias Tpl Tpl2;
	pragma(msg, Tpl2!(char).msg);
	pragma(msg, Tpl2!(Object).msg);
	pragma(msg, Tpl2!().msg);
	
	alias func func2;
	func2(2);
	func2(new Object());
}
--------------

Previously I thought alias declaration would bind to an actual target 
"definition unit". So, that explain why the stringof of an alias doesn't 
work correctly.


-- 
Bruno Medeiros - MSc in CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D



More information about the Digitalmars-d mailing list