www.digitalmars.com         C & C++   DMDScript  

D - further suggestions

reply Metthias Becker <Metthias_member pathlink.com> writes:
- Arrays

I think arrays shouldn't be converted implicitly to pointers. Instead you should
use &foo[0]. In C it was necessary that arrays can be implicitly converted to
pointeres, because otherwise passing arrays to functions would be realy
unconvenient. As D has a real array notation, this isn't needed any more.


- Atomatic type deduction part I

I'd like to have something like this:

deduce[T] T max (T x, T y)
{
if (x > y)
return x;
else
return y;
}


A new modifier (here called deduce, but you could choose a better name) that is
parameterised with one or more pseudo typenames. If you call max from the
example the compiler uses the type of the arguments instead of the pseudo
typename(s).
So for

int foo = max(2, 3)

the compiler would use int to replace T. This isn't the best example, becuse you
could do this with Object, but there are many cases, where you can't.

- Atomatic type deduction part II

The compiler knows the type of an expression. So why shouldn't the programmer
use this knowlege:

let foo = expression;

The type of foo is automaticaly deduced if you use let instead of a type.



let bar = 2 * 3;

Here bar is of type int.



My_class a_function ()
{
return new My_class;
}

let que = a_function ();

Here que is of type My_class.
Nov 10 2003
parent "Sean L. Palmer" <palmer.sean verizon.net> writes:
-Arrays:  Sounds good to me.  Most functions should take slices instead of a
pointer and length.

- Automatic type deduction part I:  Yes, you can't get templates in D to do
this for you, and it makes things really inconvenient compared to C++.  I'd
like to be able to make functions like Min and Max that work on anything
with compare and assignment, without having to manually instantiate it for
the type.

- Automatic type deduction part II:  This would help so much in some
circumstances.  Think of it as "alias for expressions", or a way to give
names to temporary intermediate results without having to explicitly declare
the type.  This feature would be very useful when writing templates, as
sometimes the exact type of an expression is not knowable (or is
ridiculously complex) until you instantiate the template.

Sean

"Metthias Becker" <Metthias_member pathlink.com> wrote in message
news:booj88$16mn$1 digitaldaemon.com...
 - Arrays

 I think arrays shouldn't be converted implicitly to pointers. Instead you
should
 use &foo[0]. In C it was necessary that arrays can be implicitly converted
to
 pointeres, because otherwise passing arrays to functions would be realy
 unconvenient. As D has a real array notation, this isn't needed any more.


 - Atomatic type deduction part I

 I'd like to have something like this:

 deduce[T] T max (T x, T y)
 {
 if (x > y)
 return x;
 else
 return y;
 }


 A new modifier (here called deduce, but you could choose a better name)
that is
 parameterised with one or more pseudo typenames. If you call max from the
 example the compiler uses the type of the arguments instead of the pseudo
 typename(s).
 So for

 int foo = max(2, 3)

 the compiler would use int to replace T. This isn't the best example,
becuse you
 could do this with Object, but there are many cases, where you can't.

 - Atomatic type deduction part II

 The compiler knows the type of an expression. So why shouldn't the
programmer
 use this knowlege:

 let foo = expression;

 The type of foo is automaticaly deduced if you use let instead of a type.



 let bar = 2 * 3;

 Here bar is of type int.



 My_class a_function ()
 {
 return new My_class;
 }

 let que = a_function ();

 Here que is of type My_class.
Nov 10 2003