Learning Pilog — 2: Facts, Rules, Queries

The Knowledge Base

Facts

: (be likes (John Susie))                   # John likes Susie 
: (be likes (@X Susie)) # Everyone likes Susie
: (be likes (John @Y)) # John likes everybody

Rules

# X and Y are friends if they like each other
(be friends (@X @Y)
(likes @X @Y)
(likes @Y @X) )
# X hates Y if X does not like Y.
(be hates (@X @Y)
(not (likes @X @Y)) )
# X and Y are enemies if they don't like each other.
(be enemies (@X @Y)
(not (likes @X @Y))
(not (likes @Y @X)) )

Creating the knowledge base

(be likes (John Susie))
(be likes (John Pizza))
(be likes (Susie John))
(be friends (@X @Y)
(likes @X @Y)
(likes @Y @X) )
(be hates (@X @Y)
(not (likes @X @Y)) )
(be enemies (@X @Y)
(not (likes @X @Y))
(not (likes @Y @X)) )
$ pil friends.l +

Running queries

: (? (likes John Susie))
-> T
: (? (friends John Susie))
-> T
: (? (likes Susie Pizza))
-> NIL
? (? (not (likes Susie Pizza)))
-> T
: (? (enemies Susie Pizza))
-> T

Working with variables

: (? (likes John @X))
@X=Susie
: (? (likes John @X))
@X=Susie
@X=Pizza
-> NIL
: (? (love John Susie))
-> NIL
: (? (likes John Susie Pizza))
-> NIL

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Mia Temma

Mia Temma

These are cross-posts from my blog https://picolisp-explored.com. I’m writing about PicoLisp for beginners. Welcome!