forked from michaelballantyne/faster-minikanren
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmk.rkt
71 lines (46 loc) · 1.37 KB
/
mk.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#lang racket/base
(require racket/list
racket/include)
(provide run run*
== =/=
fresh
conde
symbolo numbero
absento)
;; extra stuff for racket
;; due mostly to samth
(define (list-sort f l) (sort l f))
(define (remp f l) (filter-not f l))
(define (call-with-string-output-port f)
(define p (open-output-string))
(f p)
(get-output-string p))
(define (exists f l) (ormap f l))
(define for-all andmap)
(define (find f l)
(cond [(memf f l) => car] [else #f]))
(define memp memf)
(define (var*? v) (var? (car v)))
; Substitution representation
(define empty-subst-map (hasheq))
(define subst-map-length hash-count)
; Returns #f if not found, or a pair of u and the result of the lookup.
; This distinguishes between #f indicating absence and being the result.
(define subst-map-lookup
(lambda (u S)
(hash-ref S u unbound)))
(define (subst-map-add S var val)
(hash-set S var val))
(define subst-map-eq? eq?)
; Constraint store representation
(define empty-C (hasheq))
(define set-c
(lambda (v c st)
(state (state-S st) (hash-set (state-C st) v c))))
(define lookup-c
(lambda (v st)
(hash-ref (state-C st) v empty-c)))
(define remove-c
(lambda (v st)
(state (state-S st) (hash-remove (state-C st) v))))
(include "mk.scm")