enum editing

seany seany at uni-bonn.de
Thu Jun 13 01:44:16 PDT 2013


On Tuesday, 11 June 2013 at 21:02:55 UTC, Ali Çehreli wrote:
> On 06/11/2013 12:52 PM, Seany wrote:
>
> > i read here that enums, once initialized, are constants :
> > http://ddili.org/ders/d.en/enum.html
>
> enum is a type definition with a limited set of values. That 
> part cannot be changed at runtime. (A type is a compile-time 
> concept in D.)
>
> Of course then there are variables of an enum. Their values can 
> change but they can take only those limited set of values. (A 
> cast can be used to have invalid enum values. Not recommended. 
> ;))
>
> > However, i need a method, if possible, to dynamically
> (cexecution time)
> > definition of enums, and updating them.
>
> If you are talking about changing the set of values, then it is 
> not possible with enums at runtime. You must represent that 
> "type" some other way. For example, you can have an associative 
> array that you can add values to.
>
> Ali


aha. thank you.

i was nt thinking in the line of "type of a variable"

I was thinking of a function, whose domain and range is discreet
and constant,
example :  a function that randomly generates a photon to hit and
pass through and/or get absorved by a cloud (the cloud is
discreetized, and the coordinates of the fgrd cells are constant)
will deal with a constant, discreet domain / range. but i may
want to move the cloud, or create turbulence in it. in those
cases, i will need to redefine the cell coordinates. that is, i
might want to exclusively redefine domain / range.

now since this is a matter of type fixed at the compile time, i
guess i will use good old arrays, and make them constant when
needed.


More information about the Digitalmars-d mailing list