-
Notifications
You must be signed in to change notification settings - Fork 16
/
synth-task-macros.rkt
87 lines (77 loc) · 1.72 KB
/
synth-task-macros.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#lang racket/base
(require "../all.rkt")
(define-syntax-rule
(synth/sketch
(q ...)
([name rhs] ...)
[example-call -> example-return] ...)
(car
(run 1 (q ...)
(staged
(evalo-staged
`(letrec
([name rhs] ...)
(list example-call ...))
'(example-return ...))))))
(test
(synth/sketch (e)
([append
(lambda (xs ys)
(if (null? xs) ys
(cons ,e (append (cdr xs) ys))))])
[(append '() '()) -> ()]
[(append '(a) '(b)) -> (a b)]
[(append '(c d) '(e f)) -> (c d e f)])
'(car xs))
(test
(run 1 (e)
(staged
(evalo-staged
`(letrec
([append
(lambda (xs ys)
(if (null? xs) ys
(cons ,e (append (cdr xs) ys))))])
(list
(append '() '())
(append '(a) '(b))
(append '(c d) '(e f))))
'(() (a b) (c d e f)))))
'((car xs)))
(define-syntax-rule
(invert-execute
([name (lambda (arg ...) body)])
return)
(run* (arg ...)
(staged
(evalo-staged
`(letrec ([name (lambda (arg ...) body)])
(name ',arg ...))
'return))))
(test
(invert-execute
([append
(lambda (xs ys)
(if (null? xs) ys
(cons (car xs) (append (cdr xs) ys))))])
(a b c))
'((() (a b c))
((a) (b c))
((a b) (c))
((a b c) ())))
(test
(run* (xs ys)
(staged
(evalo-staged
`(letrec
([append
(lambda (xs ys)
(if (null? xs) ys
(cons (car xs)
(append (cdr xs) ys))))])
(append ',xs ',ys))
'(a b c))))
'((() (a b c))
((a) (b c))
((a b) (c))
((a b c) ())))