digitalmars.D.learn - Component Programming example
- Jonathan A Dunlap (17/17) Aug 02 2013 The example:
- Justin Whear (8/28) Aug 02 2013 1) The example has a typo; there should be a '.' between the byLine call...
- Andre Artus (11/47) Aug 03 2013 void main() {
- Justin Whear (6/11) Aug 02 2013 lockingTextWriter wraps stdout (or any other file) with an OutputRange
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!
Aug 02 2013
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=4import 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).
Aug 02 2013
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: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 }The example: http://www.drdobbs.com/architecture-and-design/component-programming-in-d/240008321?pgno=4import 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).On Windows you send EOF by using the Ctrl-Z key sequence.
Aug 03 2013
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.
Aug 02 2013