Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

prolog program predicate

Status
Not open for further replies.

sperelli

Programmer
Jul 20, 2014
3
0
0
IT
Hi everybody,

I just start to learn Prolog.
I have to write a Prolog program where the Horn clauses and the goal will only consist of a predicate symbol, which thus will not be followed by a sequence of terms enclosed in parentheses.

What exactly means?
Something like this:

A :- B, C, D.
B.
C.
D :- E.
E.


and the goal A or another character.
Is it right? Someone can give me another example?
 
That's correct but you must use lowercase letters :
Code:
a :- b, c, d.
b.
c.
d :- e.
e.
 
Thanks a lot!!!
and what exactly means that code?

that 'a' is true only if 'b' , 'c' and 'd' are true? right?

and the goal could be every letter that i use in the code?
 
You should say "a succeeds only if b, c and d (so e) succeed".
Since b, c and e are facts, a succeeds.
Yes, every letter in this example can be a goal.
 
Thanks a lot!!! :)

I have a last question.. I have to write in C the and/or tree for this prolog file..
How can I do it? how I know when is an 'or' and when is an 'and'.

For example.. if the goal is 'a':

a
|
--------------------------
| | |
b c d
| | |
succeed succeed e
|
succeed

is it ok? but how i can make an 'or'? and to have a 'failure'?
 
'or' is achieved with a semicolon ';'.
If I understand your question 'to have a failure' you can use \+ wich is the negation
\+a. gives 'false'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top