templatizing parameters and induction (was Re: Writing Bug-Free

Andrei Alexandrescu (See Website For Email) SeeWebsiteForEmail at erdani.org
Fri Mar 23 13:03:51 PDT 2007


Dan wrote:
>>>>> Andrei Alexandrescu (See Website For Email) wrote:
>>>>>> [...]
>>>>>> int foo(int x, int y, int z);
>>>>>> int foo(static int x, int y, int z); // x is known during compilation
>>>>>> int foo(int x, static int y, int z); // y is known during compilation
>>>>>> int foo(static int x, static int y, int z); // x and y are... you know
>>>>>> [...]
>>>>>> final a = to!(int)(readln), b = to!(int)(readln);
>>>>>> foo(a, b, b);  // firsts overload
>>>>>> foo(1, a + b, b); // 2nd
>>>>>> foo(a + b, a - b, b);  // 3rd
>>>>>> foo(42, 7, b); // 4th
>>>>>> [...]
>>>>> Great sir, could you impart upon us mere mortals the wisdom by which 
>>>>> you are able to ascertain, at compile time, the difference between 
>>>>> two values known only at runtime (a la the "3rd" overload)?  We are 
>>>>> in great need of such Oracle-like behavior.
>>>> I also notice you're still posting from the future. You must make good 
>>>> money daytrading. Future postulae commotus est. :o)
> 
> Dear sirs, I have such wisdom.  
> 
> Your example is absolutely packed with bugs.  First, you are reading an entire line into an int.  May I pass the pi?

The point of using readln was to clarify that the symbols were 
dynamically bound.

Andrei



More information about the Digitalmars-d mailing list