digitalmars.D - enum editing
- Seany (7/7) Jun 11 2013 Hello
- Steven Schveighoffer (3/8) Jun 11 2013 No, use a variable.
- Simen Kjaeraas (12/19) Jun 11 2013 So you're saying you need something like this?
- Seany (3/23) Jun 11 2013 thank you, but that means that when i need this to behave as
- Simen Kjaeraas (12/39) Jun 11 2013 I'm not sure I follow. (I must admit I find this whole discussion a bit
- Simen Kjaeraas (6/13) Jun 11 2013 Expounding on my previous post:
- Seany (4/18) Jun 11 2013 no, i would like to define a range as a DISCREET domain / image
- John Colvin (3/25) Jun 11 2013 I'm not following you. Could you give a clearer explanation of
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (11/15) Jun 11 2013 enum is a type definition with a limited set of values. That part cannot...
- seany (15/33) Jun 13 2013 aha. thank you.
- monarch_dodra (40/47) Jun 12 2013 You could..., but it'd be nothing more than a glorified global
- seany (2/4) Jun 13 2013 thanks, i was going to commit precisely that sin.
Hello i read here that enums, once initialized, are constants : http://ddili.org/ders/d.en/enum.html However, i need a method, if possible, to dynamically (cexecution time) definition of enums, and updating them. anyidea how that can be done? using const and/or inout, and passing an array / tuple to a function?
Jun 11 2013
On Tue, 11 Jun 2013 15:52:00 -0400, Seany <seany uni-bonn.de> wrote:Hello i read here that enums, once initialized, are constants : http://ddili.org/ders/d.en/enum.html However, i need a method, if possible, to dynamically (cexecution time) definition of enums, and updating them.No, use a variable. -Steve
Jun 11 2013
On 2013-06-11, 21:52, Seany wrote:Hello i read here that enums, once initialized, are constants : http://ddili.org/ders/d.en/enum.html However, i need a method, if possible, to dynamically (cexecution time) definition of enums, and updating them. anyidea how that can be done? using const and/or inout, and passing an array / tuple to a function?So you're saying you need something like this? struct MyEnum { int value; static MyEnum a(0); static MyEnum b(1); } void foo( ) { MyEnum.b = MyEnum(4); } -- Simen
Jun 11 2013
On Tuesday, 11 June 2013 at 20:00:23 UTC, Simen Kjaeraas wrote:On 2013-06-11, 21:52, Seany wrote:thank you, but that means that when i need this to behave as const, i should use proper keywords ya?Hello i read here that enums, once initialized, are constants : http://ddili.org/ders/d.en/enum.html However, i need a method, if possible, to dynamically (cexecution time) definition of enums, and updating them. anyidea how that can be done? using const and/or inout, and passing an array / tuple to a function?So you're saying you need something like this? struct MyEnum { int value; static MyEnum a(0); static MyEnum b(1); } void foo( ) { MyEnum.b = MyEnum(4); }
Jun 11 2013
On 2013-06-11, 22:15, Seany wrote:On Tuesday, 11 June 2013 at 20:00:23 UTC, Simen Kjaeraas wrote:I'm not sure I follow. (I must admit I find this whole discussion a bit weird, as we're basically just making glorified global variables) When do you want it to behave as const? When being used as a local variable? void foo() { const MyEnum var = MyEnum.a; } Or are you asking for MyEnum.a to be const except under certain circumstances? If so, how, why, when and are you sure that makes sense? -- SimenOn 2013-06-11, 21:52, Seany wrote:thank you, but that means that when i need this to behave as const, i should use proper keywords ya?Hello i read here that enums, once initialized, are constants : http://ddili.org/ders/d.en/enum.html However, i need a method, if possible, to dynamically (cexecution time) definition of enums, and updating them. anyidea how that can be done? using const and/or inout, and passing an array / tuple to a function?So you're saying you need something like this? struct MyEnum { int value; static MyEnum a(0); static MyEnum b(1); } void foo( ) { MyEnum.b = MyEnum(4); }
Jun 11 2013
On 2013-06-11, 21:52, Seany wrote:Hello i read here that enums, once initialized, are constants : http://ddili.org/ders/d.en/enum.html However, i need a method, if possible, to dynamically (cexecution time) definition of enums, and updating them. anyidea how that can be done? using const and/or inout, and passing an array / tuple to a function?Expounding on my previous post: So you need something like this: int i; -- Simen
Jun 11 2013
On Tuesday, 11 June 2013 at 20:18:16 UTC, Simen Kjaeraas wrote:On 2013-06-11, 21:52, Seany wrote:no, i would like to define a range as a DISCREET domain / image of a function, with the possibility of modifying it when exclusively commanded.Hello i read here that enums, once initialized, are constants : http://ddili.org/ders/d.en/enum.html However, i need a method, if possible, to dynamically (cexecution time) definition of enums, and updating them. anyidea how that can be done? using const and/or inout, and passing an array / tuple to a function?Expounding on my previous post: So you need something like this: int i;
Jun 11 2013
On Tuesday, 11 June 2013 at 20:49:58 UTC, Seany wrote:On Tuesday, 11 June 2013 at 20:18:16 UTC, Simen Kjaeraas wrote:I'm not following you. Could you give a clearer explanation of what you're trying to achieve?On 2013-06-11, 21:52, Seany wrote:no, i would like to define a range as a DISCREET domain / image of a function, with the possibility of modifying it when exclusively commanded.Hello i read here that enums, once initialized, are constants : http://ddili.org/ders/d.en/enum.html However, i need a method, if possible, to dynamically (cexecution time) definition of enums, and updating them. anyidea how that can be done? using const and/or inout, and passing an array / tuple to a function?Expounding on my previous post: So you need something like this: int i;
Jun 11 2013
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.htmlenum 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
Jun 11 2013
On Tuesday, 11 June 2013 at 21:02:55 UTC, Ali Çehreli wrote:On 06/11/2013 12:52 PM, Seany wrote: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.i read here that enums, once initialized, are constants : http://ddili.org/ders/d.en/enum.htmlenum 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
Jun 13 2013
On Tuesday, 11 June 2013 at 19:52:01 UTC, Seany wrote:Hello i read here that enums, once initialized, are constants : http://ddili.org/ders/d.en/enum.html However, i need a method, if possible, to dynamically (cexecution time) definition of enums, and updating them. anyidea how that can be done? using const and/or inout, and passing an array / tuple to a function?You could..., but it'd be nothing more than a glorified global struct. Inside a module, I'd put this: //---- private struct Enum { static { public property const { uint a(){return _a;} uint b(){return _b;} uint c(){return _c;} } private { uint _a = 0; uint _b = 1; uint _c = 2; } } } void changeState() { Enum._a = 2; Enum._c = 0; } //---- Then you can use it... void main() { writeln(Enum.a); writeln(Enum.c); changeState(); writeln(Enum.a); writeln(Enum.c); } But even then, keep i mind these aren't compile time objects, so you can't use them in a switch, for example...
Jun 12 2013
On Wednesday, 12 June 2013 at 09:13:20 UTC, monarch_dodra wrote:But even then, keep i mind these aren't compile time objects, so you can't use them in a switch, for example...thanks, i was going to commit precisely that sin.
Jun 13 2013