[erlang-questions] definition of iolist

Claes Wikstrom klacke@REDACTED
Fri Aug 31 17:02:57 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.
> 
5> list_to_binary(["abcdefg"| <<"bb">>]).
<<97,98,99,100,101,102,103,98,98>>
6> list_to_binary(["abcdefg"| $b]).

=ERROR REPORT==== 31-Aug-2007::17:01:39 ===
Error in process <0.39.0> with exit value: {badarg,[{erlang,list_to_binary,[["abcdefg"|98]]},{erl_eval,do_apply,5},{shell,exprs,6},{shell,eval_loop,3}]}

** exited: {badarg,[{erlang,list_to_binary,[["abcdefg"|98]]},
                     {erl_eval,do_apply,5},
                     {shell,exprs,6},
                     {shell,eval_loop,3}]} **

Note the | in the list as opposed to ,

In [1,2] the [] is the end of the list

/klacke



More information about the erlang-questions mailing list