Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

between when +High is infinite

0 views
Skip to first unread message

metaperl

unread,
Nov 4, 2009, 11:34:17 AM11/4/09
to
re: http://www.swi-prolog.org/pldoc/man?predicate=between%2f3

I wrote a simple program to play with the mundane use of this
predicate:
someio :- between(2,5,X), write(X), nl, fail.


But I dont understand the practical use of making the second argument
infinite:
between(X,infinite,Y)

And I also dont understand what the docs are saying exactly:
"""If High is inf or infinite, between/3 is true iff Value >=Low, a
feature that is particularly interesting for generating integers from
a certain value."""

Ulrich Neumerkel

unread,
Nov 4, 2009, 1:56:30 PM11/4/09
to

Many implementations of between/3 do not have this feature.
For this reason I write length(_, N). This is very useful in
situations where you are searching for counterexamples.

Concerning between/3, it is not clear whether or not the name
infinite or inf is ideal, since in clpfd implementations inf
refers to the infimum. I.e.,

?- X #< 2.
X in inf..1.

Whereas the other side is called sup:

?- X#> 1.
X in 2..sup.

Jan Wielemaker

unread,
Nov 5, 2009, 10:19:40 AM11/5/09
to

Typically, you need this if you want to generate increasing integers
until some condition is met and you have no clue when that will be.
So, you write

...
between(0, infinite, N),
is_this_want_i_want(N), !,
...

Using infinite is a bit more informative than writing this, even if you
know that 1 million is plenty. Of course, the downside is that the above
is a nearly infinite loop if is_this_want_i_want/1 never succeeds
(nearly, because memory is finite and the increasing N will keep using
more :-)

between(0, 1000000, N),

--- Jan

0 new messages