2

In prolog, if I assert some fact, for example:

assert(boy(john4)).
assert(boy(john3)).
assert(boy(john2)).
assert(boy(john1)).

How can I save this fact in file?

false
  • 10,264
  • 13
  • 101
  • 209
user2254798
  • 553
  • 2
  • 6
  • 17
  • [link](http://stackoverflow.com/questions/2435237/prolog-assert-and-retract?rq=1) i found it and its correct :) – user2254798 Apr 07 '13 at 16:25
  • 1
    You might be interested in [this Question](http://stackoverflow.com/q/8269971/487781), one Answer of which discusses an alternative to the dated **tell/1, told** mechanism used in the link you found. Also [SWI-Prolog has its own mechanism](http://stackoverflow.com/a/10141788/487781) for saving an interpreter state (but you don't specify which Prolog interests you). – hardmath Apr 09 '13 at 02:37

1 Answers1

1

If you are using SWI-Prolog then one alternative is the persistency.pl library. You need to declare persisted predicates and their argument types. Then you can use assert_mypred and retract_mypred. More info: http://www.swi-prolog.org/pldoc/doc/swi/library/persistency.pl

Raivo Laanemets
  • 1,119
  • 10
  • 7