diff options
Diffstat (limited to 'chapter25/docs/examples')
| -rw-r--r-- | chapter25/docs/examples/BubbleSort.smp | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/chapter25/docs/examples/BubbleSort.smp b/chapter25/docs/examples/BubbleSort.smp index 864e26da..1a4359ae 100644 --- a/chapter25/docs/examples/BubbleSort.smp +++ b/chapter25/docs/examples/BubbleSort.smp @@ -17,17 +17,23 @@ val sort = { sys.aryi64 nums -> } }; -// Read from stdin a line of the form "[ 4, 3, 2, 1]" and print it sorted. -val main = { -> - // Parse array of numbers from stdin - var nums = sys.aryi64.parseAryI64( sys.io.stdin() ); - if( !nums ) - return sys.io.p("stdin must look like [4, 3, 2, 1]"); +// Read one process argument of the form "[ 4, 3, 2, 1]" and print it sorted. +// args[0] is the executable name, as with native C argc/argv. +val main = { u8[~][] args -> + val usage = { -> + sys.io.p("Usage: please provide a list of at least two integers to sort in the format \"[1, 2, 3, 4, 5]\"\n"); + return 0; + }; + if( args# != 2 ) return usage(); + + var nums = sys.aryi64.parseAryI64(args[1]); + if( !nums ) return usage(); + if( nums.len < 2 ) return usage(); // Bubble sort array of integers sort(nums); - // Print a list of numbers to stdout - nums.str().write(1); + // Print the comma-separated result without the input brackets. + nums.csv().write(1); return 0; }; |
