We have facts
studies(cse, plc).
studies(cse, da).
studies(it, se).
studies(it, plc).
where studies(x,y) means that branch x studies module y . Now I Want to define Rule To count number of modules in all. like here it will be 3.that are (plc,da,se).PLZ HELP.
What will be the query to find how many subjects studies under CSE.
sort/2
removes duplicate elements.The arguments of
findall/3
are, from left to right, (1) a template for the answer which is to be collected, (2) the goal from which the answer is drawn, (3) the a list of all answers. So you could, for instance, label each module as such by using a different template in (1):Documentation on this and related predicates can be found in section 4.3 of the manual.
having tagged SWI-Prolog your question, take a look at library(aggregate):
library(aggregate) is powerful, learning about it can be really rewarding...
I will not tell you the solution but this can help you to find it out by yourself:
If you want to count the modules then you need a list of modules and take its length.
Always remember this sentence:
Using this you can construct lists of your modules recursively.
Make sure, no element is in the list twice.