Subject: Re: To read a file

From: "Richard A. O'Keefe" <[email-masked]>
Date: Thu, 23 Mar 2000 14:16:04 +1200 (NZST)

Fatih Hocaoglu <[email-masked]> wrote:
	The program read a rule such as set_trust(on) from the knowledge base and
	assigned it to a variable, X='set_trust(on)'. How can I assert the
	predicate set_trust(on).
	
	I tried to use asserta(X), but it doesn't work,
	I think type conversion necessary.

set_trust(on) is a FACT (a kind of CLAUSE) not a PREDICATE.

The obvious question is "HOW did the program read this fact?"
Here's a little transcript:
1 ?- read(X), asserta(X).
|: set_trust(on).
<EOF>
X = set_trust(on) 

Yes
2 ?- listing(set_trust).

set_trust(on).

The important thing here is that X was NOT 'set_trust(on)' (an ATOM,
a single symbol) but set_trust(no) (a COMPOUND TERM, with FUNCTOR
'set_trust'/1 and argument 'no')).

When you tried asserta('set_trust(on)'), it actually succeeded.
You added a fact (better known as a unit clause) for a predicate
called 'set_trust(on)' with no arguments.

asserta/1 is uncommon, assert/1 is more usual.

It looks as though the problem is with the way you are reading clauses.
Use read/1.  Any good Prolog book will tell you how to do this; Sterling
and Shapiro certainly does.