Rainer Krauskopf <mail(a)krauskopf-rainer.de> wrote: 1. I can define in Prolog "between(+,?,+)" : between(A,A,B) :- A =< B . between(A,X,B) :- A < B , A1 is A + 1 , between(A1,X,B) .
Please DON'T do that. For the last 20 years, the argument order of between/3 has been between(+LowerBound, +UpperBound, ?Element). Sample implementation:
between(L, U, X) :- ( integer(L), integer(U) -> ( integer(X) -> L =< X, X =< U ; var(X) -> L =< U, between_aux(L, U, X) ; /* report type failure in X */ ) ; var(L), integer(U), integer(X), X > U -> fail ; integer(L), var(U), integer(X), X < L -> fail ; /* diagnose and report type failure or instantiation fault */ /* in L or U */ ). between_aux(L, L, L) :- !. between_aux(L, _, L). between_aux(L, U, X) :- M is 1 + L, between_aux(M, U, X).
Part of the point of this is that the closure between(L,U) makes sense as a unary predicate, while *between(L,X) doesn't. However, it also follows the inputs-before-outputs principle, and is nicely consistent with numlist(L, U, [L,L+1,...,U]). ============================================================================== Message: Address: Action: help majordomo(a)clip.dia.fi.upm.es Info. on useful commands subscribe ciao-users-request(a)clip.dia.fi.upm.es Subscribe to this list unsubscribe ciao-users-request(a)clip.dia.fi.upm.es Unsubscribe from this list <whatever> ciao-users(a)clip.dia.fi.upm.es Send message to list ----------------------------------------------------------------------------- Archived messages: http://www.clip.dia.fi.upm.es/Mail/ciao-users/ -----------------------------------------------------------------------------
between_aux(L, L, L) :- !.
what happened to steadfast code ?
Bart Demoen ============================================================================== Message: Address: Action: help majordomo(a)clip.dia.fi.upm.es Info. on useful commands subscribe ciao-users-request(a)clip.dia.fi.upm.es Subscribe to this list unsubscribe ciao-users-request(a)clip.dia.fi.upm.es Unsubscribe from this list <whatever> ciao-users(a)clip.dia.fi.upm.es Send message to list ----------------------------------------------------------------------------- Archived messages: http://www.clip.dia.fi.upm.es/Mail/ciao-users/ -----------------------------------------------------------------------------