Re: [eclipse-users] 'forall' predicate

From: Joachim Schimpf <js10_at_...2...>
Date: Wed, 28 Mar 2007 12:20:43 +0100
Malcolm Ryan wrote:
> I want to construct a predicate which applies a certain constraint to  
> every variable in a list, kind of like the "map" function in  
> functional programming. Its logical semantics should be "for all X in  
> List : P(X)".
> 
> The following is close to what I want, but has a flaw:
> 
> forall(X, Vars, P) :-
>     (foreach(V, Vars), param(X,P)
>     do
>         copy_term((X,P), (Y,Q)),
>         Y = V,
>         call(Q)
>     ).
> 
> The problem is that the call to copy_term duplicates _every_ variable  
> in P, not just X. So the following will not work.
> 
> integers([N]), forall(X, [V1, V2, V3], X < N), N #= 3.


But that's exactly what the do-loops are for! You can write directly:

integers([N]), (foreach(X,[V1,V2,V3]),param(N) do X < N), N #= 3.


-- Joachim
Received on Wed Mar 28 2007 - 12:21:18 CEST

This archive was generated by hypermail 2.2.0 : Mon Jul 09 2018 - 02:05:29 CEST