How can I send all elements of a list one by one, from the original process to another process through message passing in Erlang?
Asked
Active
Viewed 275 times
1 Answers
1
You could use a list comprehension. For example, assume Pid
represents the target process, and List
is the list whose elements you want to send to Pid
:
[Pid ! Element || Element <- List]

Steve Vinoski
- 19,847
- 3
- 31
- 46
-
This answer seems the most appropriate to me based on the question, but I figured I would throw a couple of reference links in here in case the asker finds them helpful: http://learnyousomeerlang.com/starting-out-for-real and http://www.erlang.org/doc/programming_examples/list_comprehensions.html – Jan 24 '16 at 16:39
-
tnx @Steve problem is that its just sent the first element of the list...!? – koko Jan 24 '16 at 17:42
-
@koko: you need to check again, as this will, without question, send an entire list, one by one, to `Pid` assuming `Pid` stays alive, the sending process stays alive, `List` is actually a list, etc. Perhaps you're hitting an error of some sort? Another way to try would be `lists:foreach(fun(X) -> Pid ! X end, List).`, which does essentially the same thing. If you're still having problems you'll have to post more details in a new question so others can see what's going wrong. – Steve Vinoski Jan 24 '16 at 18:13
-
@SteveVinoski: I explained in another question did you saw it (http://stackoverflow.com/questions/34979403/erlang-massage-passing-between-process) – koko Jan 24 '16 at 19:20