代码之家  ›  专栏  ›  技术社区  ›  hcs42

是否有处理IO的组长协议的规范?

  •  5
  • hcs42  · 技术社区  · 16 年前

    在Erlang中,每个进程都有一个组长,当一个进程想要打印某些内容(即它调用IO库或执行类似的操作)时,它将向其组长发送一条消息。

    我的问题是,在哪里可以找到这些消息的规范?或者一般来说,一个团队领导应该做什么的规范?

    我设法通过一些实验发现,有时候这个过程会发送一个 {io_request, Sender, GroupLeader, Request} 术语,答案是 {io_reply, GroupLeader, ok} 期限,但可能还有其他情况。

    2 回复  |  直到 11 年前
        1
  •  6
  •   Roger Lipscombe    11 年前

    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)
    
        2
  •  1
  •   luksan    11 年前

    此处详细描述了Erlang I/O协议:

    http://www.erlang.org/doc/apps/stdlib/io_protocol.html