- Mail actions: [ respond to this message ] [ mail a new topic ]
- Contemporary messages sorted: [ by date ] [ by thread ] [ by subject ] [ by author ] [ by messages with attachments ]

From: Joachim Schimpf <js10_at_...2...>

Date: Wed, 28 Mar 2007 12:20:43 +0100

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. -- JoachimReceived on Wed Mar 28 2007 - 12:21:18 CEST

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