Extended Type Design.

Andrei Alexandrescu (See Website For Email) SeeWebsiteForEmail at erdani.org
Fri Mar 16 22:32:41 PDT 2007


Reiner Pope wrote:
> Andrei Alexandrescu (See Website For Email) Wrote:
> 
>> We have talked about a design. In short, the intent is to define three 
>> flavors of immutability:
>>
>> a) final - a simple storage class controlling the immutability of the 
>> bits allocated for the symbol per se;
>>
>> b) const - type qualifier meaning an immutable view of an otherwise 
>> modifiable data. const does not control the bits of the object, only the 
>> storage addressed indirectly by it (transitively);
>>
>> c) "superconst" - denoted as "const!" or "super const": type qualifier 
>> meaning that the data is genuinely unmodifiable.
>>
> Is there anything in your discussion about compile-time constants (the sort that you need for 'static if', etc) ? You spoke a while ago about improving compile-time evaluation syntax so that there would be no difference at the call  site between runtime and compile-time evaluation (like for regexps).

I understand this is high on Walter's list. The syntax discussed is:

// dispatched when the pattern is known at compile time
RegExpMatch match(const char[] p)(const char[] p, char[] text) {...}
// dispatched when the pattern is a runtime string
RegExpMatch match()(const char[] p, char[] text) {...}

> It seems like you could get this quite easily by adding just one more parameter modifier (is this a storage class? I'm not sure) to denote, "any time this function is called, this parameter must be known at compile-time". Effectively, it would just be a conversion from this:
> 
> RegExpMatch match(static const char[] pattern, char[] text) {...}
> ...
> main()
> {
>      match("gr[ae]y", din.read());
> }
> 
> to this:
> 
> RegExpMatch match(char[] pattern)(char[] text) {...}
> ...
> main()
> {
>      match!("gr[ae]y")(din.read());
> }
> 
> Any plans this way?

The above forces only compile-time constant regexps. What we need is to 
dispatch depending on compile-time constant vs. run-time string.

Combined with macros, this will essentially allow a call to writefln to 
morph, depending on its arguments, into putch(), fputs(), write(), 
fprintf() - or execute today's dynamically-checked writefln.


Andrei



More information about the Digitalmars-d mailing list