[eclipse-users] 'forall' predicate

From: Malcolm Ryan <malcolmr_at_...25...>
Date: Wed, 28 Mar 2007 16:57:12 +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 - 07:57:30 CEST

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