在Erlang中,每个进程都有一个组长,当一个进程想要打印某些东西(即它调用io库或做类似的事情)时,它会向其组长发送消息。是否有处理IO的组长协议的规范?
我的问题是,我在哪里可以找到这些消息的规范?或者一般来说,小组领导应该做什么的规范?
我设法找出一些实验,有时过程发送{io_request, Sender, GroupLeader, Request}
条款,答案是{io_reply, GroupLeader, ok}
条款,但也可能有其他情况。
在Erlang中,每个进程都有一个组长,当一个进程想要打印某些东西(即它调用io库或做类似的事情)时,它会向其组长发送消息。是否有处理IO的组长协议的规范?
我的问题是,我在哪里可以找到这些消息的规范?或者一般来说,小组领导应该做什么的规范?
我设法找出一些实验,有时过程发送{io_request, Sender, GroupLeader, Request}
条款,答案是{io_reply, GroupLeader, ok}
条款,但也可能有其他情况。
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)
Erlang的I/O协议在这里详细地描述: