strange behaviuor



Hi,
I'm coding my first program in prolog and I have some difficulties:
I'm trying to code a program that given a random number without repeats the same number.


The problem is when the program starts no random numbers are choosen of course, but "casuale" with the "not" should give true and exit from the loop.
However only the second "casuale" give true and enter in a loop.


What's wrong?

Thanx in advance to all who will help me.

Marco


this is the code:


initial_state([ domandefatte([]), risposte([]), status([asking]) ]).


get_state(State, domandefatte, N) :- member(domandefatte(Done), State), member(N, Done).


casual(S,N,N1):-N is random(3),casuale(S,N,N1).
casuale(S,N,N1):-not(get_state(S,domandefatte,N)), N1 is N.
casuale(S,N,N1):-get_state(S,domandefatte,N), N2 is random(3),casuale(S,N2,N1,B).



start:-initial_state(Old),casual(Old, N, N1). .



Relevant Pages

  • Re: some quick help with lists
    ... >> What I thought would be a simple first program to write in Prolog has ... > Arithmetic only works one way in plain Prolog: it is a one way constraint. ... > solver included in SWI-Prolog. ...
    (comp.lang.prolog)
  • some quick help with lists
    ... What I thought would be a simple first program to write in Prolog has ... list length that I could specify so it doesn't loop forever. ... Perhaps my code needs to ...
    (comp.lang.prolog)
  • Re: newbie question
    ... > Today is my first day of Prolog. ... > already it blows my mind. ... I've never seen such a cool language. ... > first program doesn't work. ...
    (comp.lang.prolog)
  • newbie question
    ... Today is my first day of Prolog. ... already it blows my mind. ... I've never seen such a cool language. ... first program doesn't work. ...
    (comp.lang.prolog)
  • Re: Calling C code in prolog
    ... Each Prolog has its own manual that describes ... I am coding in SWI prolog, and want to callm a single predicate that i ...
    (comp.lang.prolog)