r2 - 02 Mar 2005 - 11:20:03 - JanWielemakerYou are here: TWiki >  FAQ Web  > UndefinedCode
ERROR: Undefined procedure:

There are three common things people use that produce this error while they do not realise they made a mistake.

No facts have yet been asserted, but they will be

Sometimes you want to change a predicate at runtime using assert/1 and retract/1, but you call it before the first assert. Prolog doesn't know about your intend and reports an error. It is good practice to define every predicate you want to manipulate as dynamic:

:- dynamic is_a/2, person/1.

You remove all clauses of a dynamic predicate using abolish/[1,2]

abolish/[1,2] forgets everything Prolog knows about the predicate, including the fact is was dynamic. All clauses should be removed using retractall/1.

You enter your program at the prompt

SWI-Prolog (in fact almost any Prolog system) interprets terms typed to the ?- prompt queries and wants to prove them. Way prefered is to use an editor to create a file and load this into Prolog using

?- [myfile].

If you insist on typing your program at the prompt, consult user using the sequence below. Instead of the literal end_of_file term, you can also type the end-of-file character of your system. This is often Control-D.

?- [user]. |: likes(mary, john). |: end_of_file. % user compiled 0.00 sec, 344 bytes

-- JanWielemaker - 12 Oct 2001

Edit | Attach | Printable | Raw View | Backlinks: Web, All Webs | History: r2 < r1 | More topic actions
 
Powered by TWiki
This site is powered by the TWiki collaboration platformCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback