Example: WC
the constant [enum('line'|'word'|'byte')] Integer Counter(0...);
the function main(
that constant [Int] constant String args,
return Int rc
) yyy :
my Counter total;
std.output.printf(" lines words bytes file\n");
foreach my @ arg (args):
my Blob input(std.file.read(arg))
else std.error.die("Can not read file $arg: $std.file.error");
my (Counter local, Bool inword('false'));
foreach my @ c (input):
local['byte'] :+ 1;
if (c = ord(Ascii('\n'))):
local['line'] :+ 1;
:elsif (c /= ord(Ascii(' '))):
next if (inword='true');
inword := 'true';
local['word'] :+ 1;
:else:
inword := 'false';
:end.if;
:end.foreach;
std.output.printf("%8lu%8lu%8lu %.*s\n",local.*, arg);
total :+ local;
end.foreach;
if (args.length > 2):
std.output.printf("--------------------------------------\n"
"%8lu%8lu%8lu total",total.*);
:end.if;
return 0;
end.function;