[eclipse-users] 'forall' predicate

From: Malcolm Ryan <malcolmr_at_cse.unsw.edu.au>
Date: Wed, 28 Mar 2007 17:10:34 +1000
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.

The final binding of N does not effect V1, V2, V3 because they are  
each constrained with regard to a copy of N and not N itself.

Malcolm

--
"The modern man in revolt has become
           practically useless for all purposes of revolt.
By rebelling against everything
           he has lost his right to rebel against anything."
                                                    - G.K.Chesterton,  
Orthodoxy
Received on Wed Mar 28 2007 - 08:10:44 CEST

This archive was generated by hypermail 2.2.0 : Thu Feb 02 2012 - 02:31:57 CET