Counting Erlang LOC

Links — kevin on July 31, 2008 at 2:58 pm

Thanks to someone on #erlang whose name I can’t remember :(

-module(wc).
-author('klacke@erix.ericsson.se').

-import(count_chars, [with_file/3]).
-import(lists, [map/2, foreach/2]).

-export([file/1, files/1]).

file(File) ->
    output([gfile(File)]).

gfile(File) ->
    Fun = fun(Bin, Count) ->
                  count_bin(binary_to_list(Bin), inspace, Count)
          end,
    {File, with_file(File, Fun, {0,0,0})}.

count_bin([H|T], Where, {C,W,L}) ->
    case classify_char(H) of
        newline  when Where == inspace ->
            count_bin(T, inspace, {C+1, W, L+1});
        newline when Where == inword ->
            count_bin(T, inspace, {C+1, W+1, L+1});
        space  when Where == inspace ->
            count_bin(T, inspace, {C+1, W, L});
        space  when Where == inword ->
            count_bin(T, inspace, {C+1, W+1, L});
        char ->
            count_bin(T, inword, {C+1, W, L})
    end;
count_bin([], inword, {C, W, L}) ->
    {more, {C, W+1, L}};
count_bin([], inspace, {C, W, L}) ->
    {more, {C, W, L}}.

classify_char($ ) ->
    space;
classify_char($t) ->
    space;
classify_char($n) ->
    newline;
classify_char(_) ->
    char.

files(Files) ->
    output(map(fun(F) -> gfile(F) end, Files)).

output(Counts) ->
    io:format("~-25s ~-10s ~-10s ~-10s~n",
              ["file", "chars", "words", "lines"]),
    foreach(fun({File, {C,W,L}}) ->
                    ok = io:format("~-25s ~-10w ~-10w ~-10w~n",

HiPE CVS Repo

Links — kevin on July 26, 2008 at 10:39 am

cvs -d:pserver:guest@cvs.srv.it.uu.se:/hipe checkout otp

Core Erlang and HiPE Docs

Links — kevin on July 22, 2008 at 10:21 am

http://www.it.uu.se/research/group/hipe/cerl/

Good stuff. I figured I’d post this since I haven’t seen references to this anywhere else.

Erlang Performance Tools

Links — kevin on July 16, 2008 at 12:43 pm

Some day soon I’m going to need tools like this:

eper - A set of tools for performance tuning and debugging Erlang code

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License. | Kevin’s Link Blog