1#lang racket 2 3(require racklog) 4 5;The following is a simple database about a certain family in England. 6;Should be a piece of cake, but given here so that you can hone 7;your ability to read the syntax. 8 9;This file is written using goal combinations like %or, %and 10;like you would use Scheme procedures. For a more Prolog-like 11;syntax of the same program, see england.scm. 12 13(define %male 14 (lambda (x) 15 (%or (%= x 'philip) 16 (%= x 'charles) 17 (%= x 'andrew) 18 (%= x 'edward) 19 (%= x 'mark) 20 (%= x 'william) 21 (%= x 'harry) 22 (%= x 'peter)))) 23 24(define %female 25 (lambda (x) 26 (%or (%= x 'elizabeth) 27 (%= x 'anne) 28 (%= x 'diana) 29 (%= x 'sarah) 30 (%= x 'zara)))) 31 32(define %husband-of 33 (lambda (h w) 34 (%or (%and (%= h 'philip) (%= w 'elizabeth)) 35 (%and (%= h 'charles) (%= w 'diana)) 36 (%and (%= h 'mark) (%= w 'anne)) 37 (%and (%= h 'andrew) (%= w 'sarah))))) 38 39(define %wife-of 40 (lambda (w h) 41 (%husband-of h w))) 42 43(define %married-to 44 (lambda (x y) 45 (%or (%husband-of x y) (%wife-of x y)))) 46 47(define %father-of 48 (lambda (x y) 49 (%or (%and (%= x 'philip) (%= y 'charles)) 50 (%and (%= x 'philip) (%= y 'anne)) 51 (%and (%= x 'philip) (%= y 'andrew)) 52 (%and (%= x 'philip) (%= y 'edward)) 53 (%and (%= x 'charles) (%= y 'william)) 54 (%and (%= x 'charles) (%= y 'harry)) 55 (%and (%= x 'mark) (%= y 'peter)) 56 (%and (%= x 'mark) (%= y 'zara))))) 57 58(define %mother-of 59 (lambda (m c) 60 (%let (f) 61 (%and (%wife-of m f) (%father-of f c))))) 62 63(define %child-of 64 (lambda (c p) 65 (%or (%father-of p c) (%mother-of p c)))) 66 67(define %parent-of 68 (lambda (p c) 69 (%child-of c p))) 70 71(define %brother-of 72 (lambda (b x) 73 (%let (f) 74 (%and (%male b) 75 (%father-of f b) 76 (%father-of f x) 77 (%/= b x))))) 78 79