[erlang-questions] Deriving records from one another?

Ulf Wiger ulf@REDACTED
Mon Jun 23 17:17:59 CEST 2014

It sounds to me that you are trying to model multiple state machines inside one process. If I’m wrong about this, you may skip the rest of this mail. ;-)

I talked about a similar problem in this presentation http://vimeo.com/8672652 (Øredev 2009), ca 44 minutes into the presentation (41 - 44 minutes might also be interesting to listen to, depending on how used you are to the Erlang style).

I recall encountering this issue in ‘industrial programmers’, where they model processes as they are used to from C programming. Splitting processes into multiple state machines can then simplify the code greatly and also make it both faster and more robust.

Ulf W

On 23 Jun 2014, at 15:49, Roger Lipscombe <roger@REDACTED> wrote:

> I'm probably thinking too OO by calling it "deriving", but here's the problem:
> OTP handlers (gen_server, etc.) take a State parameter. You can stick
> anything in here, but generally I've been using a #state record, and
> keeping a bunch of values in it.
> Now I'd like to actually start representing *state* with the State[1].
> That is, I'd like to be able to match on #init, #ready,
> #expecting_key, #whatever records. This will hopefully make the code
> easier to read, and means that my record doesn't have to contain
> fields for stuff that's not relevant in the given state.
> ...
> Cheers,
> Roger.
> [1] No, I don't think that gen_fsm is the answer at this point.
> Interesting suggestion, though, thanks.
> [2] Still on R16, so I can't use maps, but I'm still interested in how
> they might help, if at all.
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions

Ulf Wiger, Co-founder & Developer Advocate, Feuerlabs Inc.

More information about the erlang-questions mailing list