Set global immutables from main/getopt?

2014-01-28 Thread Andrew Klaassen
I thought it'd be a good idea to set global immutables from args passed to main(). When I do this: import io = std.stdio; immutable string abc; void foo() { io.writeln(abc); } void main(string[] args) { abc = args[1]; foo(); } ...I get the compiler error: "Error: can only initialize

Re: Set global immutables from main/getopt?

2014-01-28 Thread Stanislav Blinov
On Tuesday, 28 January 2014 at 17:11:43 UTC, Andrew Klaassen wrote: Naturally, initialize them in constructor :) http://dpaste.dzfl.pl/620e8c61

Re: Set global immutables from main/getopt?

2014-01-28 Thread Steven Schveighoffer
On Tue, 28 Jan 2014 12:27:02 -0500, Stanislav Blinov wrote: On Tuesday, 28 January 2014 at 17:11:43 UTC, Andrew Klaassen wrote: Naturally, initialize them in constructor :) http://dpaste.dzfl.pl/620e8c61 That being said, it *could* be done, since the runtime has access to the command li

Re: Set global immutables from main/getopt?

2014-01-28 Thread Stanislav Blinov
On Tuesday, 28 January 2014 at 18:30:37 UTC, Steven Schveighoffer wrote: On Tue, 28 Jan 2014 12:27:02 -0500, Stanislav Blinov wrote: http://dpaste.dzfl.pl/620e8c61 That being said, it *could* be done, since the runtime has access to the command line args. But the runtime would have to prov

Re: Set global immutables from main/getopt?

2014-01-28 Thread Steven Schveighoffer
On Tue, 28 Jan 2014 13:41:24 -0500, Stanislav Blinov wrote: On Tuesday, 28 January 2014 at 18:30:37 UTC, Steven Schveighoffer wrote: On Tue, 28 Jan 2014 12:27:02 -0500, Stanislav Blinov wrote: http://dpaste.dzfl.pl/620e8c61 That being said, it *could* be done, since the runtime has acc

Re: Set global immutables from main/getopt?

2014-01-28 Thread Ali Çehreli
On 01/28/2014 10:41 AM, Stanislav Blinov wrote: On Tuesday, 28 January 2014 at 18:30:37 UTC, Steven Schveighoffer wrote: On Tue, 28 Jan 2014 12:27:02 -0500, Stanislav Blinov wrote: http://dpaste.dzfl.pl/620e8c61 That being said, it *could* be done, since the runtime has access to the comman

Re: Set global immutables from main/getopt?

2014-01-28 Thread Stanislav Blinov
On Tuesday, 28 January 2014 at 18:56:35 UTC, Ali Çehreli wrote: On a side note, dpaste is not associated with newsgroups. It can disappear at any time in the future. I like seeing and showing code in message bodies both for convenience and future availability. :) Awww, but it is so much more

Re: Set global immutables from main/getopt?

2014-01-28 Thread Andrew Klaassen
On Tuesday, 28 January 2014 at 19:02:41 UTC, Stanislav Blinov wrote: On Tuesday, 28 January 2014 at 18:56:35 UTC, Ali Çehreli wrote: On a side note, dpaste is not associated with newsgroups. It can disappear at any time in the future. I like seeing and showing code in message bodies both for c

Re: Set global immutables from main/getopt?

2014-01-28 Thread Stanislav Blinov
On Tuesday, 28 January 2014 at 20:07:25 UTC, Andrew Klaassen wrote: Fascinating. Any chance someone would be able to add this to http://dlang.org/module.html as an example for people like me who'd have no clue otherwise? Initialization of immutable globals is actually in the docs: http://d

Re: Set global immutables from main/getopt?

2014-01-28 Thread Meta
On Tuesday, 28 January 2014 at 19:02:41 UTC, Stanislav Blinov wrote: On Tuesday, 28 January 2014 at 18:56:35 UTC, Ali Çehreli wrote: On a side note, dpaste is not associated with newsgroups. It can disappear at any time in the future. I like seeing and showing code in message bodies both for c

Re: Set global immutables from main/getopt?

2014-01-29 Thread Stanislav Blinov
On Wednesday, 29 January 2014 at 00:28:29 UTC, Meta wrote: You can also use the Github Gist feature for displaying code, can't you? But you'd need a github account for that, won't you? :)

Re: Set global immutables from main/getopt?

2014-01-29 Thread Dicebot
One can always turn global into pointer to immutable - it will preserve most benefits but can be always replaced with differently initialized one.

Re: Set global immutables from main/getopt?

2014-01-29 Thread anonymous
On Wednesday, 29 January 2014 at 10:15:03 UTC, Stanislav Blinov wrote: On Wednesday, 29 January 2014 at 00:28:29 UTC, Meta wrote: You can also use the Github Gist feature for displaying code, can't you? But you'd need a github account for that, won't you? :) no