[Issue 3356] Make pure functions require immutable parameters
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Oct 1 08:09:24 PDT 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3356
Don <clugdbug at yahoo.com.au> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |clugdbug at yahoo.com.au
--- Comment #1 from Don <clugdbug at yahoo.com.au> 2009-10-01 08:09:24 PDT ---
(In reply to comment #0)
> 2. When a function takes a reference type parameter, the chanses are slim, that
> the return value doesn't depend on the referenced data.
Yes.
> So the referenced data must be immutable.
That conclusion does not follow. I don't think you're seeing all of the
benefits of 'pure'.
Consider foo(a) + foo(a). This can be changed into 2*foo(a), even though a is
not immutable.
It is true that in the case where all parameters are immutable, additional
optimisations (such as caching) can be performed. But there's more to pure than
that.
> 4. (??) Replace immutability of explicit pointer type with constness, since
> even if the referenced data is immutable, the code doesn't know, where the
> immutable data ends and can access subsequent possibly mutating data. This will
> instantly make any function, taking a pointer, impure. This should not apply to
> objects and byref data.
That's a memory integrity issue, not a purity issue. That could only happen in
an unsafe module.
You are asking for a feature to be removed from the language, but I'm not
really sure why.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list