Const sucks

Downs default_357-line at yahoo.de
Mon Sep 10 16:43:06 PDT 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jari-Matti Mäkelä wrote:
> 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

How about so?
T sum(T)(T a, T b) a + b;

This contains two things that I've feature requested before: implicit
return of the last expression in a function, and omitting { } for
one-statement functions.
My point being, it's somewhat closer to our current D than your
approach, in that it only requires two backwards-compatible extensions
instead of a whole new syntax :)

 --downs
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFG5daKpEPJRr05fBERApOlAJ9+t/uJ1CskJhPikz/ni1SqgT/fkgCeO/yG
lFhsq9awCy0Gi1fSTUNBWU4=
=pA1m
-----END PGP SIGNATURE-----



More information about the Digitalmars-d mailing list