[erlang-questions] My biggest beef with Erlang

Lev Walkin vlm@REDACTED
Tue Nov 27 10:40:04 CET 2007


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




More information about the erlang-questions mailing list