Re: newbie: Out of local stack, matching values from 0 to 10
- From: Jan Wielemaker <jan@xxxxxxxxxxxx>
- Date: 23 May 2005 07:26:18 GMT
On 2005-05-23, Matthijs Wensveen <mrw@xxxxxxxxxx> wrote:
> Hi,
> I recently started programmin in prolog again, just for fun. But
> immediately I encountered some major problems.
> I am trying to have prolog match any value from 0 to 10.
> What I have written so far:
> ---
> in_bounds(0).
>
> in_bounds(X) :-
> in_bounds(Y),
> X is Y + 1,
> X < 10.
> ---
>
> When I query in_bounds(X). all the values from 0 to and including 9 are
> matched, but then it says "ERROR: Out of local stack".
> I think I understand why, but I can't think of another way to do this.
A Prolog system with tabling like XSB will (as far as I understand it)
fix this. (but not for in_bounds(-1), right?)
> Actually I do:
>
> in_bounds(X) :- member(X, [0,1,2,3,4,5,6,7,8,9]).
>
> But this seems rather tedious.
A bit easier is
in_bounds(X) :-
between(0, 9, X).
> Secondly, is there a shorthand for lists like this? I would like to be
> able to write [1..10] or [1,..,10] or so.
You can generate lists for integers in a range using the numlist/3
library predicate.
Depending on the problem, you may wish to have a look at the constraint
library 'clp/bounds'.
Cheers --- Jan
.
- Follow-Ups:
- Re: newbie: Out of local stack, matching values from 0 to 10
- From: Bart Demoen
- Re: newbie: Out of local stack, matching values from 0 to 10
- References:
- newbie: Out of local stack, matching values from 0 to 10
- From: Matthijs Wensveen
- newbie: Out of local stack, matching values from 0 to 10
- Prev by Date: newbie: Out of local stack, matching values from 0 to 10
- Next by Date: Re: Efficiently finding combinations
- Previous by thread: newbie: Out of local stack, matching values from 0 to 10
- Next by thread: Re: newbie: Out of local stack, matching values from 0 to 10
- Index(es):
Relevant Pages
|
|