I have these facts:
vehicle(car,blue,[wheel,horn,optional(radio)]).
vehicle(motorcycle,blue,[wheel,optional(navigation),horn]).
vehicle(truck,white,[wheel,horn,optional(trailer)]).
I want to count all optional items (all "optional") of all blue vehicles - in this case 2. Right now I have a predicate that creates a nested list with the component lists of all blue vehicles:
countAllOptionalComponents:-
findall(X,vehicle(_,blue,X),S),
write(S).
[ [wheel,horn,optional(radio)], [wheel,optional(navigation),horn] ]
My idea was to pass this nested list to another predicate to count all optional components of all "sub-lists", but I'm having trouble. Something like this:
countAllOptionalComponents:-
findall(X,vehicle(_,blue,X),S),
countOptComponents(S,N).
countOptComponents([],0).
countOptComponents([X,Y],N):-
[...]
Maybe the approach I'm following doesn't make much sense.