Map Lambda with Side-Effects

Tobias Pankrath via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jan 13 03:33:27 PST 2015


> "Unusable theoretical crap" is better than the current trap :-)
>
> We hare "pure" in D, but still we have not grown up to actually 
> use it in Phobos, for higher order functions, or parallelism.

I don't think that Nordlöw presented a serious trap. This might 
lead to bugs, yes, like anything else, for example: void 
foo(int[] arr) { ... arr ~= ... }

Same error, if you expect arr to be changed outside the function. 
In the case of Nordlöw: If you add a warning* it will issue many 
warnings for a huge amount of perfectly fine code making the 
warning useless. Forbidding it, would be even worse (since the 
code wouldn't work, a more verbose alternative needs to be used 
etc ..). For what? To prevent a possible bug that is easily found 
and fixed? Wrong trade-off if you ask me.


* When should the warning actually be issued? Whenever a closure 
is passed to map? Whenever a closure passed to map closes over 
something where hasAliasing!T is true?


More information about the Digitalmars-d-learn mailing list