The right hand side of ::/2 is also just a list, only in a slightly different format from what you have as input. So you just translate your input list [[10, 20], [15, 30], [40, 50]] to the kind of list that the ::/2 predicate expects, i.e. input_to_intervals(In, Out) :- ( foreach([Min,Max],In), foreach(Min..Max,Out) do true ). ?- input_to_intervals([[10, 20], [15, 30], [40, 50]], Intervals), X :: Intervals. Intervals = [10 .. 20, 15 .. 30, 40 .. 50] X = X{[10 .. 30, 40 .. 50]} Yes (0.00s cpu) Sergey Dymchenko wrote: > Thank you, but the main question how to construct that domain X :: > [10..20, 15..30, 40..50] if I have a list of interval boundaries [[10, > 20], [15, 30], [40, 50]] (I read them from a file, number of intervals > can be different). > I can't see how do this simpler than in my model/2 > > Sergey. > > On Sun, Nov 6, 2011 at 2:18 AM, Joachim Schimpf <jschimpf_at_coninfer.com> wrote: >> Sergey Dymchenko wrote: >>> [eclipse 1]: model([[10, 20], [15, 30], [40, 50]], Domain), >>> query(Domain, 1, A1), query(Domain, 10, A2), query(Domain, 35, A3). >>> >>> Domain = [10 .. 30, 40 .. 50] >>> A1 = "No" >>> A2 = "Yes" >>> A3 = "No" >>> Yes (0.00s cpu) >> Hi Sergey, >> >> you can achieve that simply via >> >> ?- X :: [10..20, 15..30, 40..50], is_in_domain(1, X, B1), is_in_domain(10, X, B2). >> X = X{[10 .. 30, 40 .. 50]} >> B1 = no >> B2 = yes >> Yes (0.00s cpu) >> >> >> -- JoachimReceived on Sun Nov 06 2011 - 09:01:00 CET
This archive was generated by hypermail 2.2.0 : Thu Feb 02 2012 - 02:31:58 CET