logo       

Re: ANNOUNCE ex11 release two: msg#00269

lang.erlang.general

Subject: Re: ANNOUNCE ex11 release two

Joe Armstrong <joe@xxxxxxx> wrote:
> I have experimented with many different styles of callback handling
> and IMHO this is the best. If you want to do it with messages you can write
> your top-level thing like this:
>
> B = swButton:make(Win ......)
> S = self(),
> B ! {onClick, fun(X) -> S ! {wrapper, X} end},
> ...
>
> loop(...).
>
>
> loop(...) ->
> receive
> {wrapper, X} ->
> Do something
> ...
> end

What about allowing the caller to use a term for the message
if they just want a message sent:

B = swButton:make(Win ....),
S = self(),
B ! {onClick, {S, wrapper} end},

loop () ->
receive
{wrapper, X} ->
end,
loop().

Easy to tell a tuple and a fun apart; if it is a tuple it is a
two tuple of {Pid, Tag}; which results in the message {Tag, X}
being sent to to Pid. This way the caller doesn't need to
build a fun, and waste all the bytecode and memory on a fun to
just send itself a tagged message.

Of course, this is only really useful if a large number of apps
are written this way. :)

--
Shawn.

Getting there is only half as far as getting there and back.



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise