Home > Archive > Prolog > March 2005 > ensuring sucess upon backtracking
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
ensuring sucess upon backtracking
|
|
| michael.goodrich@gmail.com 2005-03-23, 3:58 pm |
| Greetings Prolog Community;
I am faced with a curious Prolog problem, and request some help.
I am doing a simulation in which a random variable is generated in a
goal which will prove subsequently to need a different 'randomized'
value since the first one will prove to be unsuitable for various
reasons. I would like to obtain a different random value by
backtracking successfully over the previously encountered rng predicate
in this single clause goal.
Would appreciate guidance on how to achieve this.
Thanx in advance,
-Mike Goodrich
| |
| student 2005-03-23, 8:58 pm |
| michael.goodrich@gmail.com wrote:
> Greetings Prolog Community;
>
> I am faced with a curious Prolog problem, and request some help.
>
> I am doing a simulation in which a random variable is generated in a
> goal which will prove subsequently to need a different 'randomized'
> value since the first one will prove to be unsuitable for various
> reasons. I would like to obtain a different random value by
> backtracking successfully over the previously encountered rng predicate
> in this single clause goal.
>
> Would appreciate guidance on how to achieve this.
>
> Thanx in advance,
>
> -Mike Goodrich
>
Sounds to me like you want a random number generator that "succeeds
forever". For example, in SWI-Prolog,
generate(X) :-
X is random(100).
generate(X) :-
generate(X).
(I learned this in another thread.)
--
| |
| michael.goodrich@gmail.com 2005-03-24, 4:00 pm |
| Thanx for your reply; I finally realized this late yesterday when I
recalled seeing some predicates defined this way either in Clocksin and
Mellish or maybe Shapiro, but thanks nonetheless. Actually it is not
the RNG goal that needs to be defined this way but the goal that is
making use of the RNG.
cheers,
-Mike
|
|
|
|
|