length of an iolist

Mark Scandariato <>
Mon Aug 15 22:47:57 CEST 2005


>From the current docs (.../erl5.4.8/lib/kernel-2.10.9/doc/html/erlang.html):

"Some BIFs, such as list_to_binary_1, take I/O lists as documents (written as iolist() in type descriptions). An I/O list is a deep list of binaries, integers in the range 0 through 255, and other I/O lists. In an I/O list, a binary is allowed as the tail of a list."

...

"list_to_binary(DeepList)

Types:

DeepList = iolist()

Returns a binary which is made from the integers and binaries in List. List may be deep and may contain any combination of integers and binaries.

Example: list_to_binary([Bin1,1,[2,3,Bin2],4|Bin3])

Failure: badarg if List is not a list, or if it or any sublist contains anything else than binaries or integers in the range [0, 255]."


Mark.

PS: I agree that a single binary would be a reasonable thing to pass to such a function - but the docs appear to differ.

-----Original Message-----
From: Scott Lystig Fritchie <>
Sent: Aug 15, 2005 4:20 PM
To: Mark Scandariato <>
Cc: 
Subject: Re: length of an iolist 

>>>>> "ms" == Mark Scandariato <> writes:

ms> I originally had one, but I took it out since "iolist" is supposed
ms> to be a list.

I suspect that the name "i/o list"/"iolist"/whatever was coined before
the binary data type was added to Erlang ... so nowadays a proper
iolist may be either:

    * a (possibly deep) list of:
      - integers representing byte values
      and/or
      - binaries

    * a single binary

Looking in some old R9 documentation for gen_tcp:send/2:

    send(Socket, Packet) -> ok | {error, Reason}
    
    Types: 
       Socket = socket()
       Packet = list() | binary()
       Reason = atom()

Now that binaries are part of the language, it seems silly not to
include a single binary as a valid packet to send.  Ditto for a
function like file:write/2:

    write(IoDevice, Bytes)
    
        Writes Bytes (possibly a deep list of characters, or a binary) to the
        file described by IoDevice. [...]

Though neither definition really says that your (deep) list of
characters may also include binaries of arbitrary size.

Hm, in my R9 docs, "iolist" (and various spelling variations) do not
appear in .../kernel-2.9/doc/html/index.html index.  Does it appear in
the R10 docs?

-Scott
---
Scott Lystig Fritchie
Professional Governing: Is It Faked?






More information about the erlang-questions mailing list