Re: Formatted read consumes input

2012-09-08 Thread kenji hara
I have commented to the pull. I don't like adding convenient interfaces to std.format module. https://github.com/D-Programming-Language/phobos/pull/777#issuecomment-8385551 Kenji Hara 2012/9/8 monarch_dodra monarchdo...@gmail.com: On Friday, 7 September 2012 at 15:34:12 UTC, monarch_dodra

Re: Formatted read consumes input

2012-09-08 Thread kenji hara
2012/9/8 monarch_dodra monarchdo...@gmail.com: [snip] Still, I find it horrible to have to create a named dummy variable just when I simply want to pass a copy of my range. Why you are afraid to declaring dummy variable? formattedRead is a parser, not an algorithm (as I said in the pull

Re: Formatted read consumes input

2012-09-08 Thread monarch_dodra
On Saturday, 8 September 2012 at 12:10:26 UTC, kenji hara wrote: 2012/9/8 monarch_dodra monarchdo...@gmail.com: [snip] Still, I find it horrible to have to create a named dummy variable just when I simply want to pass a copy of my range. Why you are afraid to declaring dummy variable?

Re: Formatted read consumes input

2012-09-08 Thread monarch_dodra
On Saturday, 8 September 2012 at 12:10:26 UTC, kenji hara wrote: 2012/9/8 monarch_dodra monarchdo...@gmail.com: [snip] Still, I find it horrible to have to create a named dummy variable just when I simply want to pass a copy of my range. Why you are afraid to declaring dummy variable?

Re: Formatted read consumes input

2012-09-07 Thread Steven Schveighoffer
On Thu, 23 Aug 2012 07:33:13 -0400, monarch_dodra monarchdo...@gmail.com wrote: As title implies: import std.stdio; import std.format; void main() { string s = 42; int v; formattedRead(s, %d, v); writefln([%s] [%s], s, v); } [] [42] Is this the expected behavior?

Re: Formatted read consumes input

2012-09-07 Thread monarch_dodra
On Friday, 7 September 2012 at 13:58:43 UTC, Steven Schveighoffer wrote: On Thu, 23 Aug 2012 07:33:13 -0400, monarch_dodra The only issue is, what if you *do* want ref behavior for strings? You would need to wrap the string into a ref'd range. That is not a good proposition. Unfortunately,

Re: Formatted read consumes input

2012-09-07 Thread Steven Schveighoffer
On Fri, 07 Sep 2012 10:35:37 -0400, monarch_dodra monarchdo...@gmail.com wrote: On Friday, 7 September 2012 at 13:58:43 UTC, Steven Schveighoffer wrote: On Thu, 23 Aug 2012 07:33:13 -0400, monarch_dodra The only issue is, what if you *do* want ref behavior for strings? You would need to

Re: Formatted read consumes input

2012-09-07 Thread Jonathan M Davis
On Friday, September 07, 2012 10:52:07 Steven Schveighoffer wrote: We have three situations: 1. input range is a ref type already (i.e. a class or a pImpl struct), no need to pass this by ref, just wastes cycles doing double dereference. 2. input range is a value type, and you want to

Re: Formatted read consumes input

2012-09-07 Thread monarch_dodra
On Friday, 7 September 2012 at 14:51:45 UTC, Steven Schveighoffer wrote: On Fri, 07 Sep 2012 10:35:37 -0400, monarch_dodra This looks ugly. Returning a tuple and having to split the result is horrible, I hated dealing with that in C++ (and I even wrote stuff that returned pairs!) Not only

Re: Formatted read consumes input

2012-09-07 Thread monarch_dodra
On Friday, 7 September 2012 at 15:34:12 UTC, monarch_dodra wrote: I think this is a good solution. Do you see anything I may have failed to see? I've made a pull request out of it. https://github.com/D-Programming-Language/phobos/pull/777

Re: Formatted read consumes input

2012-09-07 Thread Steven Schveighoffer
On Fri, 07 Sep 2012 11:04:36 -0400, Jonathan M Davis jmdavisp...@gmx.com wrote: On Friday, September 07, 2012 10:52:07 Steven Schveighoffer wrote: We have three situations: 1. input range is a ref type already (i.e. a class or a pImpl struct), no need to pass this by ref, just wastes

Re: Formatted read consumes input

2012-09-07 Thread Steven Schveighoffer
On Fri, 07 Sep 2012 11:34:28 -0400, monarch_dodra monarchdo...@gmail.com wrote: On Friday, 7 September 2012 at 14:51:45 UTC, Steven Schveighoffer wrote: On Fri, 07 Sep 2012 10:35:37 -0400, monarch_dodra This looks ugly. Returning a tuple and having to split the result is horrible, I

Re: Formatted read consumes input

2012-09-07 Thread monarch_dodra
On Friday, 7 September 2012 at 18:15:00 UTC, Steven Schveighoffer wrote: Well, this does work. But I don't like that the semantics depend on whether the value is an rvalue or not. Note that even ranges that are true input ranges (i.e. a file) still consume their data, even as rvalues,

Re: Formatted read consumes input

2012-08-24 Thread Dmitry Olshansky
On Thursday, 23 August 2012 at 11:33:19 UTC, monarch_dodra wrote: As title implies: import std.stdio; import std.format; void main() { string s = 42; int v; formattedRead(s, %d, v); writefln([%s] [%s], s, v); } [] [42] Is this the expected behavior? Yes, both parse

Re: Formatted read consumes input

2012-08-24 Thread monarch_dodra
On Friday, 24 August 2012 at 11:18:55 UTC, Dmitry Olshansky wrote: On Thursday, 23 August 2012 at 11:33:19 UTC, monarch_dodra wrote: I've traced the root issue to formattedRead's signature, which is: uint formattedRead(R, Char, S...)(ref R r, const(Char)[] fmt, S args); As I explained

Re: Formatted read consumes input

2012-08-24 Thread Denis Shelomovskij
24.08.2012 16:16, monarch_dodra пишет: On Friday, 24 August 2012 at 11:18:55 UTC, Dmitry Olshansky wrote: On Thursday, 23 August 2012 at 11:33:19 UTC, monarch_dodra wrote: I've traced the root issue to formattedRead's signature, which is: uint formattedRead(R, Char, S...)(ref R r,

Re: Formatted read consumes input

2012-08-24 Thread Tove
On Friday, 24 August 2012 at 11:18:55 UTC, Dmitry Olshansky wrote: C's scanf is a poor argument as it uses pointers instead of ref (and it can't do ref as there is no ref in C :) ). Yet it doesn't allow to read things in a couple of calls AFAIK. In C scanf returns number of arguments

Re: Formatted read consumes input

2012-08-24 Thread monarch_dodra
On Friday, 24 August 2012 at 13:08:43 UTC, Denis Shelomovskij wrote: 24.08.2012 16:16, monarch_dodra пишет: On Friday, 24 August 2012 at 11:18:55 UTC, Dmitry Olshansky wrote: On Thursday, 23 August 2012 at 11:33:19 UTC, monarch_dodra wrote: I've traced the root issue to formattedRead's

Re: Formatted read consumes input

2012-08-24 Thread Dmitry Olshansky
On 24-Aug-12 17:43, Tove wrote: On Friday, 24 August 2012 at 11:18:55 UTC, Dmitry Olshansky wrote: C's scanf is a poor argument as it uses pointers instead of ref (and it can't do ref as there is no ref in C :) ). Yet it doesn't allow to read things in a couple of calls AFAIK. In C scanf

Formatted read consumes input

2012-08-23 Thread monarch_dodra
As title implies: import std.stdio; import std.format; void main() { string s = 42; int v; formattedRead(s, %d, v); writefln([%s] [%s], s, v); } [] [42] Is this the expected behavior? Furthermore, it is not possible to try to save s: import std.stdio; import