plain_fsm - for beginners and purists

Vlad Dumitrescu vlad_dumitrescu@REDACTED
Fri Feb 13 12:04:24 CET 2004


> > Okay, what about
> >
> > receive
> >     .... %% normal clauses
> >     Msg ->
> >         plain_fsm:handle(State, Msg,
> > Fun_that_handles_non_system_messages)
> > end;
> >
> > It's a little ugly, but maybe not too much.
>
> Unfortunately this violates the selective receive semantics.
> You cannot do this without consuming the message, and you can't
> put it back where it was. Thus, you reorder the messages in the queue,
> and this can cause subtle bugs. If you don't recognize the message,
> you need to either throw it away or avoid touching it in the first
> place.

Ah, I see what you mean.

> Mnemosyne already does it. So does the fun2ms module in stdlib.

Of course they do -- it's only not beginner's stuff. Nor purist's.


<brain dump>

Because parse transforms exist, the compiler already is an extensible one. (*)
What I think would be needed to raise this above the level of "black magic
voodoo" is to be able to express the transformations in source code-like form
(which would be something like a macro)

By that I mean that instead of fiddling with the parse tree, in many cases it
would be easier to define the transform like for example

macro
  when Cond '->' Actions end ->
    if Cond ->
          Actions;
       false ->
          ok;
    end.

The compiler would compile this in two parse trees, match the first against the
source being compiled, transform it in the other one (replacing the
placeholders), and insert it.

It's not as simple as in Lisp, but nearly :-)

/Vlad

(*) If we could add lexer_transforms, then we could in principle graft any other
language to the Erlang VM!



More information about the erlang-questions mailing list