[erlang-questions] Baffling lists

Dmytro Lytovchenko dmytro.lytovchenko@REDACTED
Sun Sep 21 17:00:32 CEST 2014


Oh and also its list of another list and 0 as tail element. You probably
want to reverse first element of L4, like lists:reverse(hd(L4)).

On Sun, Sep 21, 2014 at 4:51 PM, Dmytro Lytovchenko <
dmytro.lytovchenko@REDACTED> wrote:

> It is irregular list, that is list which doesn't have [] as tail element,
> and has 0 there instead. While its legal to have such a value, some list
> handling functions will be waiting for [] as tail element thus they will be
> confused.
> Solution: don't have 0 there, or cut it away temporarily and append later
> as X = [CutList | 0].
>
> On Sun, Sep 21, 2014 at 4:46 PM, Stu Bailey <stu.bailey@REDACTED> wrote:
>
>> I'm sure I'm missing something obvious, but here goes:
>>
>> What is going on here?  Is L4 a list?  If so, why can't I reverse it?
>>
>> 70> L4.
>>
>> [[<<"8">>,<<"7">>,<<"6">>,<<"5">>],
>>
>>  [<<"4">>,<<"3">>,<<"2">>,<<"1">>]|
>>
>>  0]
>>
>> 71> lists:reverse(L4).
>>
>> ** exception error: bad argument
>>
>>      in function  lists:reverse/2
>>
>>         called as lists:reverse(0,
>>
>>                                 [[<<"4">>,<<"3">>,<<"2">>,<<"1">>],
>>
>>                                  [<<"8">>,<<"7">>,<<"6">>,<<"5">>]])
>>
>>      in call from lists:reverse/1 (lists.erl, line 152)
>>
>> 72> [Head1|Rest1] = L4.
>>
>> [[<<"8">>,<<"7">>,<<"6">>,<<"5">>],
>>
>>  [<<"4">>,<<"3">>,<<"2">>,<<"1">>]|
>>
>>  0]
>>
>> 73> Rest1.
>>
>> [[<<"4">>,<<"3">>,<<"2">>,<<"1">>]|0]
>>
>> 74> lists:reverse(Rest1).
>>
>> ** exception error: no function clause matching
>> lists:reverse([[<<"4">>,<<"3">>,<<"2">>,<<"1">>]|0]) (lists.erl, line 145)
>>
>> 75> [Head2|Rest2] = Rest1.
>>
>> [[<<"4">>,<<"3">>,<<"2">>,<<"1">>]|0]
>>
>> 76> Head2.
>>
>> [<<"4">>,<<"3">>,<<"2">>,<<"1">>]
>>
>> 77> Rest2.
>>
>> 0
>>
>> 78>
>>
>>
>> In practice, the kind of structure demonstrated in L4 is being returned
>> by a function from another library I'm trying to use, but I'm trying to
>> understand what's going on in general.
>>
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://erlang.org/mailman/listinfo/erlang-questions
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140921/2cb60147/attachment.htm>


More information about the erlang-questions mailing list