Is it possible to write a predicate which takes an input list and "outputs" (succeeds) an output list with key-value pairs
example:
freqs([a,b,a,a,b,c],L).
L = [(a,3),(b,2),(c,1)]
I'd prefer to do this in O(n) if possible. The furthest I've gotten is this
freqs([],[]).
freqs(In,Out):-
freqs(In,[],Out).
freqs([],Out,Out).
freqs([X|Xs],Table,Out):-
\+ member((X,_),Table),
freqs(Xs,[(X,1)|Table],Out).
freqs([X|Xs],Table,Out) :-
member((X,N),Table),
% stuck
more specifick, how to increment N? And is there an other solution possible which doesn't need an auxiliary predicate?