users-prolog
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

problems with not and unasserted facts


From: Cliff Bender
Subject: problems with not and unasserted facts
Date: Tue, 30 Aug 2005 19:24:08 -0400

Hi. I'm new to prolog, but am trying to learn the language to fulfill a prereq for a grad school program. I'm currently using Niel C. Rowe's "Artificial Intelligence Through Prolog" for reference and sample programs. I've typed out the traffic program on pages 61-62:

/*--------Rules for arrow lights--------*/
/*A*/   action(car, stop) :- light(yellow_arrow, Direction), safe_stop_possible.
/*D,E*/ action(car, yield_and_leftturn)  :- light(yellow_arrow, left), not(safe_stop_possible).
/*D,E*/ action(car, yield_and_rightturn) :- light(yellow_arrow, right), not(safe_stop_possible).
/*D*/   action(car, yield_and_leftturn)  :- light(green_arrow, left).
/*D*/   action(car, yield_and_rightturn) :- light(green_arrow, right).

/*--------Rules for regular lights------*/
/*A*/ action(car, stop) :- light(red, steady).
/*A*/ action(car, stop_and_go) :- light(red, flashing).
/*C*/ action(car, stop) :- light(yellow, steady), safe_stop_possible.
/*C*/ action(car, yield_and_go) :-light(yellow, steady), not(safe_stop_possible).
/*B*/ action(car, yield_and_go) :- light(green, steady).
/*C*/ action(car, slow) :- light(yellow, flashing).
/*A*/ action(car, stop) :- light(red_arrow, Direction).

/*--------Rules for pedestrian lights-------*/
action(pedestrian, stop) :- pedhalt(steady).
/*I*/ action(pedestrian, stop) :- not(pedsignals), greenfacing.
action(pedestrian, stop) :- pedhalt(flashing), safe_stop_possible.
/*H*/ action(pedestrian, yield_and_go) :- pedhalt(flashing), not(safe_stop_possible).

/*--------Default rules---------------------*/
/*I*/ action(pedestrian, A) :- not(pedsignals), not(greenfacing), action(car, A).
action(car, go) :- not(caution_needed(car)).
action(pedestrian, go) :- not(caution_needed(pedestrian)).

/*--------Rules defining the special terms--*/
/*G*/ pedhalt(State) :- light(wait, State).
/*G*/ pedhalt(State) :- light(dont_walk, State).
/*G*/ pedhalt(State) :- light(hand, State).

/*G*/ pedgo(State) :- light(walk, State).
/*G*/ pedgo(State) :- light(walking_person, State).

pedsignals :- pedhalt(State).
pedsignals :- pedgo(State).

greenfacing :- light(green_arrow, right), not(clockwise_cross).
greenfacing :- light(green_arrow, left), clockwise_cross.

caution_needed(X) :- action(X, stop);
                     action(X, stop_and_go);
                     action(X, yield_and_go);
                     action(X, yield_and_rightturn);
                     action(X, yield_and_leftturn).


given the facts:
  safe_stop_possible.
  light(yellow,steady).
  light(green_arrow,left).

the query action(car,X) returns:

X = yield_and_go ? ;
uncaught exception: error(existence_error(procedure,not/1),action/2)

if I don't put safe_stop_possible in as a fact, it blows up as well.

can anyone help? this is leaving me stumped. i thought not was a built-in predicate? and if a fact isn't declared/asserted, that just means that querying it would return false, correct?

thanks in advance,
Cliff

reply via email to

[Prev in Thread] Current Thread [Next in Thread]