Dnia 18-10-2010 o 20:31:26 Tomek Sowiński <[email protected]> napisał(a):
Initializing immutable structures is a source of constant grief.
Anything non-trivial requires instancing a mutable structure,
initializing it, and then either casting to immutable (it's up to you to
ensure no alias leaked) or, not to violate the type system, duplicate
the whole.
Yet, if there was a situation where the alias leaking is under control,
casting would be safe. Perhaps pure* functions are such a place. They
can only touch the immutable world, whether through globals or through
their parameters. So if one initializes the returned structure with a
reference to the outside world, it will be immutable. And if you stuff
the structure with anything mutable, it must have been created within
the function's body, so no alias leaks.
Call me crazy, but I think it is safe to implicitly convert a pure
function's return value to immutable. What you think?
* here by pure I mean either the old pure** when it still had immutable
arguments, or Don's "immutably pure".
** BTW, http://www.digitalmars.com/d/2.0/function.html still says
immutable, please update.
OK, I see the interest is dying down (so boring, not even one duck to
name) so I filed an enhancement request so it won't be forgotten.
http://d.puremagic.com/issues/show_bug.cgi?id=5081
--
Tomek