Thread overview | ||||||
---|---|---|---|---|---|---|
|
August 02, 2013 Component Programming example | ||||
---|---|---|---|---|
| ||||
The example: http://www.drdobbs.com/architecture-and-design/component-programming-in-d/240008321?pgno=4 import std.stdio; import std.array; import std.algorithm; void main() { stdin.byLine(KeepTerminator.yes) // 1 map!(a => a.idup). // 2 array. // 3 sort. // 4 copy( // 5 stdout.lockingTextWriter()); // 6 } I don't understand what happens to the output. On windows, I can keep entering lines but no output gets displayed. Also, can someone explain a bit more about lockingTextWriter? Thanks! |
August 02, 2013 Re: Component Programming example | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jonathan A Dunlap | On Fri, 02 Aug 2013 18:59:12 +0200, Jonathan A Dunlap wrote: > The example: http://www.drdobbs.com/architecture-and-design/component-programming-in- d/240008321?pgno=4 > > import std.stdio; > import std.array; > import std.algorithm; > > void main() { > stdin.byLine(KeepTerminator.yes) // 1 map!(a => a.idup). > // 2 array. // 3 > sort. // 4 copy( > // 5 > stdout.lockingTextWriter()); // 6 > } > > I don't understand what happens to the output. On windows, I can keep entering lines but no output gets displayed. Also, can someone explain a bit more about lockingTextWriter? > > Thanks! 1) The example has a typo; there should be a '.' between the byLine call and the array call. 2) The example collects all input before writing anything (so that it can sort). Hit your end-of-file character (Ctrl-D) for me to end the input. Or direct a file into the process' stdin (not sure how to do this on Windows, it's been so long). |
August 02, 2013 Re: Component Programming example | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jonathan A Dunlap | On Fri, 02 Aug 2013 18:59:12 +0200, Jonathan A Dunlap wrote:
> I don't understand what happens to the output. On windows, I can keep entering lines but no output gets displayed. Also, can someone explain a bit more about lockingTextWriter?
>
> Thanks!
lockingTextWriter wraps stdout (or any other file) with an OutputRange that locks the file while writing. This ensures that thread-shared files (which stdout is) don't accidentally interleave; if you write a line, you'll get the same line unbroken in your output, even if other threads are trying to write to stdout.
|
August 03, 2013 Re: Component Programming example | ||||
---|---|---|---|---|
| ||||
Posted in reply to Justin Whear | On Friday, 2 August 2013 at 17:03:44 UTC, Justin Whear wrote: > On Fri, 02 Aug 2013 18:59:12 +0200, Jonathan A Dunlap wrote: > >> The example: >> http://www.drdobbs.com/architecture-and-design/component-programming-in- > d/240008321?pgno=4 >> >> import std.stdio; >> import std.array; >> import std.algorithm; >> >> void main() { >> stdin.byLine(KeepTerminator.yes) // 1 map!(a => a.idup). >> // 2 array. // 3 >> sort. // 4 copy( >> // 5 >> stdout.lockingTextWriter()); // 6 >> } >> >> I don't understand what happens to the output. On windows, I can keep >> entering lines but no output gets displayed. Also, can someone explain a >> bit more about lockingTextWriter? >> >> Thanks! > > 1) The example has a typo; there should be a '.' between the byLine call > and the array call. void main() { stdin.byLine(KeepTerminator.yes) // 1 .map!(a => a.idup) // 2 '.' was missing start of this line .array // 3 .sort // 4 .copy( // 5 stdout.lockingTextWriter()); // 6 } > > 2) The example collects all input before writing anything (so that it can > sort). Hit your end-of-file character (Ctrl-D) for me to end the input. > Or direct a file into the process' stdin (not sure how to do this on > Windows, it's been so long). On Windows you send EOF by using the Ctrl-Z key sequence. |
Copyright © 1999-2021 by the D Language Foundation