Hi, as the Prolog newbie I am, I stumbled in some tutorial (I don’t remember which one) with the following little knowledge base:
age(harry,13). age(draco,14). age(ron,13). age(hermione,13). age(dumbledore,60). age(hagrid,30).
After some simple exercises with setof/3 and bagof/3, I tried to construct a goal whose answer would be a list containing sublists, each of which would include a non-duplicated age, and a list of characters with that age. Something that would look exactly as:
My best approximation, at this moment is:
setof([A,[Ch]], setof(A, age(Ch,A), B), All). B = , All = [[_1002486, [ron]], [_1002526, [hermione]], [_1002566, [harry]]] ; B = , All = [[_1002686, [draco]]] ; B = , All = [[_1002606, [hagrid]]] ; B = , All = [[_1002646, [dumbledore]]].
Or this one which is not very helpfull:
group_by(Age, AllAges, edad(Ch,Age), All). Age = 13, All = [_1008502, _1008470, _1008454] ; Age = 14, All = [_1008486] ; Age = 30, All = [_1008422] ; Age = 60, All = [_1008438].
Can anyone point me to a way to obtain the desired result?
Thanks in advance.