Dickson
Dickson

Reputation: 43

English Sentence to Prolog clauses?

I am learning about Prolog recently and I came up with a question.

How do I say:

Any Employee drives, walks, rides or flies to work in Prolog clauses?

"Any" is where I am having problem with.


Here is my thought process.

Employee(tom).     %tom is an employee (fact)

drives(X) :- Employee(X).    
walks(X) :- Employee(X).    
rides(X) :- Employee(X).   
flies(X) :- Employee(X).

Is this a correct approach?

Upvotes: 0

Views: 321

Answers (1)

Will Ness
Will Ness

Reputation: 71119

I think it's the other way around:

employee(X):- drives(X).
employee(X):- walks(X).
employee(X):- rides(X).
employee(X):- flies(X).

Plus facts for drives, walks, etc.

Whichever employee it is, one of these must hold. If it doesn't, then employee(X) fails.

This is, then, what it means under this Prolog database, that "any employee either flies, rides, etc.".

What you've written means, that given an X such that employee(X) holds, each of drives(X), walks(X), etc., will hold as well. I.e. "any employee walks, and drives, and rides, and flies" to work. (and of course, predicates must start with a lower case letter, always).

Upvotes: 1

Related Questions