-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsnapshots.scm
61 lines (47 loc) · 1.89 KB
/
snapshots.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
51
52
53
54
55
56
57
58
59
60
61
(load "transparent-evalo.scm")
(define (q-transform f inputs)
(query (defn)
(fresh (body)
(== `(lambda ,body) defn)
(evalo `(list . ,(map (lambda (input) `(app ,defn ',input)) inputs))
(map f inputs)))))
(define (q-transform-hint f inputs hint)
(query (defn)
(== hint defn)
(evalo `(list . ,(map (lambda (input) `(app ,defn ',input)) inputs))
(map f inputs))))
(define (q-np n) (q-transform (lambda (x) (cons n x)) '((x) (y))))
(define q-quine (query (p) (evalo p p)))
(define (print-labeled-solution q)
(let loop ((choices (labeled-pretty (labeled-solution q))))
(when (pair? choices)
(printf "(~s ~s)\n" (if (caar choices) 0 1) (cadar choices))
(loop (cdr choices)))))
(define (print-labeled-solution* q)
(define (boolean->idx b) (if b 0 1))
(let loop ((choices (labeled-pretty (labeled-solution* q))))
(when (pair? choices)
(printf "(~s ~s)\n" (map boolean->idx (caar choices)) (cadar choices))
(loop (cdr choices)))))
(define (print-labeled-solution*-hint q-hint q)
(define (boolean->idx b) (if b 0 1))
(let loop ((choices (labeled-pretty (labeled-solution*-hint q-hint q))))
(when (pair? choices)
(printf "(~s ~s)\n" (map boolean->idx (caar choices)) (cadar choices))
(loop (cdr choices)))))
;(print-labeled-solution* (q-np 1))
;(print-labeled-solution q-quine)
;; list manipulation examples
;; 22 steps
(print-labeled-solution* (q-transform (lambda (x) `(,@x ,@x)) '((a) (b))))
;; 34 steps (takes a moment to synthesize)
;(print-labeled-solution* (q-transform (lambda (x) `(,@x 3 ,@x)) '((a) (b))))
;; 26 steps
;(print-labeled-solution*-hint
;(q-transform-hint
;(lambda (x) (cons (car x) (cddr x)))
;'((a b c) (d e f))
;'(lambda (cons (car (var ())) (cdr (cdr (var ()))))))
;(q-transform
;(lambda (x) (cons (car x) (cddr x)))
;'((a b c) (d e f))))