-
Notifications
You must be signed in to change notification settings - Fork 0
/
barliman.scm
51 lines (44 loc) · 1.7 KB
/
barliman.scm
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
(load "Barliman/cocoa/Barliman/mk-and-rel-interp/mk/mk-vicare.scm")
(load "Barliman/cocoa/Barliman/mk-and-rel-interp/mk/mk.scm")
(load "Barliman/cocoa/Barliman/mk-and-rel-interp/interp.scm")
;; this is for formatting in Barliman call
(define spell-the-conses
(lambda (xs)
(if (null? xs)
''()
`(cons ,(car xs) ,(spell-the-conses (cdr xs))))))
(define (barliman-helper partial-success? n fun-name formals io* . options)
(let* ((inputs (map car io*))
(outputs (map cadr io*)))
(define (ans)
(define (results)
(define (absento-all v q)
(cond
((null? v) succeed)
((pair? v)
(fresh ()
(absento-all (car v) q)
(absento-all (cdr v) q)))
((number? v)
(absento v q))
(else
;; makes the search incomplete to restrict on whole io*
;; trade-offs are worth thinking about
succeed)))
(run n (q)
(absento 'match q)
(absento-all io* q)
(evalo `(begin
(define ,fun-name (lambda ,formals ,q))
,(spell-the-conses inputs))
outputs)))
(set! allow-partial-result? partial-success?)
(let ((results-fast (begin (set! allow-incomplete-search? #t) (results))))
(if (null? results-fast)
(begin (set! allow-incomplete-search? #f) (results))
results-fast)))
(ans)))
(define (barliman-filler fun-name formals io* . options)
(apply barliman-helper #f 1 fun-name formals io* options))
(define (barliman-partial-programs n fun-name formals io* . options)
(apply barliman-helper #t n fun-name formals io* options))