Skip to content

Instantly share code, notes, and snippets.

@Glorp
Last active December 13, 2015 18:38
Show Gist options
  • Save Glorp/4956554 to your computer and use it in GitHub Desktop.
Save Glorp/4956554 to your computer and use it in GitHub Desktop.
#lang racket
(require "mk.rkt")
(define (conso a d c)
(== `(,a . ,d) c))
(define (caro c a)
(fresh (d)
(conso a d c)))
(define (cdro c d)
(fresh (a)
(conso a d c)))
(define (nullo x)
(== x '()))
(define (membero e l)
(fresh (a d)
(conso a d l)
(conde ((== e a))
((membero e d)))))
(define (sameo l v ll vv)
(fresh (a d aa dd)
(conso a d l)
(conso aa dd ll)
(conde ((== a v) (== aa vv))
((=/= a v) (=/= aa vv) (sameo d v dd vv)))))
(define (neighbo l v ll vv)
(fresh (a d aa dd)
(conso a d l)
(conso aa dd ll)
(conde ((== a v) (caro dd vv))
((== aa vv) (caro d v))
((neighbo d v dd vv)))))
(define (lefto l v ll vv)
(fresh (a d aa dd)
(conso a d l)
(conso aa dd ll)
(conde ((== a v) (caro dd vv))
((lefto d v dd vv)))))
(define (list-refo l n e)
(let loopo ((i 0) (l l))
(fresh (a d)
(conso a d l)
(conde ((== i n) (== e a))
((loopo (+ i 1) d))))))
(define (mapo p l ll)
(conde ((nullo l) (nullo ll))
((fresh (a d aa dd)
(conso a d l)
(conso aa dd ll)
(p a aa)
(mapo p d dd)))))
(define (rotato l ll)
(conde ((fresh (a)
(caro l a)
(nullo a)
(nullo ll)))
((fresh (a d dd)
(mapo caro l a)
(mapo cdro l d)
(rotato d dd)
(conso a dd ll)))))
(define (fiveo l)
(fresh (a b c d e)
(== l `(,a ,b ,c ,d ,e))))
(define (husdyr)
(run* (r)
(fresh (land dyr royk drikke farge)
(fiveo land)
(fiveo dyr)
(fiveo royk)
(fiveo drikke)
(fiveo farge)
(list-refo land 0 'norsk)
(sameo land 'svensk dyr 'hund)
(sameo dyr 'fugl royk 'pallmall)
(sameo land 'tysk royk 'prince)
(neighbo royk 'blend dyr 'katt)
(neighbo dyr 'hest royk 'dunhill)
(neighbo drikke 'vann royk 'blend)
(sameo drikke 'ol royk 'bluemaster)
(sameo land 'dansk drikke 'te)
(list-refo drikke 2 'melk)
(lefto farge 'gronn farge 'hvit)
(neighbo land 'norsk farge 'blaa)
(sameo farge 'gronn drikke 'kaffe)
(sameo farge 'gul royk 'dunhill)
(sameo land 'engelsk farge 'rod)
(membero 'sebra dyr)
(rotato (list '(1 2 3 4 5) land drikke farge royk dyr) r))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment