Latest const expansion

Bill Baxter dnewsgroup at billbaxter.com
Tue Sep 11 14:55:05 PDT 2007


Yigal Chripun wrote:
> Janice Caron wrote:
>> On 9/11/07, Yigal Chripun <yigal100 at gmail.com> wrote:
>>> my proposal is to simply use the terms tail/head, so the syntax will be
>>> [head|tail] const (T) | const T
>>>
>>> for example:
>>> head const (C) c; // c is const but c.x isn't
>>> tail const (C) c; // c is mutable but c.x is const
>>> const (C) c; // as before, both c and c.x are const
>>> head const C c; // Error
>>> tail const C c; // Error
>>
>> head and tail are good variable names, so I'd rather they didn't
>> become reserved words.
>>
>> But I've no problem with headconst and tailconst.
>>
>> Only ... would that mean we'd then also have to have a tailtailconst?
> 
> agreed, no need to make tail/head reserved words.
> i thought 1 level of "tailness" is enough to cover 99% of cases...
> can you give a use case for "tailtailconst" that can't be resolved with 
> a combination of the const parens and tailconst?

I think tailconst is too long a word for something that will probably be 
used pretty frequently.  If you think of C++ the most commonly used 
const with pointer types is   "const T* foo;"  which means tail const. 
The equivalent with a D class would be come "tailconst T foo" and you'd 
have cases where "tailconst" appears 5 times in a function signature.

    tailconst Z some_func(tailconst A a, tailconst B b, tailconst C c, 
tailconst D d) { ... }

Ick.

How about shortening it to just "tconst"? And there could be ttconst, 
and tttconst as needed.  Similarly "hconst".  And still the const(T)* 
syntax can be a synonym for tconst(T*).

Kinda reminiscent of cons, cdr, cddr, cdddr, from lisp, which really are 
basically serving the same purpose.

--bb



More information about the Digitalmars-d mailing list