Re: Reading a line from stdin

2011-03-16 Thread Jonathan M Davis
On Tuesday 15 March 2011 22:05:37 Ali Çehreli wrote: I am going over some sample programs in a text of mine and replacing std.cstream references with std.stdio. There are non-trivial differences with formatted input. The following program may be surprising to the novice: import std.stdio;

Re: Reading a line from stdin

2011-03-16 Thread spir
On 03/16/2011 06:05 AM, Ali Çehreli wrote: I am going over some sample programs in a text of mine and replacing std.cstream references with std.stdio. There are non-trivial differences with formatted input. The following program may be surprising to the novice: import std.stdio; void main() {

Re: Reading a line from stdin

2011-03-16 Thread spir
On 03/16/2011 06:41 AM, Jesse Phillips wrote: Ali Çehreli Wrote: Right? Is there a better way that I am missing? Thank you, Ali No better way, the stated reason IIRC is that it is easier to remove the new line then to append it back on. May be stated, but it is very wrong! I guess:

Re: Reading a line from stdin

2011-03-16 Thread Lars T. Kyllingstad
On Wed, 16 Mar 2011 11:20:43 +0100, spir wrote: On 03/16/2011 06:41 AM, Jesse Phillips wrote: Ali Çehreli Wrote: Right? Is there a better way that I am missing? Thank you, Ali No better way, the stated reason IIRC is that it is easier to remove the new line then to append it back on.

Re: Reading a line from stdin

2011-03-16 Thread Kagamin
Ali ǥhreli Wrote: The following program may be surprising to the novice: import std.stdio; void main() { write(What is your name? ); string name = readln(); writeln(Hi , name, !); } What if the user typed leading spaces? Will the program operate as you expect?

Re: Reading a line from stdin

2011-03-16 Thread Ali Çehreli
On 03/16/2011 05:49 AM, Kagamin wrote: Ali ǥhreli Wrote: The following program may be surprising to the novice: import std.stdio; void main() { write(What is your name? ); string name = readln(); writeln(Hi , name, !); } What if the user typed leading spaces? Will the

Re: Reading a line from stdin

2011-03-16 Thread Jesse Phillips
spir Wrote: On 03/16/2011 06:41 AM, Jesse Phillips wrote: Ali Çehreli Wrote: Right? Is there a better way that I am missing? Thank you, Ali No better way, the stated reason IIRC is that it is easier to remove the new line then to append it back on. May be stated, but it is

Re: Reading a line from stdin

2011-03-16 Thread Kagamin
Ali Çehreli Wrote: I don't have a problem with whitespace being left in the line, I just want to know whether that's the intended or accepted behavior. AFAIK, it is. It was intended to preserve eols while reading and writing lines.

Re: Reading a line from stdin

2011-03-16 Thread Kai Meyer
On 03/16/2011 07:54 AM, Ali Çehreli wrote: On 03/16/2011 05:49 AM, Kagamin wrote: Ali ǥhreli Wrote: The following program may be surprising to the novice: import std.stdio; void main() { write(What is your name? ); string name = readln(); writeln(Hi , name, !); } What if the user typed

Re: Reading a line from stdin

2011-03-16 Thread Jesse Phillips
Kai Meyer Wrote: Second, D doesn't seem to have a graceful way of reading an endless stream of your favorite data type delimited by your favorite delimiting character. I think readf is rigid, and works great in some cases. I would greatly appreciate something more flexible like C++'s

TemplateParameterList in is expression

2011-03-16 Thread simendsjo
I'm having some problems understanding the (complex) is expression. // Example from the documentation static if (is(int[10] X : X[Y], int Y : 5)) { assert(0); // should not match, Y should be 10 } // but this doesn't match either.. Shouldn't it? static if (is(int[10] X : X[Y],

Expression tuples

2011-03-16 Thread simendsjo
http://www.digitalmars.com/d/2.0/tuple.html // this example fails Tuple!(3, 7, 'c') typecons.d(298): Error: static assert Attempted to instantiate Tuple with an invalid argument: 3 Even this fails: alias Tuple!(0) T; Is Tuple only meant to store types or named types?

Re: Expression tuples

2011-03-16 Thread Simen kjaeraas
On Wed, 16 Mar 2011 21:07:08 +0100, simendsjo simen.end...@pandavre.com wrote: http://www.digitalmars.com/d/2.0/tuple.html // this example fails Tuple!(3, 7, 'c') typecons.d(298): Error: static assert Attempted to instantiate Tuple with an invalid argument: 3 Even this fails: alias

Re: Expression tuples

2011-03-16 Thread Steven Schveighoffer
On Wed, 16 Mar 2011 16:28:48 -0400, Simen kjaeraas simen.kja...@gmail.com wrote: On Wed, 16 Mar 2011 21:07:08 +0100, simendsjo simen.end...@pandavre.com wrote: http://www.digitalmars.com/d/2.0/tuple.html // this example fails Tuple!(3, 7, 'c') typecons.d(298): Error: static assert

Re: Reading a line from stdin

2011-03-16 Thread Gerrit Wichert
Am 16.03.2011 11:09, schrieb spir: This is a design bug. 99% of the time one does not want the newline, which is not part of the string data, instead just a terminator. Even more on stdin where it is used by the user to say Im done!. If the text is written back to the output /and/ newline is

Template string literal?

2011-03-16 Thread Jacob Carlborg
Is it possible to declare string literal of a template type, something like this: void bar (const(T)[] a) {} void foo (T) (const(T)[] a) { bar(abcT); } foo(defw); In this case the string literal passed to bar would be of the type wstring. Is this somehow possible or do I have to

Re: Expression tuples

2011-03-16 Thread Simen kjaeraas
On Wed, 16 Mar 2011 21:51:37 +0100, Steven Schveighoffer schvei...@yahoo.com wrote: On Wed, 16 Mar 2011 16:28:48 -0400, Simen kjaeraas simen.kja...@gmail.com wrote: On Wed, 16 Mar 2011 21:07:08 +0100, simendsjo simen.end...@pandavre.com wrote:

Re: Template string literal?

2011-03-16 Thread Denis Koroskin
On Thu, 17 Mar 2011 00:30:17 +0300, Jacob Carlborg d...@me.com wrote: Is it possible to declare string literal of a template type, something like this: void bar (const(T)[] a) {} void foo (T) (const(T)[] a) { bar(abcT); } foo(defw); In this case the string literal passed to bar would

Re: Template string literal?

2011-03-16 Thread Simen kjaeraas
On Wed, 16 Mar 2011 22:39:00 +0100, Denis Koroskin 2kor...@gmail.com wrote: On Thu, 17 Mar 2011 00:30:17 +0300, Jacob Carlborg d...@me.com wrote: Is it possible to declare string literal of a template type, something like this: void bar (const(T)[] a) {} void foo (T) (const(T)[] a) {

Re: Expression tuples

2011-03-16 Thread Steven Schveighoffer
On Wed, 16 Mar 2011 17:31:06 -0400, Simen kjaeraas simen.kja...@gmail.com wrote: On Wed, 16 Mar 2011 21:51:37 +0100, Steven Schveighoffer schvei...@yahoo.com wrote: On Wed, 16 Mar 2011 16:28:48 -0400, Simen kjaeraas simen.kja...@gmail.com wrote: On Wed, 16 Mar 2011 21:07:08 +0100,

Re: Expression tuples

2011-03-16 Thread Jonathan M Davis
On Wednesday, March 16, 2011 14:43:20 Steven Schveighoffer wrote: On Wed, 16 Mar 2011 17:31:06 -0400, Simen kjaeraas simen.kja...@gmail.com wrote: On Wed, 16 Mar 2011 21:51:37 +0100, Steven Schveighoffer schvei...@yahoo.com wrote: On Wed, 16 Mar 2011 16:28:48 -0400, Simen kjaeraas

Re: Expression tuples

2011-03-16 Thread Simen kjaeraas
On Wed, 16 Mar 2011 22:43:20 +0100, Steven Schveighoffer schvei...@yahoo.com wrote: Now I am concerned, this looks like an oxymoron: TypeTuple!(1, 2, 3) Should we think about changing the name of std.typetuple.TypeTuple since it can clearly contain expressions as well as types? I would

Unicode - Windows 1252

2011-03-16 Thread Tom
I have a D2 code that writes some stuff to the screen (usually runs in cmd.exe pseudo-console). When I print spanish characters they show wrong (gibberish symbols and so, wich corresponds to CP-1252 encoding). Is there a way to convert all outputted streams to CP-1252 without having to wrap

Re: Unicode - Windows 1252

2011-03-16 Thread Andrej Mitrovic
import std.c.windows.windows; extern(Windows) BOOL SetConsoleOutputCP(UINT); SetConsoleOutputCP(65001);

Re: Unicode - Windows 1252

2011-03-16 Thread Andrej Mitrovic
Otherwise you might be interested in using the WinAPI library from dsource which has that function prototype and many others: http://www.dsource.org/projects/bindings/wiki/WindowsApi

Re: Unicode - Windows 1252

2011-03-16 Thread Andrej Mitrovic
Sorry, 65001 is actually UTF-8 or UTF-7 IIRC. For CP-1252 you'll have to find the correct value, I guess.

Re: Unicode - Windows 1252

2011-03-16 Thread Tom
El 16/03/2011 19:27, Andrej Mitrovic escribió: import std.c.windows.windows; extern(Windows) BOOL SetConsoleOutputCP(UINT); SetConsoleOutputCP(65001); Tried a bunch of values and all yields the same result. Thanks anyway.

Re: Unicode - Windows 1252

2011-03-16 Thread Tom
El 16/03/2011 19:27, Andrej Mitrovic escribió: Otherwise you might be interested in using the WinAPI library from dsource which has that function prototype and many others: http://www.dsource.org/projects/bindings/wiki/WindowsApi Mmh, the whole winapi just for that seems a little too much. :S

Re: Unicode - Windows 1252

2011-03-16 Thread Tom
El 16/03/2011 20:36, Tom escribió: El 16/03/2011 19:27, Andrej Mitrovic escribió: import std.c.windows.windows; extern(Windows) BOOL SetConsoleOutputCP(UINT); SetConsoleOutputCP(65001); Tried a bunch of values and all yields the same result. Thanks anyway. Forget it, I'll just use chcp...

Re: Unicode - Windows 1252

2011-03-16 Thread Andrej Mitrovic
On 3/17/11, Tom t...@nospam.com wrote: El 16/03/2011 20:36, Tom escribió: El 16/03/2011 19:27, Andrej Mitrovic escribió: import std.c.windows.windows; extern(Windows) BOOL SetConsoleOutputCP(UINT); SetConsoleOutputCP(65001); Tried a bunch of values and all yields the same result. Thanks

Re: Unicode - Windows 1252

2011-03-16 Thread Tom
El 16/03/2011 21:21, Andrej Mitrovic escribió: On 3/17/11, Tomt...@nospam.com wrote: El 16/03/2011 20:36, Tom escribió: El 16/03/2011 19:27, Andrej Mitrovic escribió: import std.c.windows.windows; extern(Windows) BOOL SetConsoleOutputCP(UINT); SetConsoleOutputCP(65001); Tried a bunch of