Created
September 9, 2015 18:21
-
-
Save ebellani/b58829a0ee49c6d5b632 to your computer and use it in GitHub Desktop.
datalog example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
(require datalog) | |
(define corporate-chain | |
(make-theory)) | |
(datalog corporate-chain | |
;; shareholders | |
(! (shareholder "Jorge" "pf")) | |
(! (shareholder "Bob" "pf")) | |
(! (shareholder "Googly" "pj")) | |
(! (shareholder "Megasoft" "pj")) | |
;; ownership | |
(! (owns-a-share "Jorge" "Construction SA" 60.8 "shareholder")) | |
(! (owns-a-share "Bob" "Construction SA" 39.2 "shareholder")) | |
(! (owns-a-share "Googly" "Toys SA" 100 "shareholder"))) | |
(define (majority? percent) | |
;; should return every owner who owns more than 50% | |
(> percent 50)) | |
(datalog corporate-chain | |
(! (:- (major-stockholder SHAREHOLDER) | |
(shareholder SHAREHOLDER KIND) | |
(owns-a-share SHAREHOLDER COMPANY PERCENT RELATIONSHIP) | |
(majority? PERCENT :- X) | |
(= X true))) | |
(? (major-stockholder X))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment