[erlang-questions] My biggest beef with Erlang
Robert Virding
rvirding@REDACTED
Tue Nov 27 12:04:59 CET 2007
Termite has a recieve function ?? defined as (?? pred [timeout [default]])
which retrieves the first message in the mailbox which satisfies pred. This
is basically impossible to implement today in Erlang but would be possible
to add.
I would however probably oppose it as you could get into really weird
situations if pred had side effects. It is actually just like allowing user
defined functions in guards.
receive
X when user_function(X) -> X
end
I actually defy anyone to come up with a safe, consistent and
*understandable* definition of guards which allow user defined functions. It
would also be nice if they were relatively easy to implement. Joe, remember
our ideas with pipes?
Robert
On 27/11/2007, Lev Walkin <vlm@REDACTED> wrote:
>
>
> This can be achieved using a combinator, if only there
> were a possibility to not to extract the current message,
> e.g., "retain":
>
>
> receiveFun(F) ->
> % Discover the timeout using F
> {Timeout, Default} = try F(timeout) of
> T -> T;
> catch
> _:_ -> {infinity, _}
> end,
> % Receive something and validate against F.
> receive Something ->
> try F(Something) of
> Result -> Result
> catch
> _:_ -> retain Something
> end
> after Timeout -> Default end.
>
> ...
> F = fun(Pattern1) -> Actions1;
> (Pattern2) -> Actions2 end;
> (timeout) -> {15000, Actions};
> ...
> receiveFun(F)
>
>
> Such "retain" thingie could be reused in more interesting contexts.
> However, one drawback is that retain would be useful only for the
> nearest enclosing "receive" context.
>
>
> Joe Armstrong wrote:
> > Now you mentioned receive it occurred to me that it would be rather nice
> to
> > receive a fun in Erlang. Unfortunately receive has only one syntactic
> form
> >
> > receive
> > pattern1 -> action1;
> > ...
> > end.
> >
> > In the spirit of funs it would be very nice to say:
> >
> > F = fun(Pattern1) -> Actions1
> > (Pattern2) -> Actions2
> > after Time -> Actions
> > end,
> > ...
> > receive(Fun)
> >
> > This would make writing an erlang meta interpreter much easier
> > and allow all kinds of mischief
> >
> > /Joe Armstrong
> >
> >
> >
> > On Nov 27, 2007 12:06 AM, Christian S <chsu79@REDACTED> wrote:
> >> 2007/11/26, Robert Virding <rvirding@REDACTED>:
> >>> or how about:
> >>> (: mod func arg1 arg2 ... )
> >>> for all cases?
> >> It seems like (? ...) and (! ...) are the chosen ways for receive and
> >> send, and (: M F A...) has a nice symmetry with that. That's a thumbs
> >> up. (However, I find that too many one-character symbols to make code
> >> be a bit "naked", I'm a fast enough typist that I dont mind spelling
> >> out full words and I think it makes code more readable in the end.)
> >>
> >> My initial feeling was that ':' would only be a reader macro, that
> >> there would be a full form for remote calls, just like how '(a b c) is
> >> shorthand for (quote (a b c)).
> >>
> >> As far as I understand, lisp started out being a theoretical model
> >> used to describe/reason about programs, until someone figured out it
> >> would be easy to make a computer evaluate them. It would probably be a
> >> sensible route to start erlang in sexprs too: write some programs,
> >> discover the needed features, then try to build an evaluator for it.
> >>
> >> _______________________________________________
> >> erlang-questions mailing list
> >> erlang-questions@REDACTED
> >> http://www.erlang.org/mailman/listinfo/erlang-questions
> >>
> > _______________________________________________
> > erlang-questions mailing list
> > erlang-questions@REDACTED
> > http://www.erlang.org/mailman/listinfo/erlang-questions
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20071127/56f0517f/attachment.htm>
More information about the erlang-questions
mailing list