Re: for loop in prolog
- From: Jan Wielemaker <jan@xxxxxxxxxxxxxxxxxxx>
- Date: 16 Jan 2006 21:06:20 GMT
On 2006-01-16, Diogo Bastos <damrho@xxxxxxxxxx> wrote:
> % my_for(start_value,end_value,increment,action)
> my_for(V,V,_,_) :- !.
> my_for(Start,End,Inc,Action) :-
> End > Start,
> NewValue is Start+Inc,
> call(Action),
> my_for(NewValue,End,Inc,Action).
Nice, but if you want to go into the trouble of proving a start
and a step, you probable want to pass the current value to the action
predicate. The following however won't work:
?- my_for(0, 10, 1, writeln(X)).
1
2
....
--- Jan
> "nobody" <nobody@xxxxxxxxxxxxxx> escreveu na mensagem
> news:pan.2006.01.10.19.29.18.959870@xxxxxxxxxxxxxxxxx
>> hi to all,
>>
>> How could i implement a for loop in prolog. Let's say for
>> example that i have an integer variable X and i want to repeat X
>> times a specific action. Any idea welcome...
>
>
.
- References:
- for loop in prolog
- From: nobody
- Re: for loop in prolog
- From: Diogo Bastos
- for loop in prolog
- Prev by Date: Re: problem:4x4magicSquare in prolog
- Next by Date: comp.lang.prolog Frequently Asked Questions
- Previous by thread: Re: for loop in prolog
- Next by thread: http_open vs. http_get using proxy
- Index(es):