How about 'pure' for constants?

Janice Caron caron800 at googlemail.com
Tue Dec 11 23:38:01 PST 2007


On Dec 11, 2007 10:05 PM, Janice Caron <caron800 at googlemail.com> wrote:
> On 12/11/07, Robert Fraser <fraserofthenight at gmail.com> wrote:
> > Hmmm... It's not a bad idea, but (like with enum & final), this worries me:
> >
> > pure
> > {
> >      int x = 5;      // Manifest Constant
> >      void func() { } // Function without side effects
> > }
>
> That's not really worrying at all. Think of it like this
>
>     pure int x() = 5;

Guess I should have written

    pure int x() { return 5; }

but you get the idea. If you're not allowed to take the address, then
x the function behaves exactly like x the constant. That being so, I
see no problem with using the same keyword for both. It seems
appropriate somehow. In both cases, there are no side-effects.



More information about the Digitalmars-d mailing list