Path: utzoo!mnetor!uunet!husc6!bloom-beacon!mit-eddie!uw-beaver!cornell!batcomputer!itsgw!nysernic!cmx!hilbert!hamid From: hamid@hilbert.uucp (Hamid Bacha) Newsgroups: comp.lang.prolog Subject: Re: Ranges of values in Cprolog Message-ID: <451@cmx.npac.syr.edu> Date: 5 May 88 19:14:45 GMT References: <242@yetti.UUCP> Sender: usenet@cmx.npac.syr.edu Reply-To: hamid@top.cis.syr.edu (Hamid Bacha) Organization: CIS Dept., Syracuse University Lines: 44 Try the following: %--------------- :- op(500, xfx, in). :- op(802, xfx, '..'). % precedence higher than that of '-' to allow % for negative numbers X in [S .. L] :- S < L, X = S. X in [S .. L] :- S < L, N is S + 1, X in [N .. L]. X in [X .. X]. %--------------- | ?- X in [-1 .. 2]. X = -1 ; X = 0 ; X = 1 ; X = 2 ; no | ?- X in [2 .. 1]. no | ?- X in [1 .. 1]. X = 1 ; no | ?- X in [1 .. +1]. no Note: The last two examples give different results because 1 is different from +1 in some Prolog systems (including CProlog 1.5). H. Bacha Logic Programming Research Group Syracuse University