Thread overview | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
February 24, 2014 Following up from the reddit announcement | ||||
---|---|---|---|---|
| ||||
What's the matter with http://dpaste.dzfl.pl/ebd6ba43823f? Andrei |
February 24, 2014 Re: Following up from the reddit announcement | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On Monday, 24 February 2014 at 22:05:46 UTC, Andrei Alexandrescu wrote:
> What's the matter with http://dpaste.dzfl.pl/ebd6ba43823f?
>
> Andrei
readf is returning 0 (the number of variables filled); it's not changing the variable "input".
|
February 24, 2014 Re: Following up from the reddit announcement | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On Mon, 24 Feb 2014 17:05:46 -0500, Andrei Alexandrescu <SeeWebsiteForEmail@erdani.org> wrote: > What's the matter with http://dpaste.dzfl.pl/ebd6ba43823f? This is what happens when you close input (i.e. hit ctrl-d from a console), without entering -1. readf is returning 0 meaning "I didn't get anything" and the code is ignoring it. I changed it to: if(readf("%s\n", &input) == 0) break; And it works fine. Note I had to add \n to the readf to use a one-number-per-line style (didn't make sense otherwise). -Steve |
February 24, 2014 Re: Following up from the reddit announcement | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | Andrei Alexandrescu:
> What's the matter with http://dpaste.dzfl.pl/ebd6ba43823f?
There are some problems there, this seems better:
readf("%d\n", &input);
Additionally readf() has a bug on Windows that I reported and it's still open in Bugzilla.
(Extra note: I have a large D2 codebase, but I am strongly against freezing D2 development even more at this stage.)
Bye,
bearophile
|
February 24, 2014 Re: Following up from the reddit announcement | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | Steven Schveighoffer:
> And it works fine. Note I had to add \n to the readf to use a one-number-per-line style (didn't make sense otherwise).
Also the code throws if just hit enter (it means you enter no number). So the code is still bad. Also using sort instead of sort() is an anti-pattern that's going to be deprecated, hopefully in D 2.066.
Bye,
bearophile
|
February 24, 2014 Re: Following up from the reddit announcement | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | > Also the code throws if just hit enter (it means you enter no number). So the code is still bad.
I prefer code like this:
void main() {
import std.stdio, std.algorithm, std.string, std.array,
std.conv;
int[] even, odd;
while (true) {
"Enter a number (or just enter to exit): ".write;
immutable txt = readln.strip;
if (txt.empty)
break;
try {
immutable input = txt.to!int;
if (input % 2 == 0) {
"even".writeln;
even ~= input;
} else {
"odd".writeln;
odd ~= input;
}
} catch (ConvException e) {
"Not a number.".writeln;
continue;
}
}
odd.sort().writeln;
even.sort().writeln;
}
|
February 24, 2014 Re: Following up from the reddit announcement | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On 02/24/2014 02:15 PM, Steven Schveighoffer wrote:
> if(readf("%s\n", &input) == 0)
> break;
>
> And it works fine. Note I had to add \n to the readf to use a
> one-number-per-line style (didn't make sense otherwise).
I always put a space before the format specifier to ignore all whitespace:
if (readf(" %s", &input) == 0)
Ali
|
February 25, 2014 Re: Following up from the reddit announcement | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On 2014-02-24 22:05:46 +0000, Andrei Alexandrescu said:
> What's the matter with http://dpaste.dzfl.pl/ebd6ba43823f?
>
> Andrei
Not sure what this is about, but when can we expect dlint?
-S.
|
February 25, 2014 Re: Following up from the reddit announcement | ||||
---|---|---|---|---|
| ||||
Posted in reply to Shammah Chancellor | On Tuesday, 25 February 2014 at 03:25:09 UTC, Shammah Chancellor wrote: > Not sure what this is about, but when can we expect dlint? > > -S. https://github.com/Hackerpilot/Dscanner#style-check |
February 25, 2014 Re: Following up from the reddit announcement | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On Monday, 24 February 2014 at 22:05:46 UTC, Andrei Alexandrescu wrote:
> What's the matter with http://dpaste.dzfl.pl/ebd6ba43823f?
>
> Andrei
The exception is fairly clear:
Unexpected '
' when converting from type LockingTextReader to type int
Though maybe:
Unexpected '\n' when converting from type LockingTextReader to type int
would be better.
|
Copyright © 1999-2021 by the D Language Foundation