Skip to content

Commit 24269eb

Browse files
committed
Fix totality check to be for closed expressions.
1 parent 0ac1926 commit 24269eb

File tree

1 file changed

+48
-4
lines changed

1 file changed

+48
-4
lines changed

langs/fraud/semantics.rkt

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,34 @@
104104
(Prim1 'add1 (Var x)))))
105105
8)))
106106

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+
107128

108129
(module+ test
109130
(require rackunit)
110-
;; Check that the semantics is total function
131+
;; Check that the semantics is total function on closed expressions
111132
(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))))
113135
#:print? #f))
114136

115137

@@ -245,9 +267,31 @@
245267
(test-judgment-holds (𝑮 (Prim2 '- (Int 1) (Bool #f)) err))
246268
(test-judgment-holds (𝑮 (Prim2 '- (Prim1 'add1 (Bool #f)) (Bool #f)) err)))
247269

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+
248291
(module+ test
249292
(require rackunit)
250-
;; Check that the semantics is total function
293+
;; Check that the semantics is total function -- for closed expressions
251294
(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))))
253297
#:print? #f))

0 commit comments

Comments
 (0)