const debacle

Janice Caron caron800 at googlemail.com
Wed Mar 26 01:13:52 PDT 2008


On 26/03/2008, Davidson Corry <davidsoncorry at comcasst.net> wrote:
>  idem(x) foo(const T x, const U y);      // first promise
>  idem(y) bar(T x const, U y const);      // second promise
>
>  Does this make any sense? Or have I said something silly, or resurrected
>  an old and discarded idea, or otherwise taken a pratfall on my maiden sally?

It makes sense, and you're spot on. I think the problem is well
understood now. All we're lacking a good syntax to recommend. And it
seems to me that no one's come up with anything better than Walter's

    U bar(const(T) x, return const(U) y)

although actually I still think it should be

    const(U) bar(const(T) x, return const(U) y)

because inside the function body, every return statement is going to
be returning a const(U), not a U.

Your "bar" example doesn't make complete sense to me. If the function
can only return a U (as indicated by your idem(y) - which incidently
is similar to my earlier sliceof(y) suggestion), then why does x also
have the "returnable" parameter declaration syntax? Was that a typo or
am I missing something?

Walter's syntax is not as expressive as we might like, but it does
have the benefit of being simple. By contrast, making a distinction
between const-on-the-left and const-on-the-right is potentially
confusing - and also, no more expressive that Walter's idea, so
there's nothing to be gained by it.

For what it's worth, I have a new idea, largely inspired by Stephen,
which is to allow the keyword inout as a type constructor. inout would
basically make promise 2.

    inout(U) bar(const(T) x, inout(U) y)

I think it's fully expressive, and not too confusing, but on the down
side, it would mean that we'd then have three types of constancy
instead of just two



More information about the Digitalmars-d mailing list