Re: what's the difference between ref and inout in D2?

2010-03-12 Thread bearophile
Trass3r: >And that's good behavior imho.< Here I prefer the C#/Java compilers, that don't initialize and turn the usage of initialized variables into an error. >(at function entrance I guess).< Yes. But you have seen in my program2 the variable x is initialized to 10 in the main program. Thi

Re: how to implement vector structs with different number of components without much code duplication?

2010-03-12 Thread Robert Clipsham
On 12/03/10 23:20, Trass3r wrote: Is there maybe a way to implement commonly needed vector classes Vec2, Vec3, Vec4 without having to implement the same basic code over and over again? The following are a few libraries that have already implemented vector classes/structs for Vec2 .. Vec4, they

Re: how to implement vector structs with different number of components

2010-03-12 Thread bearophile
Trass3r: > Is there maybe a way to implement commonly needed vector classes Vec2, > Vec3, Vec4 without having to implement the same basic code over and over > again? I have implemented a generic nD vector struct for D1. When I have translated it to D2 I can show it and Andrei may add it to Ph

how to implement vector structs with different number of components without much code duplication?

2010-03-12 Thread Trass3r
Is there maybe a way to implement commonly needed vector classes Vec2, Vec3, Vec4 without having to implement the same basic code over and over again?

Re: what's the difference between ref and inout in D2?

2010-03-12 Thread Trass3r
According to D2 semantics that program2 is correct, because in D you can use variables that are not initialized by the programmers. ... Because in C# it is not allowed to use uninitialized variables. D's general approach is to initialize every variable and only allow unintialized ones with e

Re: what's the difference between ref and inout in D2?

2010-03-12 Thread bearophile
Trass3r: > > This shows why built-in tuples are good. > What do tuples have to do with that? According to D2 semantics that program2 is correct, because in D you can use variables that are not initialized by the programmers. But the spirit of that program2 is trash anyway, because it reads the v

Re: what's the difference between ref and inout in D2?

2010-03-12 Thread Trass3r
So a better question (I don't know the answer) is: what's the purpose of "in" if now function arguments can be const? Yeah that's true. Is this program correct? It compiles and runs, printing 0 two times. Yeah it behaves as expected cause out parameters are initialized with their init as

Re: what's the difference between ref and inout in D2?

2010-03-12 Thread bearophile
Trass3r: > why do we have "in" if all > parameters are in by default? If you start performing some experiments on your own you can write a small program like this: // program1 import std.stdio: writeln; void foo(int x, in int y) { x = 1; y = 2; } void main() { int x, y; foo(x

Re: what's the difference between ref and inout in D2?

2010-03-12 Thread Steven Schveighoffer
On Fri, 12 Mar 2010 15:39:43 -0500, Trass3r wrote: IIRC it was the same in D1, has it changed? If no, what should be used? inout is now completely different from ref. It has been used to implement DIP2 (http://www.prowiki.org/wiki4d/wiki.cgi?action=browse&id=LanguageDevel/DIPs/DIP2&oldid

what's the difference between ref and inout in D2?

2010-03-12 Thread Trass3r
IIRC it was the same in D1, has it changed? If no, what should be used? This also reminds of another question: why do we have "in" if all parameters are in by default?

Re: how to properly overload function templates?

2010-03-12 Thread Steven Schveighoffer
On Fri, 12 Mar 2010 08:52:29 -0500, bearophile wrote: Steven Schveighoffer: However, I think it can be fixed, by either handling template function overloads, That's the more general solution. Do you know how much hard is to implement that? Do you see any downsides or possible bad side

Re: how to properly overload function templates?

2010-03-12 Thread bearophile
Steven Schveighoffer: >However, I think it can be fixed, by either handling template function >overloads, That's the more general solution. Do you know how much hard is to implement that? Do you see any downsides or possible bad side effects? Bye, bearophile

Re: how to properly overload function templates?

2010-03-12 Thread Steven Schveighoffer
On Thu, 11 Mar 2010 19:15:37 -0500, Trass3r wrote: I stumbled across this while playing with operator overloading. Since they are now function templates, this becomes an issue. struct Vector2(T) { T x; T y; /// element-wise operations, +, -, Vector2 opBinary(

Re: Tidy attributes

2010-03-12 Thread Ary Borenszweig
bearophile wrote: While looking for possible attribute problems to add to Bugzilla, I have seen the following D2 program compiles and runs with no errors or warnings: static foo1() {} final foo2() {} ref foo3() {} enum void foo5() {} nothrow foo4() {} pure foo6() {} static int x1 = 10; static