PDA

View Full Version : [SOLVED] Add a fact iteractively in prolog?



olejorgen
July 30th, 2007, 12:50 AM
Silly question, but how do I add a fact interactively in prolog. ie. directly in the interpreter.

(swi-prolog)

pmasiar
July 30th, 2007, 01:38 AM
http://en.wikipedia.org/wiki/Prolog

Fact that you have cat, with name tom:

cat(tom).

olejorgen
August 11th, 2007, 01:00 AM
?- cat(tom).
ERROR: Undefined procedure: cat/1


I suspect that it's somehow possible to change mode from "query" to "fact description" (?)

bigboy_pdb
August 11th, 2007, 02:34 AM
Use assert.

So if you want to add the fact "cat(tom)." then use "assert(cat(tom)).". When you use the query "cat(tom).", Yes will be returned.

olejorgen
August 11th, 2007, 09:29 AM
Thanks!

bigboy_pdb
August 11th, 2007, 03:21 PM
You're welcome.

Syntaxius
September 30th, 2007, 02:54 PM
An alternative, at leas in SICStus Proglog is:

?- [user] %this loads an interactive "file" where you can give interactive commands direct to the promt.
- cat(tom).
?- cat (tom).
- yes.