1. Pid = spawn(Fun)
创建并发进程对Fun求值,新创建的进程和调用者所在进程并发运行。
可以向新创建的进程Pid发送消息 Pid!M. 或者想多个进程发送消息 Pid1 ! Pid2 !...Pidn ! M . !号为发送消息运算符
注意:消息的发送是异步的,直接返回消息本身。
接受发送给当前进程的消息语法:
receive
Pattern1 [when Guard1] ->
Expressions1;
Pattern2 [when Guard2] ->
Expressions2;
end
注意: 未处理的消息交给后续过程来处理,就像人对一些外界的信息可以分时段或不处理一样。进程就像一个人。2.进程简单例子: 由计算面积函数改造而来 area_server0.erl
-module(area_server0).
-export([loop/0]).
loop() ->
receive
{rectangle, Width, Ht} ->
io:format("Area of rectangle is ~p~n",[Width * Ht]),
loop();
{circle, R} ->