[erlang-questions] Baffling lists
Stu Bailey
stu.bailey@REDACTED
Sun Sep 21 16:46:51 CEST 2014
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140921/409fccd9/attachment.htm>
More information about the erlang-questions
mailing list