digitalmars.D - Pure, const, etc
- bearophile (4/4) Jun 20 2008 Stuff D will do:
- Koroskin Denis (14/19) Jun 23 2008 Nice. But can't see why strlen is pure (in the article):
- Sean Kelly (10/30) Jun 23 2008 I don't think "invariant" is a necessary condition for pure functions. ...
Stuff D will do: http://lwn.net/Articles/285332/ Bye, bearophile
Jun 20 2008
On Sat, 21 Jun 2008 03:53:24 +0400, bearophile <bearophileHUGS lycos.com==wrote:Stuff D will do: http://lwn.net/Articles/285332/ Bye, bearophileNice. But can't see why strlen is pure (in the article): int __attribute__((pure)) strlen(const char* string) { return /* you know what */; } char* someString =3D "Hello"; int len1 =3D strlen(someString); someString[4] =3D 0; // guess what is it now? :) int len2 =3D strlen(someString); // input is *not* changed One thing they lack is an invariant type. And the main problem is that it is not standardazed, so it is not portab= le = across compilers.
Jun 23 2008
== Quote from Koroskin Denis (2korden gmail.com)'s articleOn Sat, 21 Jun 2008 03:53:24 +0400, bearophile <bearophileHUGS lycos.com=I don't think "invariant" is a necessary condition for pure functions. The only reason invariance matters at all for pure functions is if the data is shared across threads in such a manner that concurrent modification may occur while the pure function is executing. And this is such a bad idea anyway that I don't see any reason to support it in language. Personally, I'd much rather have pure functions be able to accept "const" parameters to avoid all the casting that will happen with the current approach. Sean=wrote:Stuff D will do: http://lwn.net/Articles/285332/ Bye, bearophileNice. But can't see why strlen is pure (in the article): int __attribute__((pure)) strlen(const char* string) { return /* you know what */; } char* someString =3D "Hello"; int len1 =3D strlen(someString); someString[4] =3D 0; // guess what is it now? :) int len2 =3D strlen(someString); // input is *not* changed One thing they lack is an invariant type. And the main problem is that it is not standardazed, so it is not portab= le = across compilers.
Jun 23 2008