[erlang-questions] definition of iolist
Fri Aug 31 17:25:39 CEST 2007
David Terrell wrote:
> On Fri, Aug 31, 2007 at 02:27:54PM +0200, Bjorn Gustavsson wrote:
>> Anthony Shipman <als@REDACTED> writes:
>>> The documentation often says this:
>>> iolist = [char() | binary() | iolist()]
>>> a binary is allowed as the tail of the list
>>> This says to me that an iolist is a list whose members can be characters,
>>> binaries or iolists. In which case it is automatic that a binary can be the
>>> tail of the list. So what is the point of the comment?
>> A character is not allowed in the tail.
> I think I'm misunderstanding you... wouldn't this forbid a
> normal erlang string from being considered a valid iolist?
> 1> list_to_binary(["abcdefg", $h]).
I think not. The list in your example actually ends
with an empty list ():
[$a | [$b | [$c | [$d]]]]
and therefore it is a valid iolist. But the following
is NOT an iolist:
[$a | [$b | [$c | $d]]]]
The difference is in the last $d character.
Hope this helps,
More information about the erlang-questions