Path: utzoo!mnetor!uunet!husc6!mailrus!nrl-cmf!ames!lll-tis!mordor!sri-spam!sri-unix!quintus!ok From: ok@quintus.UUCP (Richard A. O'Keefe) Newsgroups: comp.lang.prolog Subject: Re: Ranges of values in Cprolog Message-ID: <933@cresswell.quintus.UUCP> Date: 6 May 88 00:23:53 GMT References: <242@yetti.UUCP> Organization: Quintus Computer Systems, Mountain View, CA Lines: 54 In article <242@yetti.UUCP>, asst-jos@yetti.UUCP (Jonathan) writes: > I am working with C-prolog 1.5, and have implemented the following > predicate for sets. (I use lists to implement sets) [code for member/2, written as an infix 'in'] > I would [like] to implement this 'in' operator to allow for the following: > (The '..' would have the same meaning as it does in Pascal). > ?- X in [1 .. 100]. > Unfortunately, I keep running into problems when attempting this, and I am > tired of hitting my head against a brick wall. Any suggestions??? If you didn't get the CProlog version of the DEC-10 Prolog library with your copy of CProlog, ask whoever you got your CProlog licence from to explain why not. If you _did_ get the library, you'll find a predicate between(LowerBound, UpperBound, X) <-> all arguments integer & LowerBound <= X <= UpperBound and you can adapt that. You'll need to define your 'in' a little bit more clearly. What, if anything, should c in [1..10,alpha..gamma,no(c)] do? It is rather ugly to have a list whose elements are not of the same "type", and 5 and 4..6 seem to me to be of different "types". A clean approach to the design of such a data structure might go like this: a can be % type intset --> an set % {} a set % | {integer} an , or % | integer..integer a of two sets. % | intset + intset Coding this, we obtain :- current_op(Prio, yfx, *), op(Prio, xfx, ..). :- current_op(Prio, xfx, <), op(Prio, xfx, in). :- lib(between). % CProlog 1.5.edai :- compile(library(between)). % Quintus Prolog in(Element, Set) :- in1(Set, Element). in1({Element}, Element). in1(Low..High, Element) :- between(Low, High, Element). in1(Set+_, Element) :- in1(Set, Element). in1(_+Set, Element) :- in1(Set, Element). This works just fine in Quintus Prolog (e.g. "X in {1}+2..4+{5}" enumerated the results 1,..,5). What are the problems you keep running into?