Graphing FSMs

Vance Shipley vances@REDACTED
Thu Jul 13 19:13:30 CEST 2000

Robert Virding writes:
}  >	% 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.

Oops.  That was a remnant from previous tests.

}  Watch the line number variable Line, writing it this way forces them to
}  be on the same line.

Yes I knew this when I wrote it but intended to think about it some more.
I have changed it to '_' so that it doesn't matter if there is a line change.

The thing here was that I was basically documenting the Absform with the
code I was writing.  I wanted to be able to understand it when I came back
to enhance this code.  I thought that I could use '_Line' and it would have
the semantics of '_' but that is not the case.  Personally I would think that
this should be the case.  Why would you put an underscore in front of a variable
name if you wanted it treated just as if there wasn't one?


test(_Foo, _Foo) ->
test(_, _) ->

2> t:test(1, 2).
3> t:test(1, 1).

}  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).

Because it would take me half a day to understand what you just wrote. :)

}  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.

That certainly is more elegant.  I will have to think about this some more.
I'm sure your suggestions will help improve the style of code I write.  As
it is it works and I can understand it, two important things. :)


More information about the erlang-questions mailing list