plain_fsm
plain_fsm copied to clipboard
Avoid warnings in generated code for underscored variable names
In Erlang 24, it is a warning to match a variable that begins with an underscore. Avoid this for generated code with variables such as __FSM_State.
With the following program,
-module(x).
-compile({parse_transform,plain_fsm_xform}).
-export([data_vsn/0, x/1]).
data_vsn() ->
1.
x(State) ->
plain_fsm:extended_receive(
receive
_X ->
x(State)
end).
I got the warning below. The problem with the warning is that it can be an error if one has warnings_as_errors
.
1> c("x", [debug_info]).
x.erl:0: Warning: variable '__FSM_Parent' is already bound. If you mean to ignore this value, use '_' or a different underscore-prefixed name
{ok,x}
The interesting idea to use a $
in the generated variable name to avoid the warning was not mine, but thanks to @attah
In retrospect, the approach to using $
in the generated variable names was maybe not that good. I realized the generated code will for example not survive a round-trip via text form if parsed back. Maybe such a use-case is not so common, but debugging the plain_fsm
itself could become tedious. I'll try to rework this PR to use something else to make the variables unlikely to collide yet still following variable name syntax.
Addressed in #22. Thanks, and sorry for the delay.