Skip to content

Commit bc121b4

Browse files
committed
bring back the language definitions as they were before (with anys intead of es in various functions).
I got a bit overzealous in my changes! :)
1 parent 6191240 commit bc121b4

File tree

4 files changed

+80
-77
lines changed

4 files changed

+80
-77
lines changed

redex-doc/redex/scribblings/long-tut/code/common.rkt

Lines changed: 44 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -32,25 +32,25 @@
3232
(define-language Lambda
3333
(e ::=
3434
x
35-
(lambda (x_!_ ...) e)
36-
(e e ...))
35+
(lambda (x) e)
36+
(e e))
3737
(x ::= variable-not-otherwise-mentioned))
3838

3939
(define lambda? (redex-match? Lambda e))
4040

4141
(module+ test
4242
(define e1 (term y))
4343
(define e2 (term (lambda (y) y)))
44-
(define e3 (term (lambda (x y) y)))
44+
(define e3 (term (lambda (x) (lambda (y) y))))
4545
(define e4 (term (,e2 e3)))
4646

4747
(test-equal (lambda? e1) #true)
4848
(test-equal (lambda? e2) #true)
4949
(test-equal (lambda? e3) #true)
5050
(test-equal (lambda? e4) #true)
5151

52-
(define eb1 (term (lambda (x x) y)))
53-
(define eb2 (term (lambda (x y) 3)))
52+
(define eb1 (term (lambda () y)))
53+
(define eb2 (term (lambda (x) (lambda (y) 3))))
5454

5555
(test-equal (lambda? eb1) #false)
5656
(test-equal (lambda? eb2) #false))
@@ -74,7 +74,11 @@
7474
(module+ test
7575
(test-equal (term (=α (lambda (x) x) (lambda (y) y))) #true)
7676
(test-equal (term (=α (lambda (x) (x 1)) (lambda (y) (y 1)))) #true)
77-
(test-equal (term (=α (lambda (x) x) (lambda (y) z))) #false))
77+
(test-equal (term (=α (lambda (x) x) (lambda (y) z))) #false)
78+
(test-equal (term (=α (lambda (x) x) (lambda (x) (lambda (x) x)))) #false)
79+
(test-equal (term (=α (lambda (x) x) (lambda (x) (x x)))) #false)
80+
(test-equal (term (=α (lambda (x) (lambda (y) (x y))) (lambda (x) (lambda (y) (y x))))) #false)
81+
(test-equal (term (=α (lambda (x) (lambda (y) (x y))) (lambda (a) (lambda (b) (a b))))) #true))
7882

7983
(define-metafunction Lambda
8084
=α : any any -> boolean
@@ -92,38 +96,37 @@
9296

9397
(module+ test
9498
(define sd1 (term (K 1)))
95-
(define sd2 (term 1))
9699

97100
(test-equal (SD? sd1) #true))
98101

99102
(define-metafunction SD
100103
sd : any -> any
101-
[(sd any_1) (sd/a any_1 ())])
104+
[(sd any) (sd/a any ())])
102105

103106
(module+ test
104107
(test-equal (term (sd/a x ())) (term x))
105-
(test-equal (term (sd/a x ((y) (z) (x)))) (term (K 2 0)))
108+
(test-equal (term (sd/a x (y z x))) (term (K 2)))
106109
(test-equal (term (sd/a ((lambda (x) x) (lambda (y) y)) ()))
107-
(term ((lambda () (K 0 0)) (lambda () (K 0 0)))))
110+
(term ((lambda (K 0)) (lambda (K 0)))))
108111
(test-equal (term (sd/a (lambda (x) (x (lambda (y) y))) ()))
109-
(term (lambda () ((K 0 0) (lambda () (K 0 0))))))
110-
(test-equal (term (sd/a (lambda (z x) (x (lambda (y) z))) ()))
111-
(term (lambda () ((K 0 1) (lambda () (K 1 0)))))))
112+
(term (lambda ((K 0) (lambda (K 0))))))
113+
(test-equal (term (sd/a (lambda (z) (lambda (x) (x (lambda (y) z)))) ()))
114+
(term (lambda (lambda ((K 0) (lambda (K 2))))))))
112115

113116
(define-metafunction SD
114-
sd/a : any ((x ...) ...) -> any
115-
[(sd/a x ((x_1 ...) ... (x_0 ... x x_2 ...) (x_3 ...) ...))
117+
sd/a : any (x ...) -> any
118+
[(sd/a x (x_1 ... x x_2 ...))
116119
;; bound variable
117-
(K n_rib n_pos)
118-
(where n_rib ,(length (term ((x_1 ...) ...))))
119-
(where n_pos ,(length (term (x_0 ...))))
120-
(where #false (in x (x_1 ... ...)))]
121-
[(sd/a (lambda (x ...) any_1) (any_rest ...))
122-
(lambda () (sd/a any_1 ((x ...) any_rest ...)))]
123-
[(sd/a (any_fun any_arg ...) (any_rib ...))
124-
((sd/a any_fun (any_rib ...)) (sd/a any_arg (any_rib ...)) ...)]
125-
[(sd/a any_1 any)
126-
;; free variable, constant, etc
120+
(K n)
121+
(where n ,(length (term (x_1 ...))))
122+
(where #false (in x (x_1 ...)))]
123+
[(sd/a (lambda (x) any_body) (x_rest ...))
124+
(lambda (sd/a any_body (x x_rest ...)))
125+
(where n ,(length (term (x_rest ...))))]
126+
[(sd/a (any_fun any_arg) (x_rib ...))
127+
((sd/a any_fun (x_rib ...)) (sd/a any_arg (x_rib ...)))]
128+
[(sd/a any_1 (x ...))
129+
;; free variable or constant, etc
127130
any_1])
128131

129132

@@ -134,10 +137,10 @@
134137
(test-equal (term (subst ([1 x][2 y]) x)) 1)
135138
(test-equal (term (subst ([1 x][2 y]) y)) 2)
136139
(test-equal (term (subst ([1 x][2 y]) z)) (term z))
137-
(test-equal (term (subst ([1 x][2 y]) (lambda (z w) (x y))))
138-
(term (lambda (z w) (1 2))))
139-
(test-equal (term (subst ([1 x][2 y]) (lambda (z w) (lambda (x) (x y)))))
140-
(term (lambda (z w) (lambda (x) (x 2))))
140+
(test-equal (term (subst ([1 x][2 y]) (lambda (z) (lambda (w) (x y)))))
141+
(term (lambda (z) (lambda (w) (1 2)))))
142+
(test-equal (term (subst ([1 x][2 y]) (lambda (z) (lambda (w) (lambda (x) (x y))))))
143+
(term (lambda (z) (lambda (w) (lambda (x) (x 2)))))
141144
#:equiv =α/racket)
142145
(test-equal (term (subst ((2 x)) ((lambda (x) (1 x)) x)))
143146
(term ((lambda (x) (1 x)) 2))
@@ -150,23 +153,23 @@
150153
subst : ((any x) ...) any -> any
151154
[(subst [(any_1 x_1) ... (any_x x) (any_2 x_2) ...] x) any_x]
152155
[(subst [(any_1 x_1) ... ] x) x]
153-
[(subst [(any_1 x_1) ... ] (lambda (x ...) any_body))
154-
(lambda (x_new ...)
156+
[(subst [(any_1 x_1) ... ] (lambda (x) any_body))
157+
(lambda (x_new)
155158
(subst ((any_1 x_1) ...)
156-
(subst-raw ((x_new x) ...) any_body)))
157-
(where (x_new ...) ,(variables-not-in (term (any_body any_1 ...)) (term (x ...)))) ]
159+
(subst-raw (x_new x) any_body)))
160+
(where x_new ,(variable-not-in (term (any_body any_1 ...)) (term x)))]
158161
[(subst [(any_1 x_1) ... ] (any ...)) ((subst [(any_1 x_1) ... ] any) ...)]
159162
[(subst [(any_1 x_1) ... ] any_*) any_*])
160163

161164
(define-metafunction Lambda
162-
subst-raw : ((x x) ...) any -> any
163-
[(subst-raw ((x_n1 x_o1) ... (x_new x) (x_n2 x_o2) ...) x) x_new]
164-
[(subst-raw ((x_n1 x_o1) ... ) x) x]
165-
[(subst-raw ((x_n1 x_o1) ... ) (lambda (x ...) any))
166-
(lambda (x ...) (subst-raw ((x_n1 x_o1) ... ) any))]
167-
[(subst-raw [(any_1 x_1) ... ] (any ...))
168-
((subst-raw [(any_1 x_1) ... ] any) ...)]
169-
[(subst-raw [(any_1 x_1) ... ] any_*) any_*])
165+
subst-raw : (x x) any -> any
166+
[(subst-raw (x_new x_) x_) x_new]
167+
[(subst-raw (x_new x_) x) x]
168+
[(subst-raw (x_new x_) (lambda (x) any))
169+
(lambda (x) (subst-raw (x_new x_) any))]
170+
[(subst-raw (x_new x_) (any ...))
171+
((subst-raw (x_new x_) any) ...)]
172+
[(subst-raw (x_new x_) any_*) any_*])
170173

171174
;; -----------------------------------------------------------------------------
172175
(module+ test

redex-doc/redex/scribblings/long-tut/code/mon-aft.rkt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ subst (if time, otherwise it's provide)
133133
(test-equal (SD? sd1) #true))
134134

135135
(define-metafunction SD
136-
sd : e -> e
137-
[(sd e) (sd/a e ())])
136+
sd : any -> any
137+
[(sd any) (sd/a any ())])
138138

139139
(module+ test
140140
(test-equal (term (sd/a x ())) (term x))
@@ -147,31 +147,31 @@ subst (if time, otherwise it's provide)
147147
(term (lambda (lambda ((K 0) (lambda (K 2))))))))
148148

149149
(define-metafunction SD
150-
sd/a : e (x ...) -> e
150+
sd/a : any (x ...) -> any
151151
[(sd/a x (x_1 ... x x_2 ...))
152152
;; bound variable
153153
(K n)
154154
(where n ,(length (term (x_1 ...))))
155155
(where #false (in x (x_1 ...)))]
156-
[(sd/a (lambda (x) e) (x_rest ...))
157-
(lambda (sd/a e (x x_rest ...)))
156+
[(sd/a (lambda (x) any_body) (x_rest ...))
157+
(lambda (sd/a any_body (x x_rest ...)))
158158
(where n ,(length (term (x_rest ...))))]
159-
[(sd/a (e_fun e_arg) (x_rib ...))
160-
((sd/a e_fun (x_rib ...)) (sd/a e_arg (x_rib ...)))]
159+
[(sd/a (any_fun any_arg) (x_rib ...))
160+
((sd/a any_fun (x_rib ...)) (sd/a any_arg (x_rib ...)))]
161161
[(sd/a any_1 (x ...))
162-
;; free variable or constant
162+
;; free variable or constant, etc
163163
any_1])
164164

165165
;; -----------------------------------------------------------------------------
166166
;; (=α e_1 e_2) determines whether e_1 and e_2 are α equivalent
167167

168168
(module+ test
169169
(test-equal (term (=α (lambda (x) x) (lambda (y) y))) #true)
170-
(test-equal (term (=α (lambda (x) (x z)) (lambda (y) (y z)))) #true)
170+
(test-equal (term (=α (lambda (x) (x 1)) (lambda (y) (y 1)))) #true)
171171
(test-equal (term (=α (lambda (x) x) (lambda (y) z))) #false))
172172

173173
(define-metafunction SD
174-
=α : e e -> boolean
174+
=α : any any -> boolean
175175
[(=α e_1 e_2) ,(equal? (term (sd e_1)) (term (sd e_2)))])
176176

177177
(define (=α/racket x y) (term (=α ,x ,y)))

redex-doc/redex/scribblings/long-tut/lab-mon-aft.scrbl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Here is the definition of @deftech{environment}:
3939
Before you get started, make sure you can create examples of
4040
@tech{environment}s and confirm their well-formedness.}
4141

42-
@exercise["ex:let"]{Develop the metafunction @racket[let], which extends
42+
@exercise["ex:let"]{Develop the metafunction @racket[let*], which extends
4343
the language with a notational shorthand, also known as syntactic sugar.
4444

4545
Once you have this metafunction, you can write expressions such as
@@ -48,12 +48,12 @@ Before you get started, make sure you can create examples of
4848
#reader scribble/comment-reader
4949
(racketblock
5050
(term
51-
(let ((x (lambda (a b c) a))
51+
(let* ((x (lambda (a b c) a))
5252
(y (lambda (x) x)))
5353
(x y y y)))
5454
))
5555
@;%
56-
Like Racket's @racket[let], the function elaborates surface syntax into
56+
Like Racket's @racket[let*], the function elaborates surface syntax into
5757
core syntax:
5858
@;%
5959
@(begin
@@ -74,8 +74,8 @@ Before you get started, make sure you can create examples of
7474
(racketblock
7575
(term
7676
(fv
77-
(let ((x (lambda (a b c) a))
78-
(y (lambda (x) x)))
77+
(let* ((x (lambda (a b c) a))
78+
(y (lambda (x) x)))
7979
(x y y y))))
8080
))
8181
@;%
@@ -86,8 +86,8 @@ Before you get started, make sure you can create examples of
8686
(racketblock
8787
(term
8888
(bv
89-
(let ((x (lambda (a b c) a))
90-
(y (lambda (x) x)))
89+
(let* ((x (lambda (a b c) a))
90+
(y (lambda (x) x)))
9191
(x y y y))))
9292
))
9393
@;%

redex-doc/redex/scribblings/long-tut/mon-aft.scrbl

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -349,33 +349,33 @@ add binders:
349349
(test-equal (SD? sd1) #true))
350350

351351
(define-metafunction SD
352-
sd : any -> any
353-
[(sd any_1) (sd/a any_1 ())])
352+
sd : e -> e
353+
[(sd e) (sd/a e ())])
354354

355355
(module+ test
356356
(test-equal (term (sd/a x ())) (term x))
357-
(test-equal (term (sd/a x ((y) (z) (x)))) (term (K 2 0)))
357+
(test-equal (term (sd/a x (y z x))) (term (K 2)))
358358
(test-equal (term (sd/a ((lambda (x) x) (lambda (y) y)) ()))
359-
(term ((lambda () (K 0 0)) (lambda () (K 0 0)))))
359+
(term ((lambda (K 0)) (lambda (K 0)))))
360360
(test-equal (term (sd/a (lambda (x) (x (lambda (y) y))) ()))
361-
(term (lambda () ((K 0 0) (lambda () (K 0 0))))))
362-
(test-equal (term (sd/a (lambda (z x) (x (lambda (y) z))) ()))
363-
(term (lambda () ((K 0 1) (lambda () (K 1 0)))))))
361+
(term (lambda ((K 0) (lambda (K 0))))))
362+
(test-equal (term (sd/a (lambda (z) (lambda (x) (x (lambda (y) z)))) ()))
363+
(term (lambda (lambda ((K 0) (lambda (K 2))))))))
364364

365365
(define-metafunction SD
366-
sd/a : any ((x ...) ...) -> any
367-
[(sd/a x ((x_1 ...) ... (x_0 ... x x_2 ...) (x_3 ...) ...))
366+
sd/a : e (x ...) -> e
367+
[(sd/a x (x_1 ... x x_2 ...))
368368
;; bound variable
369-
(K n_rib n_pos)
370-
(where n_rib ,(length (term ((x_1 ...) ...))))
371-
(where n_pos ,(length (term (x_0 ...))))
372-
(where #false (in x (x_1 ... ...)))]
373-
[(sd/a (lambda (x ...) any_1) (any_rest ...))
374-
(lambda () (sd/a any_1 ((x ...) any_rest ...)))]
375-
[(sd/a (any_fun any_arg ...) (any_rib ...))
376-
((sd/a any_fun (any_rib ...)) (sd/a any_arg (any_rib ...)) ...)]
377-
[(sd/a any_1 any)
378-
;; free variable, constant, etc
369+
(K n)
370+
(where n ,(length (term (x_1 ...))))
371+
(where #false (in x (x_1 ...)))]
372+
[(sd/a (lambda (x) e) (x_rest ...))
373+
(lambda (sd/a e (x x_rest ...)))
374+
(where n ,(length (term (x_rest ...))))]
375+
[(sd/a (e_fun e_arg) (x_rib ...))
376+
((sd/a e_fun (x_rib ...)) (sd/a e_arg (x_rib ...)))]
377+
[(sd/a any_1 (x ...))
378+
;; free variable or constant
379379
any_1])
380380
))
381381
@;%

0 commit comments

Comments
 (0)