Can you please tell me what's wrong in line 53 of the code? As i understand it should return {[{12456},{77777}, {99999}, {88888}], []}. Why is not matching and how to fix it? Thank!
fu() ->
Tr = [{12456},{77777}, {99999}, {88888}],
car:foa1(Tr, {[],[]}).
foa1([], Acc) -> Acc;
foa1([{Tr}|Ot], {A1,A2}) ->
Direction = unknown,
A = fun(T, {Acc1, Acc2}) ->
case Direction of
unknown -> {[T | Acc1], Acc2};
_ -> {Acc1, [T | Acc2]}
end
end,
{Acc1, Acc2} = lists:foldl(A, {[],[]}, Tr),
foa1 (Ot, {A1 ++Acc1, A2 ++ Acc2}).
** exception error: no function clause matching lists:foldl(#Fun<car.0.18093156>,{[],[]},12456) (lists.erl, line 1262) in function car:foa1/2 (car.erl, line 53)
lists:foldlexpects a list, while in this line{Acc1, Acc2} = lists:foldl(A, {[],[]}, Tr),,Tris NOT a list -> because you do thisfoa1([{Tr}|Ot], {A1,A2}), it makesTras the element of the first Tuple, i.e. yielding12456on the first iteration. - Agus