Summary: E / Erlang integration

Ulf Wiger (AL/EAB) ulf.wiger@REDACTED
Mon Jun 12 11:12:33 CEST 2006


I think that even without sugar, it can be cleaned up a little:

%% @spec send(To, Request, Timeout, MatchFun) -> Result
%% @throws timeout

try e:send(RaceTrack, getPolePositionCar, 3000,
           fun(N) when N ==FarPolePositionCar ->
                io:format("My car is in pole position~n"),
                match;
              (_) -> no_match
           end) of 
   Result -> Result
   catch
      throw:timeout -> ...
end.

I'd rename the function to something other than send(), since the
asynchronous send-and-pray function in erlang is erlang:send(Dest, Msg).

I see no reason to create funs for anything but a filter function. This
fun should be passed to another process, and the return values passed
back as regular messages. Compare with gen_server call.

BR,
Ulf W

 
Michael FIG wrote:
>
> I retract my original suggestion of developing 
> special syntax for E message sending (the !< part), since 
> that can easily be accomplished by a library function 
> "Promise = e:send(CryptoCap, Message)".  However, the 
> when/catch construct of E would be clunky to use without some 
> syntactic sugar.
> 
> With sugar:
> 
>     promise_case e:send(RaceTrack, getPolePositionCar) of
>         FarPolePositionCar ->
>             io:format("My car is in pole position~n");
>         after 3000 ->
>             io:format("Timed out~n")
>         catch E ->
>             ok;
>     end.
> 
> without sugar:
> 
>     e:pcase(e:send(RaceTrack, getPolePositionCar),
>             fun (SomeFreshName) ->
>                  case SomeFreshName of
>                     FarPolePositionCar ->
>                         io:format("My car is in pole position~n"),
>                         matched;
>                     _ ->
>                         notmatched
>                  end
>             end,
>             3000, fun () -> io:format("Timed out~n"),
>             fun (E) -> ok end).



More information about the erlang-questions mailing list