-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path03.py
101 lines (101 loc) · 2.96 KB
/
03.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
test = {
'name': 'Problem 3',
'points': 2,
'suites': [
{
'cases': [
{
'code': r"""
>>> env = create_global_frame()
>>> twos = Pair(2, Pair(2, nil))
>>> plus = BuiltinProcedure(scheme_add) # + procedure
>>> scheme_apply(plus, twos, env) # Type SchemeError if you think this errors
4
""",
'hidden': False,
'locked': False
},
{
'code': r"""
>>> env = create_global_frame()
>>> twos = Pair(2, Pair(2, nil))
>>> oddp = BuiltinProcedure(scheme_oddp) # odd? procedure
>>> scheme_apply(oddp, twos, env) # Type SchemeError if you think this errors
SchemeError
""",
'hidden': False,
'locked': False
},
{
'code': r"""
>>> env = create_global_frame()
>>> two = Pair(2, nil)
>>> eval = BuiltinProcedure(scheme_eval, True) # eval procedure
>>> scheme_apply(eval, two, env) # be sure to check use_env
2
""",
'hidden': False,
'locked': False
},
{
'code': r"""
>>> env = create_global_frame()
>>> args = nil
>>> def make_scheme_counter():
... x = 0
... def scheme_counter():
... nonlocal x
... x += 1
... return x
... return scheme_counter
>>> counter = BuiltinProcedure(make_scheme_counter()) # counter
>>> scheme_apply(counter, args, env) # only call procedure.fn once!
1
""",
'hidden': False,
'locked': False
},
{
'code': r"""
>>> env = create_global_frame()
>>> args = nil
>>> q = BuiltinProcedure(scheme_exit) # same as (exit)
>>> scheme_apply(q, args, env) # Make sure youre only excepting TypeErrors!
EOFError
""",
'hidden': False,
'locked': False
},
{
'code': r"""
>>> env = create_global_frame()
>>> fn = lambda g: g is env
>>> args = nil
>>> q = BuiltinProcedure(fn, True)
>>> scheme_apply(q, args, env) # Should return True if you've correctly implemented use_env procedures
True
""",
'hidden': False,
'locked': False
},
{
'code': r"""
>>> env = create_global_frame()
>>> args = nil
>>> q = BuiltinProcedure(scheme_exit)
>>> scheme_apply(q, args, env) # If you triggered this case, you should make sure that your code *only* catches TypeErrors, and not any others!
EOFError
""",
'hidden': False,
'locked': False
}
],
'scored': True,
'setup': r"""
>>> from scheme import *
""",
'teardown': '',
'type': 'doctest'
}
]
}