I wrote a prolog program to count the number of 1's in a list.
I am using SWI prolog.
%--------------------------------
count([],0).
count([1|T], N) :-
count(T,M);
N is M+1.
count([H|T], N) :-
count(T, N).
one(1).
%--------------------------------
When I try the query
?- count([1,2,3],N).
I am getting the answer as YES.
It is not giving any other thing. I want instantiations for N.
All the other are getting printer correctly except this.
In article <························@i38g2000prf.googlegroups.com>,
······@gmail.com wrote:
> I wrote a prolog program to count the number of 1's in a list.
> I am using SWI prolog.
>
>
> %--------------------------------
> count([],0).
> count([1|T], N) :-
> count(T,M);
> N is M+1.
>
> count([H|T], N) :-
> count(T, N).
>
> one(1).
> %--------------------------------
>
> When I try the query
>
> ?- count([1,2,3],N).
>
> I am getting the answer as YES.
>
> It is not giving any other thing. I want instantiations for N.
>
> All the other are getting printer correctly except this.
Checkout comp.lang.prolog ! ;-)
--
http://lispm.dyndns.org