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.
Asked
Active
Viewed 364 times
0

Guy Coder
- 24,501
- 8
- 71
- 136
1 Answers
0
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
:- dynamic im_at/1, door/1.
or
:- dynamic([im_at/1, door/1]).
The first line of your program attempts to modify the definition of dynamic/1
by declaring that dynamic([im_at/1, door/1])
is a fact. This is prohibited, because dynamic/1
is static (i.e., you are prohibited from modifying the definition of dynamic/1
in a program).

emi
- 5,380
- 1
- 27
- 45
-
1writing `:- dynamic([im_at/1,door/1]).` as a declaration is fine. – false Jan 26 '20 at 09:50
-
@false Right. I wanted to stress the preferred syntax and highlight where the OP went wrong. – emi Jan 26 '20 at 11:07
-
1You are using a system that has `dynamic` defined as a prefix operator. – false Jan 26 '20 at 16:04
-
I believe the OP is using SWI-Prolog. In any case, updated to reflect your comment. – emi Jan 27 '20 at 21:10