dynamic( [im_at/1, door/1]).
im_at(car).
door(false).
/* Facts*/
path(car,forward,gasstation):-
door(true),write('Wellcome to Gas Station'),nl,
write('You can buy a newspaper or a drink!').
path(car,forward,gasstation):-
write('You need to open the Car door '),nl,
!,fail.
path(gasstation,back,car):-
door(true),write('You got back in the car'),nl.
path(gasstation,back,car):-
write('You need to open the car door'),nl.
open_cardoor:-
door(true),
write('You already opend the door!'),
nl, !.
open_cardoor:-
im_at(car),
assertz(door(true)),
retract(door(false)),nl,
write('You openned the car door!'),nl,!.
forward:-go(forward).
back:-go(back).
go(Direction) :-
im_at(Here),
path(Here, Direction, There),
retract(im_at(Here)),
assert(im_at(There)),
!.
buy(drink) :-
im_at(gasstation),
write('Added a drink to bag.'), nl,
!.
buy(newspaper) :-
im_at(gasstation),
write('Added a newspaper to bag.'), nl,
!.
buy(_):-
write('You need to go to Gas Station to buy!'),nl.
start:- write('All that driving made me thirsty, you?'),nl.
No permission to modify static procedure dynamic/1
404 Views Asked by begginer programmer At
1
I assume you are using SWI-Prolog. In order to declare a sequence of predicates dynamic, you should use the syntax documented in the manual. In your case, the correct clause is
or
The first line of your program attempts to modify the definition of
dynamic/1
by declaring thatdynamic([im_at/1, door/1])
is a fact. This is prohibited, becausedynamic/1
is static (i.e., you are prohibited from modifying the definition ofdynamic/1
in a program).