Const sucks

Jari-Matti Mäkelä jmjmak at utu.fi.invalid
Mon Sep 10 14:48:22 PDT 2007


Bill Baxter wrote:
> Nathan Reed wrote:
>> Carlos Santander wrote:
>>> Walter Bright escribió:
>>>> o  So, we still need a method to declare a constant that will not
>>>> consume memory. We'll co-opt the future macro syntax for that:
>>>>
>>>>     macro x = 3;
>>>>     macro s = "hello";
>>>
>>> Am I the only one who doesn't like this syntax? I guess it kinda makes
>>> sense, but I just don't like how it looks.
>>>
>> 
>> Seems to me like this unnecessarily departs from the macro syntax
>> introduced at the conference:
>> 
>> macro foo(e) { e = 3; }
>> 
>> (On the other hand, in one of them the macro is for an expression while
>> in the other one it's a sequence of declarations/statements.  So maybe
>> it is reasonable to have the different syntax.)
> 
> It's not far off from things used in some functional programming
> languages, so it doesn't look to bad to me.  The word 'macro' typically
> implies a direct, maybe even textual, substitution.  It's also a lot
> like #define, just with an '=' there which I think is an improvement
> over #define.  '=' for the no-arg macros, '{ }' for the arg-ful macros.
>   Seems ok to me.

And let's take another step forward (might scare off some old C farts,
though, but I like it):

T sum(T)(T a, T b) = a + b;

For consistency's sake! :D



More information about the Digitalmars-d mailing list