Re: noob Q: array out-of-range
Steven Schveighoffer wrote: I wonder if someone recalls the feature set of the dmd compiler from July, 2005. That would be http://ftp.digitalmars.com/dmd.128.zip Tested the example given with that compiler, and got ArrayBoundsError. Just as expected. -- Simen
Re: Three legitimate bugs? (D1.061)
strtr wrote: Should I report these bugs? The general answer to this question is: Yes, as long as * you're sure it's a bug * you can reproduce it in a current version of DMD or GDC * it isn't already reported The bug reporting system is here: http://d.puremagic.com/issues/ (and how should I call this first one?) -- main.d(4): Error: struct main.S no size yet for forward reference main.d(4): Error: struct main.S no size yet for forward reference main.d(11): Error: cannot evaluate opCall() at compile time Puzzling. It appears that line 2 is somehow helping the compiler to get it right - and without it, the compiler gets thrown while trying to make sense of the S() you're setting S2 to. But the line numbers you're getting are puzzling in any case. In any case, there's certainly a bug here. -- run main.exe Error: ArrayBoundsError main.d(8) should be t_def.d(8) That's certainly a bug that needs to be reported if it isn't reported already. module main; const S S1 = S(); struct S { static S func( S s_ ) out(result){ assert(false,random); } body{ return s_; } const S S2 = func(S()); } void main(){} -- main.d(8): Error: __error <---# should be assert failure # The error should be "undefined identifier random". main.d(11): Error: cannot evaluate func((S())) at compile time Indeed, this is probably a bug along the same lines as the compiler's tendency to treat invalid expressions as being subsequently of type int. Stewart.
Re: Three legitimate bugs? (D1.061)
Steven Schveighoffer wrote: Unlike some languages, D1 const does not imply static. Which means you are trying to define an S as containing an S, which would then contain another S and so on. This should work: It's implying static in this context according to my testing. Try this at home: -- import std.stdio; const S S1 = S(); struct S { float value; static S opCall() { S s; s.value = 42; return s; } const S S2 = S(); } pragma(msg, S.sizeof); pragma(msg, S1.value); pragma(msg, S.S2.value); --
What does 'scope' mean for non-class types?
In D2, what is the effect (if any) of 'scope' in the following situations? scope int a; struct B { ... } scope B b; scope int[] c; // According to the spec, 'in' is shorthand for 'const scope'. void foo(in char[] d) { ... } Thanks, -Lars
Re: What does 'scope' mean for non-class types?
Lars T. Kyllingstad: > In D2, what is the effect (if any) of 'scope' in the following situations? I think, it's just sloppiness of the compiler. I have reported similar things in a bug report time ago, bug 3934. If the things you have found are missing in that bug report, you can add them. Bye, bearophile
noob Q: declaring string variables
Back again... As an introductory tutorial, I'm now using: http://www.dsource.org/projects/tutorials/wiki/InitializingVariablesExample BTW, somebody fix that page - the `writefln' statements are missing the %d and %s. char[] password = "sesame"; didn't work on my MacOS X box. Why? [sidebar] Why is every D tutorial I've touched upon so far, been frigged up? This is NOT good advocacy, people! Bad advertising! Where is the good stuff hiding? L8r... -- duke
Re: noob Q: declaring string variables
On 05/29/2010 06:38 PM, Duke Normandin wrote: Back again... As an introductory tutorial, I'm now using: http://www.dsource.org/projects/tutorials/wiki/InitializingVariablesExample BTW, somebody fix that page - the `writefln' statements are missing the %d and %s. char[] password = "sesame"; didn't work on my MacOS X box. Why? Hi Duke, Why it didn't work? Please provide the error message the compiler gave you, otherwise it's hard to reproduce and know exactly what the problem is.
Re: noob Q: declaring string variables
Hello Duke, char[] password = "sesame"; IIRC you are using D2 and that only work for D1, for D2 I think you need to do: string password = "sesame"; This has something to do with the const system. I do know there is no way to safely modify a char[] set from a string literal so D2 forcing you to use const (or immutable, I forget what's used) for this case fixes a hole in D1. -- ... <
Re: What does 'scope' mean for non-class types?
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Lars T. Kyllingstad wrote: > In D2, what is the effect (if any) of 'scope' in the following situations? > > scope int a; Nothing > > struct B { ... } > scope B b; Nothing, B's destructor will be called even without scope. > > scope int[] c; c gets deleted when the scope ends. this applies to classes as well. > > // According to the spec, 'in' is shorthand for 'const scope'. > void foo(in char[] d) { ... } d is const (read only). I've no idea why scope is mentioned, it's meaningless in the context of function arguments. - -- My enormous talent is exceeded only by my outrageous laziness. http://www.ssTk.co.uk -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.7 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iD8DBQFMAZHkT9LetA9XoXwRAkDMAKCRPhWUbfGkWD5bKafe7EEobTzmgQCeKkEm YmIbhSYIkyQnjgwk+9GH2U8= =NoeB -END PGP SIGNATURE-
Re: noob Q: declaring string variables
On 05/29/2010 04:38 PM, Duke Normandin wrote: Back again... As an introductory tutorial, I'm now using: http://www.dsource.org/projects/tutorials/wiki/InitializingVariablesExample BTW, somebody fix that page - the `writefln' statements are missing the %d and %s. char[] password = "sesame"; didn't work on my MacOS X box. Why? Maybe you're using d2, which types string literals differently than d1? rewrite to string password = "sesame"; Or maybe you attempted to modify the contents of password, which shouldn't be done for d1 or d2. rewrite to char[] password = "sesame".dup; [sidebar] Why is every D tutorial I've touched upon so far, been frigged up? This is NOT good advocacy, people! Bad advertising! Where is the good stuff hiding? L8r... Good question. I really can't think of any tutorials I used when I was learning D, past the spec and compiler sources. And the tango book. I bet Andrei's book will fit the bill nicely. I rather like his writing style, in spite of all the puns.
Re: noob Q: declaring string variables
Duke Normandin wrote: Back again... As an introductory tutorial, I'm now using: http://www.dsource.org/projects/tutorials/wiki/InitializingVariablesExample BTW, somebody fix that page - the `writefln' statements are missing the %d and %s. char[] password = "sesame"; didn't work on my MacOS X box. Why? [sidebar] Why is every D tutorial I've touched upon so far, been frigged up? This is NOT good advocacy, people! Bad advertising! Where is the good stuff hiding? L8r... Yeah. It's an advertising disaster. Basically because just about every tutorial in existence is a D1 tutorial, and many of them don't even state that. And I think that very soon, most of the interest will be in D2. OTOH, Andrei's book is excellent.
Re: What does 'scope' mean for non-class types?
div0 wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Lars T. Kyllingstad wrote: In D2, what is the effect (if any) of 'scope' in the following situations? scope int a; Nothing struct B { ... } scope B b; Nothing, B's destructor will be called even without scope. scope int[] c; c gets deleted when the scope ends. this applies to classes as well. // According to the spec, 'in' is shorthand for 'const scope'. void foo(in char[] d) { ... } d is const (read only). I've no idea why scope is mentioned, it's meaningless in the context of function arguments. I think in one of the early, complicated versions of the const system, it meant something. Looks like this mention of it was accidentally left in the spec.
Re: noob Q: declaring string variables
Duke Normandin wrote: char[] password = "sesame"; didn't work on my MacOS X box. Why? As others have said, in D2, strings are immutable by default, so string password = "sesame"; or immutable(char)[] password = "sesame"; Would be the correct way. [sidebar] Why is every D tutorial I've touched upon so far, been frigged up? This is NOT good advocacy, people! Bad advertising! Where is the good stuff hiding? L8r... One of the reasons probably is the D1/D2 schism. D1 was, in a way, a hastily chosen point at which to call the language stable. Because it has been a stable version of the language for three years, D1 has been the subject of most tutorials, while D2 has been a moving target and thus any tutorial written for it would soon be outdated. Hopefully, this situation will change as D2 becomes more stable (it actually is fairly stable already). -- Simen