Skip to content

Instantly share code, notes, and snippets.

@ebellani
Created September 9, 2015 18:21
Show Gist options
  • Save ebellani/b58829a0ee49c6d5b632 to your computer and use it in GitHub Desktop.
Save ebellani/b58829a0ee49c6d5b632 to your computer and use it in GitHub Desktop.
datalog example
#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