too much sugar not good for the health
Stewart Gordon
smjg_1998 at yahoo.com
Wed Mar 21 10:55:55 PDT 2007
Davidl Wrote:
> it's totally not arbitrary. since AA in D is a container, but
> we lack of method to operate on it and even more with any
> resort to add method for it on user land. So functions as
> Array Properties in a language with AA is a must. it looks
> beautiful, and we can extend our AA with funcs and they work
> as methods like way. it's reasonable. i used to think in ur
> way either. But after u post this, and i consider the AA's
> func stuff, i finally realize why we don't get rid of this
> feature.
<snip top of upside-down reply>
I've never been sure about this feature. The notation makes it look as though the property is part of the type, when it could be part of the code that's using someone else's type. This gets more complicated when you try allowing it for structs and classes.
But even sillier is this:
----------
import std.stdio;
class Qwert {
int yuiop(int[] asdfg) { return asdfg[0]; }
int hjkl(int[] asdfg) {
return asdfg.yuiop();
}
}
void main() {
Qwert zxcvb = new Qwert;
writefln(zxcvb.hjkl([3, 4, 5]));
}
----------
Moreover, why is the doc calling them properties, even though it doesn't work without the ()?
Another way that extending basic types could have been implemented is by enhanced typedefs. For example:
typedef char[] String {
char[] toUpper() { ... }
}
Stewart.
More information about the Digitalmars-d
mailing list