Reading about D: few questions
Jonathan M Davis
jmdavisProg at gmx.com
Fri Dec 23 15:27:34 PST 2011
On Friday, December 23, 2011 14:51:21 Ali Çehreli wrote:
> On 12/23/2011 11:51 AM, bearophile wrote:
> > Ali:
> >> There is nothing in the language that makes me say "the returned
>
> object is unique; you can cast it to mutable or immutable freely."<
>
> > The return value of strongly pure functions is implicitly castable to
>
> immutable.
>
> Is that working yet? The commented-out lines below don't compile with 2.057:
>
> void main()
> {
> char[] s = "hello".dup;
>
> char[] am = endWithDot(s);
> const(char)[] ac = endWithDot(s);
> const(char[]) acc = endWithDot(s);
> // immutable(char)[] ai = endWithDot(s);
> // immutable(char[]) aii = endWithDot(s);
> }
>
> pure char[] endWithDot(const(char)[] s)
> {
> char[] result = s.dup;
> result ~= '.';
> return result;
> }
Well, that's not strongly pure - only weakly pure - so if the optimization is
only for strongly pure functions, then that won't work. I know that it _could_
be done with weakly pure functions as well (such as your example here), but
I'm not exactly sure what it does right now. The feature is new, so it doesn't
yet work in all of the cases that it should, and it's not entirely clear
exactly far it will go. IIRC, Daniel Murphy and Steven were discussing it a
while back, and it clearly didn't do as much as it could, and it wasn't
entirely clear that it ever would beacuse of the increased complications
involved. However, it wil almost certainly work in more cases in the future
than it does now as the feature is improved.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list