-
Notifications
You must be signed in to change notification settings - Fork 0
/
20.py
76 lines (76 loc) · 1.96 KB
/
20.py
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
test = {
'name': 'Problem 20 (Optional)',
'points': 0,
'suites': [
{
'cases': [
{
'code': r"""
scm> (define-macro (for formal iterable body)
.... (list 'map (list 'lambda (list formal) body) iterable))
for
scm> (for i '(1 2 3)
.... (if (= i 1)
.... 0
.... i))
(0 2 3)
""",
'hidden': False,
'locked': False
},
{
'code': r"""
scm> (define (cadr s) (car (cdr s)))
cadr
scm> (define (cars s) (map car s))
cars
scm> (define (cadrs s) (map cadr s))
cadrs
scm> (define-macro (leet bindings expr)
.... (cons (list 'lambda (cars bindings) expr)
.... (cadrs bindings)))
leet
scm> (define (square x) (* x x))
square
scm> (define (hyp a b)
.... (leet ((a2 (square a)) (b2 (square b))) (sqrt (+ a2 b2))))
hyp
scm> (hyp 3 4)
5.0
""",
'hidden': False,
'locked': False
},
{
'code': r"""
scm> (define-macro wat?)
SchemeError
scm> (define-macro woah okay)
SchemeError
scm> (define-macro (hello world))
SchemeError
scm> (define-macro (5) (list 1 2))
SchemeError
scm> (define-macro (name) (body))
name
scm> name
(lambda () (body))
scm> (name)
SchemeError
""",
'hidden': False,
'locked': False
}
],
'scored': True,
'setup': r"""
scm> (define (map f lst)
.... (if (null? lst)
.... nil
.... (cons (f (car lst)) (map f (cdr lst)))))
""",
'teardown': '',
'type': 'scheme'
}
]
}