This works :
%maplist(?P, ?L) : Apply the predicate P on each element in L
maplist(P, []).
maplist(P, [X|Xn]) :- call(P, X),maplist(P, Xn).
Lol zero isn't an odd integer.
So this is normal :
| ?- maplist(odd, [z]).
no
| ?- maplist(odd, [s(z)]).
true ?
yes
Thank you a lot :-)
Selon Paulo Moura <[email protected]>:
>
> On 2010/06/09, at 17:17, [email protected] wrote:
>
> > Hello,
> >
> > I am using GNU Prolog 1.3.1.
> >
> > I use this code :
> >
> > % int(?I) : I is an integer
> > int(z).
> > int(s(X)) :- int(X).
> >
> > % odd(?I) : I is an odd integer
> > odd(s(z)).
> > odd(s(s(X))) :- odd(X).
> >
> > % intzodd(?I) : I is an odd integer or zero (z)
> > intzodd(X) :- X=z.
> > intzodd(X) :- odd(X).
> >
> > % listzodd(?L) : L is a list which each element is an odd integer or zero
> (z)
> > listzodd(X) :- maplist(intzodd, X).
> >
> > And I don't find the maplist built-in predicate.
> >
> > | ?- listzodd([z]).
> > uncaught exception: error(existence_error(procedure,maplist/2),listzodd/1)
> >
> > Where is the maplist built-in predicate, please?
>
> maplist/2 is not a built-in predicate in GNU Prolog and, as far as I know, in
> any other Prolog compiler. Some Prolog compilers, however, provide it in a
> library. You will need to define it yourself. Is easy.
>
> Cheers,
>
> Paulo
>
>
> -----------------------------------------------------------------
> Paulo Jorge Lopes de Moura, PhD
> Assistant Professor
> Dep. of Computer Science, University of Beira Interior
> 6201-001 Covilhã, Portugal
>
> Office 3.18 Ext. 3276
> Phone: +351 275319891 Fax: +351 275319899
> Email: <mailto:[email protected]>
>
> Home page: <http://www.di.ubi.pt/~pmoura>
> Research: <http://logtalk.org/> Blog: <http://blog.logtalk.org/>
> -----------------------------------------------------------------
>
>
> _______________________________________________
> Users-prolog mailing list
> [email protected]
> http://lists.gnu.org/mailman/listinfo/users-prolog
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.