[erlang-questions] definition of iolist

Kostis Sagonas kostis@REDACTED
Fri Aug 31 17:11:25 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]).
> <<"abcdefgh">>

You probably have not fully grasped what constitutes the tail of a list.
Compare your thing above with:

	list_to_binary(["abcdefg" | $h]).
	list_to_binary(["abcdefg" | <<42>>]).


PS. I've repeatedly mentioned to the OTP group that there is very little
     reason for an IOList to allow binaries in the tail.

     Allowing binaries in the tail of the list only saves one cons cell
     but it disallows the use of many/most lists functions for IOLists.
     For example lists:length/1 cannot be safely used for IOLists because
     its use may or might not throw an exception.

     IMO, IOLists should not allow for binaries in the tail position.
     Other than that, IOLists are great.

More information about the erlang-questions mailing list