Proposal for scoped const contracts
Janice Caron
caron800 at googlemail.com
Mon Mar 24 12:19:55 PDT 2008
On 24/03/2008, Walter Bright <newshound1 at digitalmars.com> wrote:
> For me, the question is is solving these issues a large enough problem
> that justifies adding a rather confusing new variation on const?
We can trade! :-)
We could drop "in" as a function parameter attribute. I find the
difference between "in" and "const" to be somewhat unfathomable.
Removing "in" would simplify the const system, with, as far as I can
see, no real loss.
See - you can add variations with one hand, and take them away with
the other! :-)
However, I can see a problem with the "return" syntax, exemplified by
the following example.
const(char)[] g = "hello"; // global variable
char[] f(return char[] s)
{
return g;
}
char[] s;
s = f(s);
s[0] = 'x';
It's not just the constancy you have to worry about. You also have to
prove that you are actually returning what you claim you're returning.
As in, the actual variable. That's why I earlier suggested
sliceof(t) foo(const(T) t)
...although "sliceof" is clearly the wrong word, since [] is not
defined for all types.
More information about the Digitalmars-d
mailing list