erlang程序设计8.11的习题

第二题:

-module(for).
-export([for/3,empty_proc/0,post_msg/1]).

for(N,N,F)->[F()];
for(I,N,F)->[F() | for(I+1,N,F)].

empty_fun()->
	receive
		_Any->
			io:format("~w is exit",[self()])
	end.

post_msg([]) -> void;
post_msg([Head | Tail])-> Head ! "Other",
			  post_msg(Tail).

 在shell里面输入

CreateProc=fun()->spawn(fun for:empty_proc/0) end. %创建进程的函数

PidList=for:for(1,10,CreateProc).  %创建10个进程

for:post_msg(PidList).  发送消息给进程

这几天写erlang的感觉已经来了^-^

原文地址:https://www.cnblogs.com/linyilong3/p/2528770.html