a more consistent const syntax

Chris Nicholson-Sauls ibisbasenji at gmail.com
Tue Aug 7 20:57:21 PDT 2007


Bill Baxter wrote:
> Derek Parnell wrote:
>> On Sun, 05 Aug 2007 14:42:09 +0200, Daniel919 wrote:
>>
>>
>>> The "define proposal" is not such a big change in the language,
>>
>> I love the 'define' proposal. It is totally unambiguous and clear what is
>> intended by the code writer, and totally unambiguous and clear about what
>> we expect of the compiler.
> 
> What I think would really rock is if 'define' could also be used for 
> types and maybe expressions.
> 
> I've long felt it was silly that aliases were backwards from normal 
> assignments.
> 
> define x = 1;
> define myInt = int;
> 
> I'd love that.
> Then just get rid of alias.  :-)
> 
> Or maybe just allow alias to use either syntax:
> 
> alias x = 1;
> alias 1 x;
> alias myInt = some_complex_expr_to_compute_a_type!(int);
> alias some_complex_expr_to_compute_a_type!(int) myInt;
> 
> In my opinion it's a lot easier to read the assignment syntax (alias 
> sym=thing) than the current alias syntax (alias thing sym).  Mainly 
> because, as you see above, often the 'thing' is really long, but usually 
> the 'sym' is something very short.  It makes it easier to see the thing 
> you care about in the end which is the sym that comes out of the 
> statement that you'll be using in subsequent code.
> 
> --bb

As I understand it, the reason alias syntax is like this, is so the compiler can simply 
parse the alias as though it were a normal 'Type symbol;' decleration -- just like 
variables and functions (up until argument lists).  That said, I don't imagine it would be 
difficult to have something of a separator in there instead, either '=' as suggested or 
even ':' as used to specify inheritance of classes and enums.  Hmm.  In fact, maybe have 
'=' expect an expression to define a compile-time constant, and ':' expect a type to 
define an alias as per current behavior.

alias x     = 1                                         ;
alias myInt : some_complex_expr_to_compute_a_type!(int) ;

Just thinking "aloud."

-- Chris Nicholson-Sauls



More information about the Digitalmars-d mailing list