Graphing FSMs
Robert Virding
rv@REDACTED
Tue Jul 11 13:45:27 CEST 2000
"Vance Shipley" <vances@REDACTED> writes:
>
>parse_function(IoDevice, FunctionName, H, T) ->
> case H of
> % if there are two args; 'Event' & 'StateData' then it's a state
> {clause, Line, [{var, Line, 'Event'}, {var, Line, 'StateData'}],
> _Guard, Body} ->
> parse_clause(IoDevice, FunctionName, Body);
> _ ->
> true
> end,
> % if the function has multiple clauses we parse them all
> case T of
> [Head|Tail] ->
> parse_function(IoDevice, FunctionName, Head, Tail);
> [Head] ->
> parse_function(IoDevice, FunctionName, Head, []);
> [] ->
> true
> end.
Just a quick comment, without reading at what you are really doing. The
second clause in the second case will never be used because the pattern
in the clause will catch the last element. Although the way the code is
written is does not matter and the second clause is unnecessary anyway.
Watch the line number variable Line, writing it this way forces them to
be on the same
line.
Why not write it like:
parse_function(IoDevice, FuncName, Cls) ->
lists:foreach(fun ({clause,Line,[{var,Le,'Event'},{var,Ls,'SateData'}],
_Guard,Body}) ->
parse_clause(IoDevice, FuncName, Body);
(_Clause) -> ok
end, Cls).
Or if you prefer not to use higher-order functions:
parse_function(IoDevice, FuncName,
[{clause,Line,[{var,Le,'Event'},{var,Ls,'SateData'}],
_Guard,Body}|Cls]) ->
parse_function(IoDevice, FuncName, Body),
parse_function(IoDevice, FuncName, Cls);
parse_function(IoDevice, FuncName, [Cl|Cls]) ->
parse_function(IoDevice, FuncName , Cls);
parse_function(IoDevice, Funcname, []) -> true.
Similar for parse_function and parse_clause.
Robert
--
Robert Virding Tel: +46 (0)8 692 22 12
Bluetail AB Email: rv@REDACTED
Hantverkargatan 78 WWW: http://www.bluetail.com/~rv
SE-112 38 Stockholm, SWEDEN
"Folk säger att jag inte bryr mig om någonting, men det skiter jag i".
More information about the erlang-questions
mailing list