|
104 | 104 | (Prim1 'add1 (Var x))))) |
105 | 105 | 8))) |
106 | 106 |
|
| 107 | +;; replace any free variables with 0 |
| 108 | +(define-metafunction F |
| 109 | + F-close-with-zero : e (x ...) -> e |
| 110 | + [(F-close-with-zero (Var x) (x_0 ... x x_1 ...)) (Var x)] |
| 111 | + [(F-close-with-zero (Var x) any) (Int 0)] |
| 112 | + [(F-close-with-zero (Int i) any) (Int i)] |
| 113 | + [(F-close-with-zero (Bool b) any) (Bool b)] |
| 114 | + [(F-close-with-zero (If e_1 e_2 e_3) any_r) |
| 115 | + (If (F-close-with-zero e_1 any_r) |
| 116 | + (F-close-with-zero e_2 any_r) |
| 117 | + (F-close-with-zero e_3 any_r))] |
| 118 | + [(F-close-with-zero (Prim1 p1 e_1) any_r) |
| 119 | + (Prim1 p1 (close-with-zero e_1 any_r))] |
| 120 | + #;[(F-close-with-zero (Prim2 p2 e_1 e_2) any_r) |
| 121 | + (Prim2 p2 |
| 122 | + (close-with-zero e_1 any_r) |
| 123 | + (close-with-zero e_2 any_r))] |
| 124 | + [(F-close-with-zero (Let x e_1 e_2) (x_0 ...)) |
| 125 | + (Let x (close-with-zero e_1 (x_0 ...)) |
| 126 | + (close-with-zero e_2 (x x_0 ...)))]) |
| 127 | + |
107 | 128 |
|
108 | 129 | (module+ test |
109 | 130 | (require rackunit) |
110 | | - ;; Check that the semantics is total function |
| 131 | + ;; Check that the semantics is total function on closed expressions |
111 | 132 | (redex-check F e |
112 | | - (check-true (redex-match? F (a_0) (judgment-holds (𝑭 e a) a)) (format "~a" (term e))) |
| 133 | + (redex-let F ([e_0 (term (F-close-with-zero e ()))]) |
| 134 | + (check-true (redex-match? F (a_0) (judgment-holds (𝑭 e_0 a) a)) (format "~a" (term e)))) |
113 | 135 | #:print? #f)) |
114 | 136 |
|
115 | 137 |
|
|
245 | 267 | (test-judgment-holds (𝑮 (Prim2 '- (Int 1) (Bool #f)) err)) |
246 | 268 | (test-judgment-holds (𝑮 (Prim2 '- (Prim1 'add1 (Bool #f)) (Bool #f)) err))) |
247 | 269 |
|
| 270 | +;; replace any free variables with 0 |
| 271 | +(define-metafunction G |
| 272 | + close-with-zero : e (x ...) -> e |
| 273 | + [(close-with-zero (Var x) (x_0 ... x x_1 ...)) (Var x)] |
| 274 | + [(close-with-zero (Var x) any) (Int 0)] |
| 275 | + [(close-with-zero (Int i) any) (Int i)] |
| 276 | + [(close-with-zero (Bool b) any) (Bool b)] |
| 277 | + [(close-with-zero (If e_1 e_2 e_3) any_r) |
| 278 | + (If (close-with-zero e_1 any_r) |
| 279 | + (close-with-zero e_2 any_r) |
| 280 | + (close-with-zero e_3 any_r))] |
| 281 | + [(close-with-zero (Prim1 p1 e_1) any_r) |
| 282 | + (Prim1 p1 (close-with-zero e_1 any_r))] |
| 283 | + [(close-with-zero (Prim2 p2 e_1 e_2) any_r) |
| 284 | + (Prim2 p2 |
| 285 | + (close-with-zero e_1 any_r) |
| 286 | + (close-with-zero e_2 any_r))] |
| 287 | + [(close-with-zero (Let x e_1 e_2) (x_0 ...)) |
| 288 | + (Let x (close-with-zero e_1 (x_0 ...)) |
| 289 | + (close-with-zero e_2 (x x_0 ...)))]) |
| 290 | + |
248 | 291 | (module+ test |
249 | 292 | (require rackunit) |
250 | | - ;; Check that the semantics is total function |
| 293 | + ;; Check that the semantics is total function -- for closed expressions |
251 | 294 | (redex-check G e |
252 | | - (check-true (redex-match? G (a_0) (judgment-holds (𝑮 e a) a))) |
| 295 | + (redex-let G ([e_0 (term (close-with-zero e ()))]) |
| 296 | + (check-true (redex-match? G (a_0) (judgment-holds (𝑮 e_0 a) a)))) |
253 | 297 | #:print? #f)) |
0 commit comments