[erlang-questions] Newbie problems with gen_fsm

Oliver Korpilla Oliver.Korpilla@REDACTED
Sun May 15 19:33:37 CEST 2016


When I see this:

awaiting_payment({payment, Amount}, From, {Price, Paid}) when Amount >= (Price - Paid) ->
  io:format("~p paid ~p", [From, Amount]),
  Change = Amount + Paid - Price,
  {next_state, valid_ticket, {change, Change}, {Price, Price}};

There are too many elements in the tuple returned.

  | {next_state,NextStateName,NewStateData}
  | {next_state,NextStateName,NewStateData,Timeout}
  | {next_state,NextStateName,NewStateData,hibernate}

You are allowed to return these when selecting next_state as your return value. But you return a 4-tuple instead of a 3-tuple.

If one of these is a reply back to the original requestor, then you need:


Also, not 100% sure, but:

init(Price) ->
  {ok, awaiting_payment, {Price, 0}}.

I think it has to be:

init([Price]) ->

because init/1 takes the start_link params as a list.

Sorry, no Erlang system under my fingertips to test. Hope this helps.


Gesendet: Sonntag, 15. Mai 2016 um 16:26 Uhr
Von: TA <tobias.ammann@REDACTED>
An: "Erlang Users' List" <erlang-questions@REDACTED>
Betreff: [erlang-questions] Newbie problems with gen_fsm

I wrote some code for a parking meter to understand how gen_fsm works. There are two states (awaiting_payment, valid_ticket), two input messages (payment, cancel_ticket), and three output messages (unpaid, change, refund).
I'm getting the following error and don't understand what's wrong. Any pointers?
** exception exit: {{function_clause,[{gen,do_for_proc,
     in function  gen_fsm:sync_send_event/2 (gen_fsm.erl, line 223)
     in call from ticketing_fsm:demo1/0 (ticketing_fsm.erl, line 25)
Source: https://transfer.sh/M7n3b/ticketing-fsm.erl
Tobias_______________________________________________ erlang-questions mailing list erlang-questions@REDACTED http://erlang.org/mailman/listinfo/erlang-questions[http://erlang.org/mailman/listinfo/erlang-questions]

More information about the erlang-questions mailing list