[erlang-questions] beersong.erl on trapexit

Per Melin <>
Fri May 9 00:56:07 CEST 2008


2008/5/8 DougEdmunds <>:

> Could someone show me how to modify beersong.erl
> (on trapexit.org) so it puts the result out into
> a variable?
>
> i.e.  > Beersong = beersong:sing(), io:format("~p~n),[Beersong].
>


sing_verse(Bottle) ->
    sing_verse(Bottle, []).

sing_verse(-1, Song) ->
    lists:reverse(Song);
sing_verse(Bottle, Song) ->
    receive
        {Bottle, Verse} ->
            sing_verse(Bottle-1, [lists:flatten(Verse)|Song])
        after 3000 ->
            io:format("Verse not received after 3 seconds"
                          " - re-starting singer~n"),
            spawn_singer(Bottle),
            sing_verse(Bottle, Song)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080509/7a0b8afa/attachment.html>


More information about the erlang-questions mailing list