;; ;; Sample PROLOG program ;; By Nils M Holm, 1998-2009 ;; Ported to Chicken Scheme by Ivan Raikov. ;; (import tiny-prolog test) (new-database!) ; set up fresh database (! (female cathy)) ; add some facts (! (female denise)) (! (female fanny)) (! (male anthony)) (! (male bertram)) (! (male eric)) (! (parent bertram eric)) (! (parent cathy eric)) (! (parent anthony cathy)) (! (parent eric denise)) (! (parent anthony fanny)) (! (wife cathy bertram)) (:- (husband ?a ?b) (wife ?b ?a)) ; define some predicates (:- (mother ?a ?b) (female ?a) (parent ?a ?b)) (:- (father ?a ?b) (male ?a) (parent ?a ?b)) (:- (child ?a ?b) (parent ?b ?a)) (:- (descendant ?a ?b) (child ?a ?b)) (:- (descendant ?a ?b) (child ?a ?x) (descendant ?x ?b)) (print "Which females are there?") (print-frames (? (female ?who))) (test-assert (equal? (? (female ?who)) '(((who . cathy)) ((who . denise)) ((who . fanny))))) (print "Which relatives does Eric have?") (print-frames (? (_ eric ?who))) (test-assert (equal? (? (_ eric ?who)) '(((who . denise)) ((who . bertram)) ((who . cathy)) ((who . anthony))))) (print "Cathy is related to whom in which way?") (print-frames (? (?relation cathy ?who))) (test-assert (equal? (? (?relation cathy ?who)) '(((relation . parent) (who . eric)) ((relation . wife) (who . bertram)) ((relation . mother) (who . eric)) ((relation . child) (who . anthony)) ((relation . descendant) (who . anthony))))) (test-exit)