Skip to content

assert/retract & dynamic predicates #2405

Answered by bakaq
JoelHobson asked this question in Q&A
Discussion options

You must be logged in to vote

That's one of the uses of the dynamic/1 directive:

?- [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.

I don't see anything that looks promising under builtins in the docs.

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 for dynamic/1, but SWI also makes it an operator …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@JoelHobson
Comment options

Answer selected by JoelHobson
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants