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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to begin with Visual Prolog 1

Status
Not open for further replies.

debiesven

Programmer
Oct 8, 2009
3
NL
I'm new to Prolog. I'v got only 1 question: How can I start with Prolog using Visual Prolog?

I currently have:
- Visual Prolog 7.1 installed
- Made a new project
- Build the project
- Opened main.pro

main.pro:
Code:
implement main
    open core

constants
    className = "main".
    classVersion = "".

clauses
    classInfo(className, classVersion).

clauses
    run():-
        console::init(),
        succeed(). % place your own code here

end implement main

goal
    mainExe::run(main::run).

And I have the following code:
Code:
parent( pam, bob).
parent( tom, bob).
parent( tom, liz).
parent( bob, ann).
parent( bob, pat).
parent( pat, jim).
female( pam).
male( tom).
male( bob).
female( liz).
female( ann).
female( pat).
male( jim).

offspring( Y, X) :-
parent( X, Y).

mother( X, Y) :-
parent( X, Y),
female( X).

grandparent(X, Z) :-
parent( X, Y),
parent( Y, Z).

sister( X, Y) :-
parent( Z, X),
parent( Z, Y),
female( X),
different( X, Y).

predecessor(X,Z ) :-
parent( X, Z).

predecessor( X, Z) :-
parent( X, Y),
predecessor(Y, Z).

I tried the following:
Code:
implement main
    open core

constants
    className = "main".
    classVersion = "".

clauses
    classInfo(className, classVersion).

clauses
    run():-
        console::init(),
        succeed(). % place your own code here

parent( pam, bob).
parent( tom, bob).
parent( tom, liz).
parent( bob, ann).
parent( bob, pat).
parent( pat, jim).
female( pam).
male( tom).
male( bob).
female( liz).
female( ann).
female( pat).
male( jim).

offspring( Y, X) :-
parent( X, Y).

mother( X, Y) :-
parent( X, Y),
female( X).

grandparent(X, Z) :-
parent( X, Y),
parent( Y, Z).

sister( X, Y) :-
parent( Z, X),
parent( Z, Y),
female( X),
different( X, Y).

predecessor(X,Z ) :-
parent( X, Z).

predecessor( X, Z) :-
parent( X, Y),
predecessor(Y, Z).

end implement main

goalAnd
    mainExe::run(main::run).

But it doesn't work. I only need a little explanation, how I can start using this code. (It's from Ivan Bratko - Programming for Artificial Intelligence - Fig. 1.8)
 
And how can I do this with SWI-Prolog? I've got this program too.
 
You copy the middle code in the editor.
You complie it Complie/Compile/buffer then in the console you ask questions, for example
sister( X, liz).
mother( X, ann)
 
Okay, thank you. Know I've got the following qustion:
When I ask sister(X,ann). then the following error occured:
ERROR: sister/2: Undefined procedure: different/2
 
in SWI-Prolog you can define different with
Code:
different(X,Y) :-
  X \= Y.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top