[erlang-questions] Issue with my first program

Richard A. O'Keefe <>
Fri Sep 5 04:24:38 CEST 2008


On 5 Sep 2008, at 7:34 am, Timothy Baldridge wrote:
> -module(filemonitor).
> -export([start/1, dispatchloop/2]).

whatiswiththewordsruntogetherlikethis?
thatisevenhardertoreadthan BaStudlyCaps.

> dispatchloop([],Working) ->
>    Working;
> dispatchloop([H|T], Working) ->
>    if
> 	H == "#" ->
> 	    callcommand(Working),
> 	    dispatchloop(T, []);
> 	true ->
> 	    dispatchloop(T, Working)
>    end.

> 4> filemonitor:start("192.168.101.170").
> <<"getattr|/#">>
> ** exception exit: function_clause
>     in function  filemonitor:dispatchloop/2
>        called as filemonitor:dispatchloop(<<"getattr|/#">>,[])
>     in call from filemonitor:loop/2

It is telling you plainly that dispatchloop/2 was called
with the BINARY <<"getattr|/#">> as its first argument.
But dispatchloop wants a LIST as its first argument, so
no clause matched.  ('function_clause' really means
"[no] function clause [matched]".)

I also note that you never ever put anything into the
Working argument; all you ever do is to pass it along or
reset it to [].

I also note that you have interleaved >finding< the
commands and >processing< the commands.  When you are
getting started with something, it's often better to
keep things separate.

These three examples might be helpful:
1> regexp:split("foo#bar#ugh#", "#").
{ok,["foo","bar","ugh",[]]}
2> regexp:split("ick|ack||ugh", "|").
{ok,["ick","ack",[],"ugh"]}
3> binary_to_list(<<"getattr|/#">>).
"getattr|/#"




More information about the erlang-questions mailing list