[erlang-questions] closures and list comprehensions
Bengt Kleberg
bengt.kleberg@REDACTED
Mon Feb 18 09:06:51 CET 2008
Greetings,
You are correct, the list comprehension will be done in the spawned
process. Everything in the fun will be done when the fun is evaluated,
which is in the new process.
bengt
On Mon, 2008-02-18 at 00:05 +0200, Harold Ship wrote:
> Hello
>
> I'm fairly new to Erlang, and I'm just starting to get the hang of it.
>
> I have a question about using spawn/1, giving it a fun which is a
> closure that contains a list comprehension. The example is like this:
>
> my_func([First|Rest]) ->
> Me = self(),
> spawn(fun() -> Me ! do_something([X || X <- Rest, X < First]) end),
> do_something_else(),
> receive
> Result ->
> do_something_with(Result)
> end.
>
>
> My question is, in which process is the list comprehension evaluated?
> It seems to me that it should be evaluated in the spawned process but
> I can't reason it out.
>
> Thanks in advance,
> Harold Ship
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
More information about the erlang-questions
mailing list