assert/retract & dynamic predicates #2405
-
tl;dr - Is there a way to tell Scryer that a predicate defined in a source file can be changed via assert & retract? I'm working through the book Adventure in Prolog, which guides you through using prolog to create a text adventure game. The book's introduced the use of Here's a minimal example of what I'm trying to do: here(kitchen).
move(Place) :-
retract(here(_)),
asserta(here(Place)). When I try to use the It looks like swi-prolog has a I realize that using assert & retract like this isn't necessarily good practice (the book makes this clear), but I'd like to follow the code examples in the book as closely as possible for my own learning. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
That's one of the uses of the ?- [user].
:- dynamic(here/1).
here(kitchen).
move(Place) :-
retract(here(_)),
asserta(here(Place)).
end_of_file.
?- here(A).
A = kitchen.
?- move(bedroom).
true.
?- here(A).
A = bedroom.
Maybe this is a indication that directives should also be documented somewhere (relevant: #2030). |
Beta Was this translation helpful? Give feedback.
That's one of the uses of the
dynamic/1
directive:Maybe this is a indication that directives should also be documented somewhere (relevant: #2030).
dynamic/1
is a part of the ISO standard (it is also marked as this in the SWI documentation), so it should work mostly the same for any compliant Prolog implementation. If I'm not mistaken Scryer follows the standard closely fordynamic/1
, but SWI also makes it an operator …