users-prolog
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Where is the maplist built-in predicate ?


From: spam . spam . spam . spam
Subject: Re: Where is the maplist built-in predicate ?
Date: Wed, 09 Jun 2010 19:06:12 +0200
User-agent: Internet Messaging Program (IMP) 3.2.8

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 <address@hidden>:

>
> On 2010/06/09, at 17:17, address@hidden 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:address@hidden>
>
> Home page: <http://www.di.ubi.pt/~pmoura>
> Research:  <http://logtalk.org/> Blog: <http://blog.logtalk.org/>
> -----------------------------------------------------------------
>
>
> _______________________________________________
> Users-prolog mailing list
> address@hidden
> http://lists.gnu.org/mailman/listinfo/users-prolog
>





reply via email to

[Prev in Thread] Current Thread [Next in Thread]