Manifest constants (was const again)

Bill Baxter dnewsgroup at billbaxter.com
Thu Dec 6 17:11:46 PST 2007


Walter Bright wrote:
> Janice Caron wrote:
>> Hoping to branch this off to a new thread to avoid polluting the const 
>> one...
>>
>> On 12/6/07, Walter Bright <newshound1 at digitalmars.com> wrote:
>>> That leaves what to do about manifest constants. It occurs that we
>>> already have a mechanism for them - enums. So why not:
>>>         enum x = 3;
>>>         enum long y = 4;
>>> ? I think that solves our problem.
>>
>> Will it work for reals?
>>
>> enum pi = 3.14159265358979;
>>
>> ?
> 
> Yes.

And arrays?

enum square = [[0,0],[1,0],[[1,1],[0,1]];

and hashes?

enum str2component = ["x":0, "y":1, "z":2];


--bb



More information about the Digitalmars-d mailing list