The Great Computer Language Shootout is back
Isaac Gouy
igouy2@REDACTED
Wed Jul 28 00:08:21 CEST 2004
One of the peculiarities of the Shootout tests is that they take
redirected input from the commandline rather than opening a file
directly. How would you do that?
--- Mark Scandariato <mscandar@REDACTED> wrote:
> How about:
>
> -module(wc).
> -compile(export_all).
>
> start(File) ->
> {ok, F} = file:open(File, [raw, read, binary]),
> s(next({F, 0, <<>>}), 0, 0).
>
> next({F, C, <<Char:8, Rest/binary>>}) ->
> {Char, {F, C+1, Rest}};
>
> next({F, C, <<>>}) ->
> case file:read(F, 4096) of
> {ok, Bin} -> next({F, C, Bin});
> eof -> {eof, C}
> end.
>
> s({eof, C}, L, W) -> {L, W, C};
> s({$\s, S}, L, W) -> s(next(S), L, W);
> s({$\t, S}, L, W) -> s(next(S), L, W);
> s({$\n, S}, L, W) -> s(next(S), L+1, W);
> s({_, S}, L, W) -> w(next(S), L, W+1).
>
> w({eof, C}, L, W) -> {L, W, C};
> w({$\s, S}, L, W) -> s(next(S), L, W);
> w({$\t, S}, L, W) -> s(next(S), L, W);
> w({$\n, S}, L, W) -> s(next(S), L+1, W);
> w({_, S}, L, W) -> w(next(S), L, W).
__________________________________
Do you Yahoo!?
Yahoo! Mail - 50x more storage than other providers!
http://promotions.yahoo.com/new_mail
More information about the erlang-questions
mailing list