# Re: [eclipse-users] 'forall' predicate

From: Malcolm Ryan <malcolmr_at_...25...>
Date: Thu, 29 Mar 2007 13:02:10 +1000
```Yes, but I want the constraints to be passed around as data before
being applied. I'm working towards adding a feature to the
"generic_sets" library so that you can specify a bunch of constraints
that are applied to every element of the set. As such, they need to
be stored as terms in the set's attributes so that they can be
applied to any new value that is in the set.

Basically, I want a way to do the equivalent of a lambda operation in
functional programming, on a constraint expression. So that I can
say: lambda(X, X #< N or X #> 0).

I am beginning to remember why I dislike Prolog. It tempts you into
thinking you can do functional-style programming with maps and lambda
expressions, but then the handling of unbound variables is always
awkward, and you end up wasting a lot of time preventing them from
binding to things you don't want them to.

Malcolm

On 28/03/2007, at 9:20 PM, Joachim Schimpf wrote:

> 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
>
> _______________________________________________
> ECLiPSe-Users mailing list
> ECLiPSe-Users_at_...2...
> http://www.crosscoreop.com/mailman/listinfo/eclipse-users

--
"The Christian ideal has not been tried and found wanting;
it has been found difficult and left untried."
- G.K.Chesterton, What's Wrong With The World
```
Received on Thu Mar 29 2007 - 04:02:31 CEST

This archive was generated by hypermail 2.3.0 : Sat Aug 24 2019 - 21:14:55 CEST