0
votes

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)

1
That's because the 3rd argument of lists:foldl expects a list, while in this line {Acc1, Acc2} = lists:foldl(A, {[],[]}, Tr),, Tr is NOT a list -> because you do this foa1([{Tr}|Ot], {A1,A2}), it makes Tr as the element of the first Tuple, i.e. yielding 12456 on the first iteration. - Agus
Thanks a lot @Agus, your comment helped me figure it out !! Everything worked out! - Aleksey Samotokin

1 Answers

-1
votes

The issue is resolved! I have corrected the format of the list sent to work. Thanks to all