www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - noob Q: declaring string variables

reply Duke Normandin <dukeofperl ml1.net> writes:
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
May 29 2010
next sibling parent Ary Borenszweig <ary esperanto.org.ar> writes:
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.
May 29 2010
prev sibling next sibling parent BCS <none anon.com> writes:
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. -- ... <IXOYE><
May 29 2010
prev sibling next sibling parent Ellery Newcomer <ellery-newcomer utulsa.edu> writes:
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.
May 29 2010
prev sibling next sibling parent Don <nospam nospam.com> writes:
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.
May 29 2010
prev sibling next sibling parent reply "Simen kjaeraas" <simen.kjaras gmail.com> writes:
Duke Normandin <dukeofperl ml1.net> 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
May 29 2010
next sibling parent Philippe Sigaud <philippe.sigaud gmail.com> writes:
On Sun, May 30, 2010 at 08:54, Simen kjaeraas <simen.kjaras gmail.com>wrote:

 Duke Normandin <dukeofperl ml1.net> wrote:

 [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).
We could wait a month or two, to let the dust settle and then have go at cleaning tutorials?
May 30 2010
prev sibling parent reply Duke Normandin <dukeofperl ml1.net> writes:
On Sun, 30 May 2010, Philippe Sigaud wrote:

 On Sun, May 30, 2010 at 08:54, Simen kjaeraas <simen.kjaras gmail.com>wrote:

 Duke Normandin <dukeofperl ml1.net> wrote:

 [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).
We could wait a month or two, to let the dust settle and then have go at cleaning tutorials?
I'll see you guys in 6 months - maybe 12. --
May 30 2010
parent BCS <none anon.com> writes:
Hello Duke,

 On Sun, 30 May 2010, Philippe Sigaud wrote:
 
 On Sun, May 30, 2010 at 08:54, Simen kjaeraas
 <simen.kjaras gmail.com>wrote:
 
 Duke Normandin <dukeofperl ml1.net> wrote:
 
 [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).
We could wait a month or two, to let the dust settle and then have go at cleaning tutorials?
I'll see you guys in 6 months - maybe 12.
Or we could start beating on them now. I'd guess that would get things fixed sooner even with having to go back and refix anything that changes in the interim. I'd offer but my writing sucks and my free time situation is even worse. -- ... <IXOYE><
May 30 2010
prev sibling parent reply Jesse Phillips <jessekphillips+D gmail.com> writes:
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...
Almost all tutorials have been written for D1.x and most of those probably in the early years. I suggest you sign up for an account and modify the examples that give you problems. For writefln, I believe D1.x did not reqire a %s (also writeln didn't exist). And for this example %s for both would be perfectly fine and the correct method. The issue with char[] password = "sesame"; is what has already been said. Both of these forms will work in D1.x and D2.x auto password = "sesame"; string password = "sesame"; D1.x has an alias for string to char[] and D2.x has an alias to immutable(char)[] Important changes from 1.x to 2.x are found on this page: http://digitalmars.com/d/2.0/features2.html Another issues you might run into for the examples are 'inout' parameters ('ref' works in both versions)
May 30 2010
parent "Nick Sabalausky" <a a.a> writes:
"Jesse Phillips" <jessekphillips+D gmail.com> wrote in message 
news:htue1b$2son$1 digitalmars.com...
 D1.x has an alias for string to char[]
Phobos does, but Tango doesn't seem to.
Jun 05 2010