I am having a really hard time understanding how to get my code to show my segregated lists consisting of even and odd numbers. I am not even sure what my understanding is lacking. I am new to this language obviously and must use it for school. My imperative and functional mind won't let me know what the hell is going on with this lol.
Now, no I am not asking you to do my homework! I am simply asking you to help me see what my lack of understanding is. I have also looked up similar answers but I cannot convert them to the way I am supposed to write this function.
Please, once more, do not bash me for this like I have previously usually been bashed. Please just help me see what my understanding is lacking. Do not just give me answers and code snippets without explaining it please.
Here it is:
is_even(H) :-
0 is mod(H, 2).
segregate(List, Even, Odd) :- segregator(List, Even, Odd).
segregator([], [], []).
segregator([H|T], E, O) :-
is_even(H),
% I feel here is where I am supposed to build the list,
% but I have no clue how since Even or Odd has not been unified.
segregator(T, E, O),
write('Even is '), write(E), nl.
segregator([H|T], E, O) :-
% Same here as above.
segregator(T, E, O),
write('Odd is '), write(O), nl.
See Question&Answers more detail:os