2008-11-12 50 views
5

在Erlang中,每個進程都有一個組長,當一個進程想要打印某些東西(即它調用io庫或做類似的事情)時,它會向其組長髮送消息。是否有處理IO的組長協議的規範?

我的問題是,我在哪裏可以找到這些消息的規範?或者一般來說,小組領導應該做什麼的規範?

我設法找出一些實驗,有時過程發送{io_request, Sender, GroupLeader, Request}條款,答案是{io_reply, GroupLeader, ok}條款,但也可能有其他情況。

回答

6

The Erlang Rationale (video)(slides);是一個很好的信息來源,user.erl的源代碼也是如此。

簡而言之:

{io_request, From, ReplyAs, Request} 
    %From is the process to send the reply to, 
    %ReplyAs is any term the caller desires to 
    %match up the request and the response. (returned verbatim in the reply) 
    {io_reply, ReplyAs, Reply} 

在user.erl有些請求:

{put_chars, IoList} % puts the iolist 
{put_chars, M,F,A} % puts the result of apply(M,F,A) 
{get_geometry, 'rows' | 'columns'} % returns the number of rows or columns of the console 
{get_line, Prompt} % calls io_lib:collect_line(Prompt) 
{get_chars, Prompt, Mod, Func, ExtraArgs} 
{get_until, Prompt, Mod, Func, Args} 
{setopts, Options} % only option supported by user is 'binary' 
        % (binary mode if present in Options, list mode otherwise)