www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.announce - DMD 1.025 and 2.009 releases

reply Walter Bright <newshound1 digitalmars.com> writes:
New const/invariant/enum in 2.009!

http://www.digitalmars.com/d/1.0/changelog.html
http://ftp.digitalmars.com/dmd.1.025.zip

http://www.digitalmars.com/d/changelog.html
http://ftp.digitalmars.com/dmd.2.009.zip
Jan 01 2008
next sibling parent John Reimer <terminal.node gmail.com> writes:
Walter Bright wrote:
 New const/invariant/enum in 2.009!
 
 http://www.digitalmars.com/d/1.0/changelog.html
 http://ftp.digitalmars.com/dmd.1.025.zip
 
 http://www.digitalmars.com/d/changelog.html
 http://ftp.digitalmars.com/dmd.2.009.zip
Ah ha! A new year surprise! Happy new year, Walter. (you are in the same time zone as me). -JJR
Jan 01 2008
prev sibling next sibling parent Don Clugston <dac nospam.com.au> writes:
Walter Bright wrote:
 New const/invariant/enum in 2.009!
 
 http://www.digitalmars.com/d/1.0/changelog.html
 http://ftp.digitalmars.com/dmd.1.025.zip
 
 http://www.digitalmars.com/d/changelog.html
 http://ftp.digitalmars.com/dmd.2.009.zip
Nice CTFE fixes, too. Thanks, Walter. Happy New Year! Don.
Jan 01 2008
prev sibling next sibling parent reply Marcin Kuszczak <aarti_please_no spam_interia.pl> writes:
Walter Bright wrote:

 New const/invariant/enum in 2.009!
 
 http://www.digitalmars.com/d/1.0/changelog.html
 http://ftp.digitalmars.com/dmd.1.025.zip
 
 http://www.digitalmars.com/d/changelog.html
 http://ftp.digitalmars.com/dmd.2.009.zip
There is something wrong with linux libphobos2 library. I get linker errors for simplest program: -------------- import std.stdio; void main() { writefln("Just a test!"); } ------------- Version 2.008 works just right. marcin genesis:~/Programy/D/TestCases/src$ dmd quicktest.d gcc quicktest.o -o quicktest -m32 -Xlinker -L/usr/local/lib -lphobos2 -lpthread -lm quicktest.o: In function `_D3std8bitmanip102__T15createAccessorsVAyaa20_6672616374696f6e6578706f6e656e747369676eTkVyG8aa8_6672616374696f6eVi23Vk0Z15createAccessorsFZAya': quicktest.d (.text._D3std8bitmanip102__T15createAccessorsVAyaa20_6672616374696f6e6578706f6e656e747369676eTkVyG8aa8_6672616374696f6eVi23Vk0Z15createAccessorsFZAya+0x27): undefined reference to `_D3std8bitmanip11toStringSfxFmZAya' quicktest.d (.text._D3std8bitmanip102__T15createAccessorsVAyaa20_6672616374696f6e6578706f6e656e747369676eTkVyG8aa8_6672616374696f6eVi23Vk0Z15createAccessorsFZAya+0x41): undefined reference to `_D3std8bitmanip11toStringSfxFmZAya' quicktest.d (.text._D3std8bitmanip102__T15createAccessorsVAyaa20_6672616374696f6e6578706f6e656e747369676eTkVyG8aa8_6672616374696f6eVi23Vk0Z15createAccessorsFZAya+0xa3): undefined reference to `_D3std8bitmanip11toStringSfxFmZAya' quicktest.d (.text._D3std8bitmanip102__T15createAccessorsVAyaa20_6672616374696f6e6578706f6e656e747369676eTkVyG8aa8_6672616374696f6eVi23Vk0Z15createAccessorsFZAya+0xba): undefined reference to `_D3std8bitmanip11toStringSfxFmZAya' quicktest.d (.text._D3std8bitmanip102__T15createAccessorsVAyaa20_6672616374696f6e6578706f6e656e747369676eTkVyG8aa8_6672616374696f6eVi23Vk0Z15createAccessorsFZAya+0xf8): undefined reference to `_D3std8bitmanip11toStringSfxFmZAya' quicktest.o:quicktest.d (.text._D3std8bitmanip102__T15createAccessorsVAyaa20_6672616374696f6e6578706f6e656e747369676eThVyG8aa8_6578706f6e656e74Vi8Vk23Z15createAccessorsFZAya+0x27): more undefined references to `_D3std8bitmanip11toStringSfxFmZAya' follow collect2: ld returned 1 exit status --- errorlevel 1 -- Regards Marcin Kuszczak (Aarti_pl) ------------------------------------- Ask me why I believe in Jesus - http://www.zapytajmnie.com (en/pl) Doost (port of few Boost libraries) - http://www.dsource.org/projects/doost/ -------------------------------------
Jan 01 2008
parent reply Walter Bright <newshound1 digitalmars.com> writes:
Marcin Kuszczak wrote:
 There is something wrong with linux libphobos2 library.
I just uploaded it again. I think I inadvertently posted the old one.
Jan 01 2008
parent Aarti_pl <aarti interia.pl> writes:
Walter Bright pisze:
 Marcin Kuszczak wrote:
 There is something wrong with linux libphobos2 library.
I just uploaded it again. I think I inadvertently posted the old one.
Great! Now it works perfectly. BTW. Thanks for nice release. Personally I like new enum design. The old, traditional enum was too limited, and IMHO there was a great need for something better. BR Marcin Kuszczak (aarti_pl)
Jan 02 2008
prev sibling next sibling parent reply =?UTF-8?B?IuOBruOBl+OBhOOBiyAobm9zaGlpa2EpIg==?= writes:
Walter Bright wrote:
 New const/invariant/enum in 2.009!
 
 http://www.digitalmars.com/d/1.0/changelog.html
 http://ftp.digitalmars.com/dmd.1.025.zip
 
 http://www.digitalmars.com/d/changelog.html
 http://ftp.digitalmars.com/dmd.2.009.zip
Happy new year, Walter! This update caused a massive breakage to my program and I don't have any idea how to observe the new const/invariant rules. Codes using const class or struct are broken: -------------------------------------------- import std.conv, std.stdio; class C { private int i; this(int i) { this.i = i; } const string toString() { return to!(string)(this.i); } } void main() { const(C) c; c = new C(1); // error writeln(c); } -------------------------------------------- Please help me upgrade to 2.009! Thank you.
Jan 01 2008
parent reply Walter Bright <newshound1 digitalmars.com> writes:
のしいか (noshiika) wrote:

Replace:

     const(C) c;
     c = new C(1); // error
with: const(C) c = new C(1);
Jan 01 2008
next sibling parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"Walter Bright" <newshound1 digitalmars.com> wrote in message 
news:fle8mi$1j24$2 digitalmars.com...
 ???? (noshiika) wrote:

 Replace:

     const(C) c;
     c = new C(1); // error
with: const(C) c = new C(1);
Solve: const(C) c; if(someCondition) c = new C(1); else c = new C(2);
Jan 01 2008
next sibling parent reply =?UTF-8?B?IkrDqXLDtG1lIE0uIEJlcmdlciI=?= <jeberger free.fr> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jarrett Billingsley wrote:
 "Walter Bright" <newshound1 digitalmars.com> wrote in message 
 news:fle8mi$1j24$2 digitalmars.com...
 ???? (noshiika) wrote:

 Replace:

     const(C) c;
     c = new C(1); // error
with: const(C) c = new C(1);
Solve: const(C) c; if(someCondition) c = new C(1); else c = new C(2);
Untested: const(C) c = (delegate const(C) () { if (someCondition) return new C(1); else return new C(2); })(); Jerome - -- +------------------------- Jerome M. BERGER ---------------------+ | mailto:jeberger free.fr | ICQ: 238062172 | | http://jeberger.free.fr/ | Jabber: jeberger jabber.fr | +---------------------------------+------------------------------+ -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (GNU/Linux) iD8DBQFHeqxwd0kWM4JG3k8RAmbAAKCogrgIIj0/6oNi4WfoM5PkLcPawgCgjvR6 5kpZYty6ulyuKkbKSUXTeto= =TqPW -----END PGP SIGNATURE-----
Jan 01 2008
parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
""Jrme M. Berger"" <jeberger free.fr> wrote in message 
news:flea9n$1n0r$1 digitalmars.com...

 Untested:

 const(C) c =  (delegate const(C) () {
   if (someCondition)
      return new C(1);
   else
      return new C(2);
 })();
I'm crying.
Jan 01 2008
parent reply =?UTF-8?B?IkrDqXLDtG1lIE0uIEJlcmdlciI=?= <jeberger free.fr> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jarrett Billingsley wrote:
 ""J�r�me M. Berger"" <jeberger free.fr> wrote in message 
 news:flea9n$1n0r$1 digitalmars.com...
 
 Untested:

 const(C) c =  (delegate const(C) () {
   if (someCondition)
      return new C(1);
   else
      return new C(2);
 })();
I'm crying.
In fact, there's much simpler: const (C) c = (someCondition) ? (new C (1)) : (new C (2)), Jerome - -- +------------------------- Jerome M. BERGER ---------------------+ | mailto:jeberger free.fr | ICQ: 238062172 | | http://jeberger.free.fr/ | Jabber: jeberger jabber.fr | +---------------------------------+------------------------------+ -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (GNU/Linux) iD8DBQFHeq9rd0kWM4JG3k8RAkXZAJ4+/gomgWy6HvcMZ85Kt3Y6y4f2EACgrEQs lslXsrsfZwRjeLlqvj2i7Ng= =HFSY -----END PGP SIGNATURE-----
Jan 01 2008
parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
""Jrme M. Berger"" <jeberger free.fr> wrote in message 
news:fleb1b$1ol5$1 digitalmars.com...

 const (C) c = (someCondition) ? (new C (1)) : (new C (2)),
OK. I guess the point I was trying to make before is that you can't generally combine declaration and initialization. I'm sure you can all imagine a more complex example that would be prohibitive/stupid to try to initialize in a single expression.
Jan 01 2008
parent reply Charles D Hixson <charleshixsn earthlink.net> writes:
Jarrett Billingsley wrote:
 ""Jrme M. Berger"" <jeberger free.fr> wrote in message 
 news:fleb1b$1ol5$1 digitalmars.com...
 
 const (C) c = (someCondition) ? (new C (1)) : (new C (2)),
OK. I guess the point I was trying to make before is that you can't generally combine declaration and initialization. I'm sure you can all imagine a more complex example that would be prohibitive/stupid to try to initialize in a single expression.
General solution? (untested) 1) define a function to return a value of the desired type and value. 2) use it to assign a value to a constant. I suspect that this function might need to be static, but I seem to remember that const is intentionally limited to rom-able values, so that shouldn't be too restrictive. It's still not as pleasant as being able to assign once.
Jan 01 2008
parent Charles D Hixson <charleshixsn earthlink.net> writes:
Charles D Hixson wrote:
 Jarrett Billingsley wrote:
 ""Jrme M. Berger"" <jeberger free.fr> wrote in message 
 news:fleb1b$1ol5$1 digitalmars.com...

 const (C) c = (someCondition) ? (new C (1)) : (new C (2)),
OK. I guess the point I was trying to make before is that you can't generally combine declaration and initialization. I'm sure you can all imagine a more complex example that would be prohibitive/stupid to try to initialize in a single expression.
General solution? (untested) 1) define a function to return a value of the desired type and value. 2) use it to assign a value to a constant. I suspect that this function might need to be static, but I seem to remember that const is intentionally limited to rom-able values, so that shouldn't be too restrictive. It's still not as pleasant as being able to assign once.
I just re-checked the documentation, and it doesn't say that it can't be changed after compile time at all...in fact it says that it *CAN* be changed, just not via the const reference.
Jan 02 2008
prev sibling next sibling parent reply Walter Bright <newshound1 digitalmars.com> writes:
Jarrett Billingsley wrote:
 Solve:
 
 const(C) c;
 
 if(someCondition)
     c = new C(1);
 else
     c = new C(2); 
C cx; if (someCondition) cx = new C(1); else cx = new C(2); const(C) c = cx;
Jan 01 2008
next sibling parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"Walter Bright" <newshound1 digitalmars.com> wrote in message 
news:flebgf$1pmb$1 digitalmars.com...

 C cx;
 if (someCondition)
 cx = new C(1);
 else
 cx = new C(2);
 const(C) c = cx;
...
Jan 01 2008
parent reply Walter Bright <newshound1 digitalmars.com> writes:
Jarrett Billingsley wrote:
 "Walter Bright" <newshound1 digitalmars.com> wrote in message 
 news:flebgf$1pmb$1 digitalmars.com...
 
 C cx;
 if (someCondition)
 cx = new C(1);
 else
 cx = new C(2);
 const(C) c = cx;
...
Note that this isn't any different from what you'd write for a const int: int ix; if (someCondition) ix = 1; else ix = 2; const(int) i = ix; or const of any type.
Jan 01 2008
parent Bill Baxter <dnewsgroup billbaxter.com> writes:
Walter Bright wrote:
 Jarrett Billingsley wrote:
 "Walter Bright" <newshound1 digitalmars.com> wrote in message 
 news:flebgf$1pmb$1 digitalmars.com...

 C cx;
 if (someCondition)
 cx = new C(1);
 else
 cx = new C(2);
 const(C) c = cx;
 ... 
Note that this isn't any different from what you'd write for a const int: int ix; if (someCondition) ix = 1; else ix = 2; const(int) i = ix; or const of any type.
It's also the same sort of rigmarole you have to go through to conditionally initialize a reference in C++ since they cannot be rebound except at initialization. C++ programmers manage to get by with that. But that still doesn't mean it's the ideal way to do such initializations. In particular it looks pretty inefficient if we're talking about a BigStruct instead of an int. (I'd probably just switch to using a const pointer to refer to the BigStruct under the current rules.) At any rate, the lack of this capability doesn't seem a big enough problem to justify scrapping the new const. Or even to try "fixing" it with new syntax so soon before we've had the chance to get used to the new system. If the above does turn out to be a big deal in practice, perhaps some new initializer syntax could be added to make that sort of thing easier, but it doesn't look like a deal-breaker either way. --bb
Jan 01 2008
prev sibling parent Daniel919 <Daniel919 web.de> writes:
 C cx;
 if (someCondition)
     cx = new C(1);
 else
     cx = new C(2);
 const(C) c = cx;
Wouldn't it be good if there was a way to express "I will not modify this anymore", instead of creating a new object? C c; if (someCondition) c = new C(1); else c = new C(2); cast(invariant) c; //from now on, c will not change anymore //more code ... The last line could do sth like: { //new scope invariant c = cast(invariant) c; //shadowing declaration //more code ... } //ends just before the ... } //... end of the outer scope Best regards, Daniel
Jan 01 2008
prev sibling parent BCS <ao pathlink.com> writes:
Reply to Jarrett,

 "Walter Bright" <newshound1 digitalmars.com> wrote in message
 news:fle8mi$1j24$2 digitalmars.com...
 
 ???? (noshiika) wrote:
 
 Replace:
 
 const(C) c;
 c = new C(1); // error
with: const(C) c = new C(1);
Solve: const(C) c; if(someCondition) c = new C(1); else c = new C(2);
const(C) c = (someCondition) ? new C(1) : new C(2); or: const(C) c = new C((someCondition) ? 1 : 2);
Jan 01 2008
prev sibling parent reply =?UTF-8?B?IuOBruOBl+OBhOOBiyAobm9zaGlpa2EpIg==?= writes:
Walter Bright wrote:
 のしいか (noshiika) wrote:
 
 Replace:
 
     const(C) c;
     c = new C(1); // error
with: const(C) c = new C(1);
Oh, then, I have to declare a variable each time I want to assign a new value of const(class) object or a generic type, now...
Jan 02 2008
parent Walter Bright <newshound1 digitalmars.com> writes:
のしいか (noshiika) wrote:
 Walter Bright wrote:
 のしいか (noshiika) wrote:

 Replace:

     const(C) c;
     c = new C(1); // error
with: const(C) c = new C(1);
Oh, then, I have to declare a variable each time I want to assign a new value of const(class) object or a generic type, now...
Right. Just as if C were an int: const(int) i; i = 3; // error const(int) i = 3; // ok
Jan 02 2008
prev sibling next sibling parent reply Jason House <jason.james.house gmail.com> writes:
Walter Bright wrote:

 New const/invariant/enum in 2.009!
 
 http://www.digitalmars.com/d/1.0/changelog.html
 http://ftp.digitalmars.com/dmd.1.025.zip
 
 http://www.digitalmars.com/d/changelog.html
 http://ftp.digitalmars.com/dmd.2.009.zip
Has the const/invariant/enum documentation been updated yet? Looking at http://www.digitalmars.com/d/const3.html, there is no mention of enum. It does discuss manifest constants... Can you please update the docs to reflect the new design?
Jan 01 2008
parent reply Walter Bright <newshound1 digitalmars.com> writes:
Jason House wrote:
 Has the const/invariant/enum documentation been updated yet?
 Looking at http://www.digitalmars.com/d/const3.html, there is no mention of
 enum.  It does discuss manifest constants...
 
 Can you please update the docs to reflect the new design?
See http://www.digitalmars.com/d/enum.html for the enum stuff.
Jan 01 2008
parent reply Jason House <jason.james.house gmail.com> writes:
Walter Bright wrote:

 Jason House wrote:
 Has the const/invariant/enum documentation been updated yet?
 Looking at http://www.digitalmars.com/d/const3.html, there is no mention
 of
 enum.  It does discuss manifest constants...
 
 Can you please update the docs to reflect the new design?
See http://www.digitalmars.com/d/enum.html for the enum stuff.
... so you're saying that I can define manifest constants in several different ways? Quoting the online docs: "The simplest invariant declarations use it as a storage class. It can be used to declare manifest constants. invariant int x = 3; // x is set to 3" I thought manifest constants were going to be made more explicit. That way, it's known when taking an address of something is valid. Afterall, the docs also say: "Invariant used as a storage class is equivalent to using invariant as a type constructor for the entire type of a declaration: invariant int x = 3; // x is typed as invariant(int) invariant(int) y = 3; // y is invariant" ... after all the discussion about const/invariant/manifest, I think the docs should be very clear on this topic. I don't want to see more long threads about manifest constants.
Jan 01 2008
parent reply John Reimer <terminal.node gmail.com> writes:
Jason House wrote:
 Walter Bright wrote:
 
 Jason House wrote:
 Has the const/invariant/enum documentation been updated yet?
 Looking at http://www.digitalmars.com/d/const3.html, there is no mention
 of
 enum.  It does discuss manifest constants...

 Can you please update the docs to reflect the new design?
See http://www.digitalmars.com/d/enum.html for the enum stuff.
... so you're saying that I can define manifest constants in several different ways? Quoting the online docs: "The simplest invariant declarations use it as a storage class. It can be used to declare manifest constants. invariant int x = 3; // x is set to 3" I thought manifest constants were going to be made more explicit. That way, it's known when taking an address of something is valid. Afterall, the docs also say:
Yes, I saw that too. I'm guessing that Walter was saying here that an invariant /also/ can be used as a sort of manifest constant declaration. .. not of the formal sort like that of the "anonymous enum"; but people might like to take advantage of the invariants immutability for such a purpose... and so the same with "const". I wager these are the 4 ways to do manifests that Walter was referring to in earlier posts: invariant, const, named enum, and anonymous enum - the last being the "true" manifest constant. That's why he felt he shouldn't have to add another keyword to replace the anonymous enum version if he could just stretch enum a bit more at the seams. (incidentally, notice that the four ways still exist). But are these four ways equivalent and the link level? I don't think so. My question is whether this "type" of manifest constant takes up any symbol space in the program...you know: the way the libraries used to get bloated with D's old constants (something that seemed to circumvented with anonymous enums). Do all these consts (when used like manifests) truly mirror the weightless "#define". I think only the "enum" version does...unless the compiler is indeed smart enough here. But yes, the docs do tend to mix things up a little. Probably best to avoid referring to manifest constants in the discussion on immutables in that context. Other than that, I was surprised that I actually seemed to be able to grasp the const/invariant section this time around. It is fairly understandable and simply presented. Perhaps the complexities and problems will show up in actual practice, but for now the explanations seemed well done. -JJR
Jan 01 2008
parent Jason House <jason.james.house gmail.com> writes:
John Reimer Wrote:
 I wager these are the 4 ways to do manifests that Walter was referring 
 to in earlier posts: invariant, const, named enum, and anonymous enum - 
 the last being the "true" manifest constant.  That's why he felt he 
 shouldn't have to add another keyword to replace the anonymous enum 
 version if he could just stretch enum a bit more at the seams. 
 (incidentally, notice that the four ways still exist).
 
 But are these four ways equivalent and the link level?  I don't think 
 so. My question is whether this "type" of manifest constant takes up any 
 symbol space in the program...you know: the way the libraries used to 
 get bloated with D's old constants (something that seemed to 
 circumvented with anonymous enums).  Do all these consts (when used like 
 manifests) truly mirror the weightless "#define".  I think only the 
 "enum" version does...unless the compiler is indeed smart enough here.
 
 But yes, the docs do tend to mix things up a little.
That's really my whole point. There's plenty of room for confusion and assumptions when reading the docs. I feel like I keep posting stuff like "please add this to the docs", or "please clarify this in the docs". Being a developer, I understand the pain of documentation, but it truly is important... especially for D when there's lots of people (like me) who refuse to use D 2.x until they're convinced the design is both sane and stable. Actually, I might hold off on porting my code until the Tango + Phobos merger is (nearly?) complete.
Jan 02 2008
prev sibling next sibling parent reply Pablo Ripolles <in-call gmx.net> writes:
Walter Bright Wrote:

 New const/invariant/enum in 2.009!
 
 http://www.digitalmars.com/d/1.0/changelog.html
 http://ftp.digitalmars.com/dmd.1.025.zip
 
 http://www.digitalmars.com/d/changelog.html
 http://ftp.digitalmars.com/dmd.2.009.zip
Hello and Happy New Year! The example in the D Programming Language 2.0 root web page (http://www.digitalmars.com/d/) doesn't compile with dmd.2.008, I haven't been able to try it with the last version though. This is one of those things whose update may be missed easily. Exactly this same example was the first compilation I tried with the dmd compiler and I think it should welcome new developers. Cheers!
Jan 02 2008
parent Walter Bright <newshound1 digitalmars.com> writes:
Fixed.
Jan 02 2008
prev sibling next sibling parent Robert DaSilva <sp.unit.262+digitalmars gmail.com> writes:
Walter Bright wrote:
 New const/invariant/enum in 2.009!
 
 http://www.digitalmars.com/d/1.0/changelog.html
 http://ftp.digitalmars.com/dmd.1.025.zip
 
 http://www.digitalmars.com/d/changelog.html
 http://ftp.digitalmars.com/dmd.2.009.zip
Finally, I can try to break it. It was no fun too break something that was already thrown out ( http://www.digitalmars.com/d/archives/digitalmars/D/Invariants_broken_with_out_cast_63199.html ).
Jan 02 2008
prev sibling next sibling parent reply eao197 <eao197 intervale.ru> writes:
On Tue, 01 Jan 2008 12:37:38 +0300, Walter Bright  =

<newshound1 digitalmars.com> wrote:

 New const/invariant/enum in 2.009!
I have tried this sample: import std.stdio; class Notifier { int i; this( int i_value ) { i =3D i_value; } } class Message { public Notifier notifier; this( Notifier notifier_object ) { notifier =3D notifier_object; } } void main() { void show( Message m ) { writefln( &m.notifier, ": ", m.notifier.i ); } auto m1 =3D new Message( new Notifier( 1 ) ); show( m1 ); auto m2 =3D new invariant(Message)( new Notifier( 2 ) ); show( m2 ); m2.notifier =3D new Notifier( 3 ); show( m2 ); } and got: 882FF8: 1 882FD8: 2 882FD8: 3 Why m2 is not an invariant object? -- = Regards, Yauheni Akhotnikau
Jan 12 2008
next sibling parent reply torhu <no spam.invalid> writes:
eao197 wrote:
I've modified 3 lines in your main function:

 void
 main()
    {
      void show( Message m )
void show( in Message m )
        {
          writefln( &m.notifier, ": ", m.notifier.i );
writefln( cast(Notifier*)&m.notifier, ": ", m.notifier.i );
        }
 
      auto m1 = new Message( new Notifier( 1 ) );
      show( m1 );
 
      auto m2 = new invariant(Message)( new Notifier( 2 ) );
auto m2 = cast(invariant) new Message( new Notifier( 2 ) );
      show( m2 );
      m2.notifier = new Notifier( 3 );
      show( m2 );
    }
 
With these changes, I get the error "Error: cannot modify const/invariant m2.notifier".
Jan 12 2008
parent reply naryl <cy ngs.ru> writes:
On Sat, 12 Jan 2008 23:26:58 +0300, torhu <no spam.invalid> wrote:

 eao197 wrote:
 I've modified 3 lines in your main function:

 void
 main()
    {
      void show( Message m )
void show( in Message m )
        {
          writefln( &m.notifier, ": ", m.notifier.i );
writefln( cast(Notifier*)&m.notifier, ": ", m.notifier.i )=
;
        }
       auto m1 =3D new Message( new Notifier( 1 ) );
      show( m1 );
       auto m2 =3D new invariant(Message)( new Notifier( 2 ) );
auto m2 =3D cast(invariant) new Message( new Notifier( 2 ) );
      show( m2 );
      m2.notifier =3D new Notifier( 3 );
      show( m2 );
    }
With these changes, I get the error "Error: cannot modify =
 const/invariant m2.notifier".
But what 'new invariant(Message)' is supposed to do? I can't find it in = = the docs.
Jan 12 2008
parent torhu <no spam.invalid> writes:
naryl wrote:
 But what 'new invariant(Message)' is supposed to do? I can't find it in  
 the docs.
As far as I know, it doesn't do anything. DMD allows some syntaxes that have no effect. It's a bit confusing sometimes.
Jan 12 2008
prev sibling parent Walter Bright <newshound1 digitalmars.com> writes:
eao197 wrote:
 Why m2 is not an invariant object?
It is, and it's a compiler bug that will get fixed.
Jan 13 2008
prev sibling next sibling parent reply baaaam <nospam empty.com> writes:
1) is there any up to date documentation for the way const/invariant/enum works
now ?

2) whats the use for the enum manifest stuff since it renders it even
impossible to apply visibility attributes to const of that style. enum manifest
 consts are always "static public" as it seems..


Walter Bright Wrote:

 New const/invariant/enum in 2.009!
 
 http://www.digitalmars.com/d/1.0/changelog.html
 http://ftp.digitalmars.com/dmd.1.025.zip
 
 http://www.digitalmars.com/d/changelog.html
 http://ftp.digitalmars.com/dmd.2.009.zip
Jan 13 2008
parent reply Walter Bright <newshound1 digitalmars.com> writes:
baaaam wrote:
 1) is there any up to date documentation for the way
 const/invariant/enum works now ?
Yes, click the links on "enum" and "const" on the documentation pages.
 2) whats the use for the enum manifest stuff since it renders it even
 impossible to apply visibility attributes to const of that style.
 enum manifest  consts are always "static public" as it seems..
private enum i = 3;
Jan 13 2008
parent reply baaaam <nospam empty.com> writes:
Walter Bright Wrote:

 baaaam wrote:
 1) is there any up to date documentation for the way
 const/invariant/enum works now ?
Yes, click the links on "enum" and "const" on the documentation pages.
so did anything change in the behaviour of const/invaraiant ? "Both invariant and const are transitive, .." -> i thought this is not the case ? wasnt there too many problems with it ? i am confused and i guess i am not the only one.
 
 2) whats the use for the enum manifest stuff since it renders it even
 impossible to apply visibility attributes to const of that style.
 enum manifest  consts are always "static public" as it seems..
private enum i = 3;
this doesnt prevent anything from accessing that value of i. I testet it with dmd 2.009. struct Foo{ private enum i = 3; } every other piece of code can access i through "Foo.i" .
Jan 13 2008
parent reply Moritz Warning <moritzwarning web_nospam_.de> writes:
On Sun, 13 Jan 2008 06:17:25 -0500, baaaam wrote:
 "Both invariant and const are transitive, .." -> i thought this is not
 the case ? wasnt there too many problems with it ? i am confused and i
 guess i am not the only one.
"Both invariant and const are transitive, .." - that's right (for D2.00x).
 this doesnt prevent anything from accessing that value of i. I testet it
 with dmd 2.009.
 
 struct Foo{
  private enum i = 3;
 }
 
 every other piece of code can access i through "Foo.i" .
private members are always accessible on the same module level. If you have two modules (= two files), they can't access each others private members.
Jan 13 2008
parent baaaam <nospam empty.com> writes:
Moritz Warning Wrote:

 On Sun, 13 Jan 2008 06:17:25 -0500, baaaam wrote:
 "Both invariant and const are transitive, .." -> i thought this is not
 the case ? wasnt there too many problems with it ? i am confused and i
 guess i am not the only one.
"Both invariant and const are transitive, .." - that's right (for D2.00x).
 this doesnt prevent anything from accessing that value of i. I testet it
 with dmd 2.009.
 
 struct Foo{
  private enum i = 3;
 }
 
 every other piece of code can access i through "Foo.i" .
private members are always accessible on the same module level. If you have two modules (= two files), they can't access each others private members.
right, thats exactly what i did and i was able to access that private member from another module. thats why i wondered, sounds like a bug huh ?
Jan 13 2008
prev sibling parent reply foobar <foobar nomail.net> writes:
nice work !

i am very curious what exactly has changed from 2.008 to 2.009 regarding the
const/invariant stuff. what has changed in the behaviour of const and why is
there enum as another way to manifest a constant ?

where is the difference between 
 invariant int x = 3; 
or 
 const int x = 3;
and
 enum int x = 3;
?


Walter Bright Wrote:

 New const/invariant/enum in 2.009!
 
 http://www.digitalmars.com/d/1.0/changelog.html
 http://ftp.digitalmars.com/dmd.1.025.zip
 
 http://www.digitalmars.com/d/changelog.html
 http://ftp.digitalmars.com/dmd.2.009.zip
Jan 13 2008
parent reply "Vladimir Panteleev" <thecybershadow gmail.com> writes:
On Sun, 13 Jan 2008 21:47:36 +0200, foobar <foobar nomail.net> wrote:

 nice work !

 i am very curious what exactly has changed from 2.008 to 2.009 regardi=
ng the const/invariant stuff. what has changed in the behaviour of const= and why is there enum as another way to manifest a constant ?
 where is the difference between
  invariant int x =3D 3;
 or
  const int x =3D 3;
 and
  enum int x =3D 3;
 ?
Out of those three, here is only one way to declare a manifest constant = - enum. The first two will take up space in the resulting binary. Also, sock puppetry is not nice (if you did that on purpose). -- = Best regards, Vladimir mailto:thecybershadow gmail.com
Jan 13 2008
parent foobar <foobar nomail.net> writes:
Vladimir Panteleev Wrote:

 On Sun, 13 Jan 2008 21:47:36 +0200, foobar <foobar nomail.net> wrote:
 
 nice work !

 i am very curious what exactly has changed from 2.008 to 2.009 regarding the
const/invariant stuff. what has changed in the behaviour of const and why is
there enum as another way to manifest a constant ?

 where is the difference between
  invariant int x = 3;
 or
  const int x = 3;
 and
  enum int x = 3;
 ?
Out of those three, here is only one way to declare a manifest constant - enum. The first two will take up space in the resulting binary. Also, sock puppetry is not nice (if you did that on purpose).
i am very sorry but i am not native in english and i really dont know what sock puppetry is. can explain that ?
Jan 13 2008