gowtham wrote:
> Hi All,
> Bear with this newbie. I come from procedural programming and started to
> learn prolog a week ago. Though, I really appreciate its amazing capacity,

I had a look at your code and tried to execute it without examining it
closely. It complained about undefined flag/3 predicate in count/2. After
commenting it out it ran fine.

> My quaries are getting the solutions but, i have problem in counting the
> solutions.

> count_pcg0(X) :-

Writes _29 here.

> count_pcg(X) :-

Writes _29_29 here. My impression is you are not using GNU Prolog and we
get wildly different results. I suggest another solution.

findall/3 is very useful for collecting solutions.

findall(GOAL, prop(GOAL, is_coding, 'YES'), LIST) will return a LIST of
atoms satisfying query given as second argument to this findall
invocation.

Use this in count_pcg0(X) predicate to simplify it. You'll need to count
elements in list but this allows you to remove duplicates if you wish.

count_pcg(X) is only a little bit trickier. A possible solution is to
combine all conditions into a single predicate.

cond_pcg(X) :-
node(X),
prop(X, is_coding, 'YES'),
prop(X, located_on, 'Lmjchr1').

-- 
Michał Bieliński


_______________________________________________
Users-prolog mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/users-prolog

Reply via email to