Take the 2-minute tour ×

I am reading http://cs.union.edu/~striegnk/learn-prolog-now/html/node3.html#subsec.l1.kb1 but I am having trouble running the following predicate:

SICStus 4.0.1 (x86-win32-nt-4): Tue May 15 21:17:49 WEST 2007
| ?- woman(mia).
! Existence error in user:woman/1
! procedure user:woman/1 does not exist
! goal:  user:woman(mia)
| ?- 

If in the other hand, I write it to a file and run consult the file, it seems to work fine. Am I only allowed to define predicates in a file having later to consult them? Can't I just do it in the editor itself?

share|improve this question

2 Answers 2

up vote 4 down vote accepted

You should enter woman(mia). into a file to assert it as a fact. If you write it into the interpreter, it's taken as a query, not a fact.

From the SWI Prolog FAQ:




?- carnivore(X) :- animal(X), eats_meat(X). ERROR: Undefined
procedure: (:-)/2 ERROR:   Rules must be loaded from a file ERROR:  


If a text reads

:- use_module(library(clpfd)).


Instead of writing to a file you can also use assert in the toplevel (as explained later in the FAQ as well).

share|improve this answer
So, in this case assert(woman(mia)). would do just what I want? –  devoured elysium Sep 6 '11 at 18:56
@devoured: Yes. –  sepp2k Sep 6 '11 at 18:59
The error message can be missleading for a novice. Since rules can also be loaded from user, which is not exactly a file. But this is a general problem of creating good error messages. –  j4n bur53 Sep 6 '11 at 20:48

It's a little annoying to make predicates in the repl. You could do

| ?- ['user'].

ie consult user input, or

| ?- assertz(woman(mia)).

assert it. Both awkward IMO -- there might be a better way, though, I just don't know it. In general it is easier to use a script.

share|improve this answer

Your Answer


