SHARE
TWEET

Untitled

a guest Mar 19th, 2019 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. %szukanie potwierdzenia cechy obiektu w dynamicznej bazie
  2. positive(X,Y) :-
  3.     xpositive(X,Y),!.
  4. positive(X,Y) :-
  5.     not(xnegative(X,Y)), ask(X,Y,yes).
  6.    
  7. negative(X,Y) :-
  8.     xnegative(X,Y),!.
  9. negative(X,Y) :-
  10.     not(xpositive(X,Y)) ,
  11.     ask(X,Y,no).
  12.    
  13. %zadawanie pytań użytkownikowi
  14. ask(X,Y,yes) :-
  15.     write(X), write(' it '),write(Y), write('\n'),
  16.     read(Reply),
  17.     sub_string(Reply,0,1,_,'y'),!,
  18.     remember(X,Y,yes).
  19.    
  20. ask(X,Y,no) :-
  21.     write(X), write(' it '),write(Y), write('\n'),
  22.     read(Reply),
  23.     sub_string(Reply,0,1,_, 'n'),!,
  24.     remember(X,Y,no).
  25.  
  26. %zapamiętanie odpowiedzi w dynamicznej bazie
  27. remember(X,Y,yes) :-
  28. asserta(xpositive(X,Y)).
  29. remember(X,Y,no) :-
  30. asserta(xnegative(X,Y)).
  31.  
  32. %uruchomienie programu
  33. run :-
  34.     vehicle_is(X),!,
  35.     write('\nYour vehicle may be a(n) '),write(X),
  36.     nl,nl,clear_facts.
  37. run :-
  38.     write('\nUnable to determine what'),
  39.     write('your vehicle is.\n\n'),clear_facts.
  40.  
  41. %wyczyszczenie zawartości dynamicznej bazy
  42. clear_facts :-
  43. retract(xpositive(_,_)),fail.
  44. clear_facts :-
  45. retract(xnegative(_,_)),fail.
  46. clear_facts :-
  47. write('\n\nPlease press the space bar to exit\n').
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top