Skip to content

Commit e50b07e

Browse files
some width fixes for thesis
1 parent 1d4abf8 commit e50b07e

File tree

4 files changed

+61
-34
lines changed

4 files changed

+61
-34
lines changed

scribblings/reference/compiling.scrbl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ Can only be used with simple non-terminals.
286286
(syntax-rules ()
287287
[(sqr n) (* n n)])))
288288
(begin-for-syntax
289-
(define local-expand-arithmetic (nonterminal-expander arithmetic))
289+
(define local-expand-arithmetic
290+
(nonterminal-expander arithmetic))
290291
(displayln (local-expand-arithmetic #'(sqr 1)))))
291292
]

scribblings/reference/specifying.scrbl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,14 +260,16 @@ When a form production's form is used outside of the context of a syntax-spec DS
260260
spec-variable-id
261261
(bind spec-variable-id)
262262
(bind-syntax spec-variable-id spec-variable-id)
263-
(bind-syntaxes spec-variable-id ooo ... spec-variable-id)
263+
(bind-syntaxes spec-variable-id ooo ...
264+
spec-variable-id)
264265
(scope spec-or-ooo ...)
265266
[spec-or-ooo ...]
266267
(nest spec-variable-id ooo ... binding-spec)
267268
(import spec-variable-id)
268269
(export spec-variable-id)
269270
(export-syntax spec-variable-id spec-variable-id)
270-
(export-syntaxes spec-variable-id ooo ... spec-variable-id)
271+
(export-syntaxes spec-variable-id ooo ...
272+
spec-variable-id)
271273
(re-export spec-variable-id))
272274
(ooo
273275
...)
@@ -317,7 +319,8 @@ Similar to syntax patterns and templates, syntax specs and binding specs have a
317319
(nonterminal my-expr
318320
#:allow-extension my-macro
319321
n:number
320-
(my-let-syntaxes ([(x:my-var ...) trans:my-macro]) body:my-expr)
322+
(my-let-syntaxes ([(x:my-var ...) trans:my-macro])
323+
body:my-expr)
321324
#:binding (scope (bind-syntaxes x ... trans) body)))
322325
]
323326
Here, @racket[trans] should evaluate to multiple transformers using @racket[values].
@@ -351,7 +354,8 @@ Similar to syntax patterns and templates, syntax specs and binding specs have a
351354

352355
The @racket[nest] binding spec sort of folds over the binding pairs. In this example, it'll produce binding structure like
353356

354-
@racketblock[[e1 (scope (bind x1) [e2 (scope (bind x2) [... [en (scope (bind xn) body)]])])]]
357+
@racketblock[[e1 (scope (bind x1) [e2 (scope (bind x2)
358+
[... [en (scope (bind xn) body)]])])]]
355359

356360
@racket[nest] does not necessarily have to be used with a sequence.
357361

scribblings/tutorial/multipass-tutorial.scrbl

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,8 @@ Now let's automate this process:
264264
(define bindings-rev '())
265265
(code:comment2 "Identifier rhs-expr -> Void")
266266
(code:comment2 "record a variable binding pair")
267-
(define (lift-binding! x e) (set! bindings-rev (cons (list x e) bindings-rev)))
267+
(define (lift-binding! x e)
268+
(set! bindings-rev (cons (list x e) bindings-rev)))
268269
(define e^ (to-rhs! e lift-binding!))
269270
(wrap-lets e^ (reverse bindings-rev)))
270271

@@ -380,7 +381,8 @@ Without pruning, this would print something, but with pruning, it would not. Our
380381
(define (remove-unused-vars e used-vars)
381382
(syntax-parse e
382383
[((~and let (~datum let)) ([x e]) body)
383-
(define/syntax-parse body^ (remove-unused-vars #'body used-vars))
384+
(define/syntax-parse body^
385+
(remove-unused-vars #'body used-vars))
384386
(if (symbol-set-member? used-vars #'x)
385387
#'(let ([x e])
386388
body^)
@@ -406,9 +408,12 @@ Due to the nature of expansion and binding structure, some special care needs to
406408
(define-syntax compile-expr
407409
(syntax-parser
408410
[(_ e)
409-
(define e/anf (local-expand-anf (to-anf #'e) #:should-rename? #t))
410-
(define e/pruned (prune-unused-variables e/anf))
411-
(define/syntax-parse e/pruned^ (local-expand-anf e/pruned #:should-rename? #t))
411+
(define e/anf
412+
(local-expand-anf (to-anf #'e) #:should-rename? #t))
413+
(define e/pruned
414+
(prune-unused-variables e/anf))
415+
(define/syntax-parse e/pruned^
416+
(local-expand-anf e/pruned #:should-rename? #t))
412417
#'(compile-anf e/pruned^)]))
413418
]
414419

scribblings/tutorial/stlc-tutorial.scrbl

Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ Let's start out with defining the grammar and binding rules for basic typed expr
2727
x:typed-var
2828
n:number
2929

30-
(#%lambda ([x:typed-var (~datum :) t:type] ...) body:typed-expr)
30+
(#%lambda ([x:typed-var (~datum :) t:type] ...)
31+
body:typed-expr)
3132
#:binding (scope (bind x) ... body)
3233
(#%app fun:typed-expr arg:typed-expr ...)
3334

@@ -111,20 +112,25 @@ Now let's define @racket[infer-expr-type]:
111112
(define f-type (infer-expr-type #'f))
112113
(match f-type
113114
[(function-type expected-arg-types return-type)
114-
(unless (= (length expected-arg-types) (length (attribute arg)))
115-
(raise-syntax-error 'infer-expr-type
116-
(format "arity error. expected ~a arguments, but got ~a"
117-
(length expected-arg-types)
118-
(length (attribute arg)))
119-
this-syntax))
115+
(unless (= (length expected-arg-types)
116+
(length (attribute arg)))
117+
(raise-syntax-error
118+
'infer-expr-type
119+
(format
120+
"arity error. expected ~a arguments, but got ~a"
121+
(length expected-arg-types)
122+
(length (attribute arg)))
123+
this-syntax))
120124
(for ([expected-type expected-arg-types]
121125
[arg (attribute arg)])
122126
(check-expr-type arg expected-type))
123127
return-type]
124-
[_ (raise-syntax-error 'infer-expr-type
125-
(format "type mismatch. expected a function type, but got ~a"
126-
(type->datum f-type))
127-
#'f)])]
128+
[_ (raise-syntax-error
129+
'infer-expr-type
130+
(format
131+
"type mismatch. expected a function type, but got ~a"
132+
(type->datum f-type))
133+
#'f)])]
128134
[((~datum :) e t-stx)
129135
(define t (parse-type #'t-stx))
130136
(check-expr-type #'e t)
@@ -136,19 +142,24 @@ Now let's define @racket[infer-expr-type]:
136142
(infer-expr-type #'body)]))
137143

138144
(define (get-identifier-type x)
139-
(symbol-table-ref types x (lambda () (raise-syntax-error #f "untyped identifier" x))))
145+
(symbol-table-ref
146+
types x
147+
(lambda () (raise-syntax-error #f "untyped identifier" x))))
140148

141149
(define (extend-type-environment! x t)
142-
(void (symbol-table-ref types x (lambda () (symbol-table-set! types x t)))))
150+
(void (symbol-table-ref
151+
types x
152+
(lambda () (symbol-table-set! types x t)))))
143153

144154
(define (check-expr-type e expected-type)
145155
(define actual-type (infer-expr-type e))
146156
(unless (equal? expected-type actual-type)
147-
(raise-syntax-error 'infer-expr-type
148-
(format "type mismatch. expected ~a, but got ~a"
149-
(type->datum expected-type)
150-
(type->datum actual-type))
151-
e)))
157+
(raise-syntax-error
158+
'infer-expr-type
159+
(format "type mismatch. expected ~a, but got ~a"
160+
(type->datum expected-type)
161+
(type->datum actual-type))
162+
e)))
152163

153164
(define (parse-type t-stx)
154165
(syntax-parse t-stx
@@ -208,7 +219,8 @@ Finally, we can write macros for @racket[let] and @racket[lambda]:
208219

209220
(define-stlc-syntax lambda
210221
(syntax-parser
211-
[(_ ([x (~datum :) t] ...) body) #'(#%lambda ([x : t] ...) body)]))
222+
[(_ ([x (~datum :) t] ...) body)
223+
#'(#%lambda ([x : t] ...) body)]))
212224

213225
(define-stlc-syntax let*
214226
(syntax-parser
@@ -307,8 +319,10 @@ Let's do it!
307319
(match t
308320
[(number-type) #'number?]
309321
[(function-type arg-types return-type)
310-
(define/syntax-parse (arg-type-stx ...) (map type->contract-stx arg-types))
311-
(define/syntax-parse return-type-stx (type->contract-stx return-type))
322+
(define/syntax-parse (arg-type-stx ...)
323+
(map type->contract-stx arg-types))
324+
(define/syntax-parse return-type-stx
325+
(type->contract-stx return-type))
312326
#'(-> arg-type-stx ... return-type-stx)])))
313327

314328
(define-syntax compile-expr
@@ -346,7 +360,8 @@ Let's run some example programs now:
346360
1))
347361
(eval:error
348362
(stlc/expr
349-
(let ([app (lambda ([f : (-> Number Number)] [x : Number]) (f x))])
363+
(let ([app (lambda ([f : (-> Number Number)] [x : Number])
364+
(f x))])
350365
(rkt (app "not a function" 1) : Number))))
351366
]
352367

@@ -462,7 +477,8 @@ Now let's update the rest of our code:
462477
(define-syntax compile-defn-or-expr/top
463478
(syntax-parser
464479
[(_ ((~datum #%define) x:id _ body))
465-
#`(define x (compile-expr/top body #,(get-identifier-type #'x) #t))]
480+
#`(define x (compile-expr/top
481+
body #,(get-identifier-type #'x) #t))]
466482
[(_ ((~datum begin) body ...+))
467483
#'(begin (compile-defn-or-expr/top body) ...)]
468484
[(_ e)
@@ -501,7 +517,8 @@ Now let's update the rest of our code:
501517
(syntax-parser
502518
[(_ x:id (~datum :) t e)
503519
#'(#%define x t e)]
504-
[(_ (f:id [arg:id (~datum :) arg-type] ...) (~datum ->) return-type body ...)
520+
[(_ (f:id [arg:id (~datum :) arg-type] ...)
521+
(~datum ->) return-type body ...)
505522
#'(#%define f (-> arg-type ... return-type)
506523
(lambda ([arg : arg-type] ...)
507524
body

0 commit comments

Comments
 (0)