Skip to content

Instantly share code, notes, and snippets.

@swannodette
Last active December 16, 2015 06:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save swannodette/5389214 to your computer and use it in GitHub Desktop.
Save swannodette/5389214 to your computer and use it in GitHub Desktop.
(define menu
(lambda (x y)
(conde
[(== x 'tea) (== y 'biscuit)]
[(== x 'coffee) (== y 'cookie)])))
(define conso
(lambda (x y o)
(== `(,x . ,y) o)))
(define child
(lambda (x y)
(conde
[(== 'Mary x) (== 'Richard y)]
[(== 'Richard x) (== 'Leslie y)]
[(== 'Emma x) (== 'Helen y)]
[(== 'Sophie x) (== 'Helen y)])))
(define male
(lambda (x)
(conde
[(== 'Leslie x)]
[(== 'Richard x)])))
(define female
(lambda (x)
(conde
[(== 'Emma x)]
[(== 'Sophie x)]
[(== 'Helen x)]
[(== 'Mary x)])))
(define son
(lambda (x y)
(fresh ()
(male x)
(child x y))))
(define daughter
(lambda (x y)
(fresh ()
(female x)
(child x y))))
(define grandchild
(lambda (x y)
(fresh (z)
(child x z)
(child z y))))
(define right
(lambda (x y l)
(conde
[(fresh (z)
(== `(,x ,y . ,z) l))]
[(fresh (a z)
(== `(,a . ,z) l)
(right x y z))])))
(define next
(lambda (x y l)
(conde
[(right x y l)]
[(right y x l)])))
(define nevero
(lambda ()
(fresh ()
(nevero))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment