pyDatalog - Datalog tutorial

submited by
Style Pass
2021-06-05 16:30:07

pyDatalog is a powerful language with very few syntactic elements, mostly coming from Python : this makes it easy to learn ! In this tutorial, we'll review:

We'll see that pyDatalog statements are declarative : they describe the result we want, leaving to the computer the task of finding the appropriate solutions. We'll start with trivial problems to show the basics of the language, and progressively address more complex problems, to show how simply they can be expressed. We'll finish with an efficient solution to the 8-queen problem.

# give me all the X and Y so that X is True and Y is False print ((X==True) & (Y==False)) X | Y -----|------ True | False

# give me all the X and Y so that X is a name and Y is 'Hello ' followed by the first letter of X print ((X==raw_input('Please enter your name : ')) & (Y=='Hello ' + X[0])) Please enter your name : World X | Y ------|-------- World | Hello W

In the second equality, X is said to be bound by the first equality, i.e. the first equality gives it a value, making it possible to evaluate the expression in the second equality.

Leave a Comment