Skip to content

Commit e72b939

Browse files
Automated Resyntax fixes (#1443)
* Fix 13 occurrences of `single-clause-match-to-match-define` This `match` expression can be simplified using `match-define`. * Fix 1 occurrence of `define-lambda-to-define` The `define` form supports a shorthand for defining functions. * Fix 8 occurrences of `let-to-define` Internal definitions are recommended instead of `let` expressions, to reduce nesting. * Fix 6 occurrences of `define-syntax-syntax-rules-to-define-syntax-rule` This `define-syntax` macro can be replaced with a simpler, equivalent `define-syntax-rule` macro. * Fix 4 occurrences of `if-else-false-to-and` This `if` expression can be refactored to an equivalent expression using `and`. * Fix 1 occurrence of `inverted-when` This negated `when` expression can be replaced by an `unless` expression. * Fix 2 occurrences of `zero-comparison-to-positive?` This expression is equivalent to calling the `positive?` predicate. * Fix 1 occurrence of `define-simple-macro-to-define-syntax-parse-rule` The `define-simple-macro` form has been renamed to `define-syntax-parse-rule`. * Fix 1 occurrence of `provide-deduplication` Providing the same identifier multiple times is unnecessary. * Fix 1 occurrence of `if-let-to-cond` `cond` with internal definitions is preferred over `if` with `let`, to reduce nesting * Fix 1 occurrence of `apply-flattening` The `apply` function accepts single arguments in addition to a trailing list argument. * Fix 2 occurrences of `define-values-values-to-define` This use of `define-values` is unnecessary. * Fix 3 occurrences of `sort-with-keyed-comparator-to-sort-by-key` This `sort` expression can be replaced with a simpler, equivalent expression. * Fix 1 occurrence of `map-to-for` This `map` operation can be replaced with a `for/list` loop. * Fix 3 occurrences of `quasiquote-to-list` This quasiquotation is equialent to a simple `list` call. * Fix 1 occurrence of `for/fold-result-keyword` Only one of the `for/fold` expression's result values is used. Use the `#:result` keyword to return just that result. * Fix 1 occurrence of `when-expression-in-for-loop-to-when-keyword` Use the `#:when` keyword instead of `when` to reduce loop body indentation. --------- Co-authored-by: resyntax-ci[bot] <181813515+resyntax-ci[bot]@users.noreply.github.com>
1 parent 8257245 commit e72b939

File tree

18 files changed

+282
-310
lines changed

18 files changed

+282
-310
lines changed

typed-racket-lib/typed-racket/base-env/annotate-classes.rkt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@
169169
#:with ty #'t))
170170
(define-splicing-syntax-class optional-standalone-annotation
171171
(pattern (~optional a:standalone-annotation)
172-
#:attr ty (if (attribute a) #'a.ty #f)))
172+
#:attr ty (and (attribute a) #'a.ty)))
173173

174174
(define-syntax-class type-variables
175175
#:attributes ((vars 1))
@@ -330,10 +330,8 @@
330330
(define-values (all-mand-tys all-opt-tys)
331331
(cond
332332
[kw-property
333-
(define-values (mand-kw-set opt-kw-set)
334-
(values
335-
(list->set (lambda-kws-mand kw-property))
336-
(list->set (lambda-kws-opt kw-property))))
333+
(define mand-kw-set (list->set (lambda-kws-mand kw-property)))
334+
(define opt-kw-set (list->set (lambda-kws-opt kw-property)))
337335

338336
(define-values (mand-tys^ opt-kw^)
339337
(partition (part-pred opt-kw-set)

typed-racket-lib/typed-racket/base-env/base-structs.rkt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111

1212
(require (for-template racket/base (prefix-in k: '#%kernel)))
1313

14-
(provide initialize-structs -Date -Srcloc -Date -Arity-At-Least -Exn)
14+
(provide initialize-structs
15+
-Date
16+
-Srcloc
17+
-Arity-At-Least
18+
-Exn)
1519

1620
(define-syntax define-hierarchy
1721
(syntax-rules (define-hierarchy)

typed-racket-lib/typed-racket/base-env/unit-prims.rkt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,8 @@
133133
;; in the signature, this is needed to typecheck define-values/invoke-unit forms
134134
(define-for-syntax (imports/members sig-id)
135135
(define-values (_1 imp-mem _2 _3) (signature-members sig-id sig-id))
136-
#`(#,sig-id #,@(map (lambda (id)
137-
(local-expand
138-
id
139-
(syntax-local-context)
140-
(kernel-form-identifier-list)))
141-
imp-mem)))
136+
#`(#,sig-id #,@(for/list ([id (in-list imp-mem)])
137+
(local-expand id (syntax-local-context) (kernel-form-identifier-list)))))
142138

143139
;; Given a list of signature specs
144140
;; Processes each signature spec to determine the variables exported

typed-racket-lib/typed-racket/static-contracts/combinators/dep-function.rkt

Lines changed: 53 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -25,64 +25,63 @@
2525
#:property prop:combinator-name "dep->/sc"
2626
#:methods gen:sc
2727
[(define (sc->contract v rec)
28-
(match v
29-
[(->i/sc typed-side? ids dom/scs dom-deps pre pre-deps rng/scs rng-deps)
30-
(with-syntax ([(id ...) ids]
31-
[(c ...) (for/list ([d/sc (in-list dom/scs)]
32-
[dep-ids (in-list dom-deps)])
33-
(cond
34-
[(not (null? dep-ids))
35-
(parameterize ([static-contract-may-contain-free-ids? #t])
36-
(rec d/sc))]
37-
[else (rec d/sc)]))]
38-
[(dep ...) dom-deps]
39-
[(r-deps ...) rng-deps]
40-
[(p-deps ...) pre-deps])
41-
#`(->i ([id dep c] ...)
42-
#,@(cond
43-
[(not pre) #'()]
44-
[else #`(#:pre (p-deps ...)
45-
#,(cond
46-
[(not (null? pre-deps))
47-
(parameterize ([static-contract-may-contain-free-ids? #t])
48-
(rec pre))]
49-
[else (rec pre)]))])
50-
#,(cond
51-
[(and typed-side? (andmap any/sc? rng-deps)) #'any]
52-
[(null? rng-deps)
53-
#`[_ () (values #,@(map rec rng/scs))]]
54-
[else
55-
(parameterize ([static-contract-may-contain-free-ids? #t])
56-
#`[_ (r-deps ...) (values #,@(map rec rng/scs))])])))]))
28+
(match-define (->i/sc typed-side? ids dom/scs dom-deps pre pre-deps rng/scs rng-deps) v)
29+
(with-syntax ([(id ...) ids]
30+
[(c ...) (for/list ([d/sc (in-list dom/scs)]
31+
[dep-ids (in-list dom-deps)])
32+
(cond
33+
[(not (null? dep-ids))
34+
(parameterize ([static-contract-may-contain-free-ids? #t])
35+
(rec d/sc))]
36+
[else (rec d/sc)]))]
37+
[(dep ...) dom-deps]
38+
[(r-deps ...) rng-deps]
39+
[(p-deps ...) pre-deps])
40+
#`(->i ([id dep c] ...)
41+
#,@(cond
42+
[(not pre) #'()]
43+
[else
44+
#`(#:pre (p-deps ...)
45+
#,(cond
46+
[(not (null? pre-deps))
47+
(parameterize ([static-contract-may-contain-free-ids? #t])
48+
(rec pre))]
49+
[else (rec pre)]))])
50+
#,(cond
51+
[(and typed-side? (andmap any/sc? rng-deps)) #'any]
52+
[(null? rng-deps) #`[_ () (values #,@(map rec rng/scs))]]
53+
[else
54+
(parameterize ([static-contract-may-contain-free-ids? #t])
55+
#`[_ (r-deps ...) (values #,@(map rec rng/scs))])]))))
5756
(define (sc-map v f)
58-
(match v
59-
[(->i/sc typed-side? ids dom/scs dom-deps pre pre-deps rng/scs rng-deps)
60-
(->i/sc typed-side?
61-
ids
62-
(for/list ([d/sc (in-list dom/scs)])
63-
(f d/sc 'contravariant))
64-
dom-deps
65-
(and pre (f pre 'contravariant))
66-
pre-deps
67-
(for/list ([r/sc (in-list rng/scs)])
68-
(f r/sc 'covariant))
69-
rng-deps)]))
57+
(match-define (->i/sc typed-side? ids dom/scs dom-deps pre pre-deps rng/scs rng-deps) v)
58+
(->i/sc typed-side?
59+
ids
60+
(for/list ([d/sc (in-list dom/scs)])
61+
(f d/sc 'contravariant))
62+
dom-deps
63+
(and pre (f pre 'contravariant))
64+
pre-deps
65+
(for/list ([r/sc (in-list rng/scs)])
66+
(f r/sc 'covariant))
67+
rng-deps))
7068
(define (sc-traverse v f)
71-
(match v
72-
[(->i/sc _ _ dom/scs _ pre _ rng/scs _)
73-
(for ([d/sc (in-list dom/scs)])
74-
(f d/sc 'contravariant))
75-
(when pre (f pre 'contravariant))
76-
(for ([r/sc (in-list rng/scs)])
77-
(f r/sc 'covariant))]))
69+
(match-define (->i/sc _ _ dom/scs _ pre _ rng/scs _) v)
70+
(for ([d/sc (in-list dom/scs)])
71+
(f d/sc 'contravariant))
72+
(when pre
73+
(f pre 'contravariant))
74+
(for ([r/sc (in-list rng/scs)])
75+
(f r/sc 'covariant)))
7876
(define (sc-terminal-kind v) 'impersonator)
7977
(define (sc->constraints v f)
80-
(match v
81-
[(->i/sc _ _ dom/scs _ pre _ rng/scs _)
82-
(merge-restricts* 'impersonator
83-
(append (if pre (list (f pre)) (list))
84-
(map f rng/scs)
85-
(map f dom/scs)))]))])
78+
(match-define (->i/sc _ _ dom/scs _ pre _ rng/scs _) v)
79+
(merge-restricts* 'impersonator
80+
(append (if pre
81+
(list (f pre))
82+
(list))
83+
(map f rng/scs)
84+
(map f dom/scs))))])
8685

8786
(require-for-cond-contract "proposition.rkt")
8887

typed-racket-lib/typed-racket/static-contracts/combinators/unit.rkt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@
1616
#:transparent
1717
#:property prop:combinator-name "unit/sc"
1818
#:methods gen:sc
19-
[(define (sc-map v f)
20-
(match v
21-
[(unit-combinator unit-spec)
22-
(unit-combinator (unit-spec-sc-map f unit-spec))]))
19+
[(define (sc-map v f)
20+
(match-define (unit-combinator unit-spec) v)
21+
(unit-combinator (unit-spec-sc-map f unit-spec)))
2322
(define (sc-traverse v f)
2423
(match v
2524
[(unit-combinator unit-spec)

typed-racket-lib/typed-racket/types/base-abbrev.rkt

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,11 @@
102102
(foldr -pair b l))
103103

104104
;; Recursive types
105-
(define-syntax -v
106-
(syntax-rules ()
107-
[(_ x) (make-F 'x)]))
105+
(define-syntax-rule (-v x)
106+
(make-F 'x))
108107

109-
(define-syntax -mu
110-
(syntax-rules ()
111-
[(_ var ty)
112-
(let ([var (-v var)])
113-
(make-Mu 'var ty))]))
108+
(define-syntax-rule (-mu var ty)
109+
(let ([var (-v var)]) (make-Mu 'var ty)))
114110

115111
;; Results
116112
(define/cond-contract (-result t [pset -tt-propset] [o -empty-obj])
@@ -493,31 +489,20 @@
493489

494490

495491
;; Convenient syntax for polymorphic types
496-
(define-syntax -poly
497-
(syntax-rules ()
498-
[(_ (vars ...) ty)
499-
(let ([vars (-v vars)] ...)
500-
(make-Poly (list 'vars ...) ty))]))
501-
502-
(define-syntax -polydots
503-
(syntax-rules ()
504-
[(_ (vars ... dotted) ty)
505-
(let ([dotted (-v dotted)]
506-
[vars (-v vars)] ...)
507-
(make-PolyDots (list 'vars ... 'dotted) ty))]))
508-
509-
(define-syntax -polyrow
510-
(syntax-rules ()
511-
[(_ (var) consts ty)
512-
(let ([var (-v var)])
513-
(make-PolyRow (list 'var) ty consts))]))
492+
(define-syntax-rule (-poly (vars ...) ty)
493+
(let ([vars (-v vars)] ...) (make-Poly (list 'vars ...) ty)))
494+
495+
(define-syntax-rule (-polydots (vars ... dotted) ty)
496+
(let ([dotted (-v dotted)]
497+
[vars (-v vars)] ...)
498+
(make-PolyDots (list 'vars ... 'dotted) ty)))
499+
500+
(define-syntax-rule (-polyrow (var) consts ty)
501+
(let ([var (-v var)]) (make-PolyRow (list 'var) ty consts)))
514502

515503
;; abbreviation for existential types
516-
(define-syntax -some
517-
(syntax-rules ()
518-
[(_ (vars ...) ty)
519-
(let ([vars (-v vars)] ...)
520-
(make-Some (list 'vars ...) ty))]))
504+
(define-syntax-rule (-some (vars ...) ty)
505+
(let ([vars (-v vars)] ...) (make-Some (list 'vars ...) ty)))
521506

522507
;; abbreviation for existential type results
523508
(define-syntax -some-res

typed-racket-lib/typed-racket/types/classes.rkt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@
8888
(match-define (Row: inits fields methods augments _) row)
8989
;; check a given clause type (e.g., init, field)
9090
(define (check-clauses row-dict absence-set)
91-
(for ([(name _) (in-dict row-dict)])
92-
(when (member name absence-set)
93-
(fail name))))
91+
(for ([(name _) (in-dict row-dict)]
92+
#:when (member name absence-set))
93+
(fail name)))
9494
(check-clauses inits init-absents)
9595
(check-clauses fields field-absents)
9696
(check-clauses methods method-absents)

typed-racket-lib/typed-racket/types/generalize.rkt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@
4545
[(Pair: t1 (== -Null)) (-lst t1)]
4646
[(MPair: t1 (== -Null)) (-mlst t1)]
4747
[(or (Pair: t1 t2) (MPair: t1 t2))
48-
(let ([t-new (loop t2)])
49-
(define -lst-type
50-
((match t*
51-
[(Pair: _ _) -lst]
52-
[(MPair: _ _) -mlst])
53-
t1))
54-
(if (type-equiv? -lst-type t-new)
55-
-lst-type
56-
(exit t)))]
48+
(define t-new (loop t2))
49+
(define -lst-type
50+
((match t*
51+
[(Pair: _ _) -lst]
52+
[(MPair: _ _) -mlst])
53+
t1))
54+
(if (type-equiv? -lst-type t-new)
55+
-lst-type
56+
(exit t))]
5757
[(ListDots: t bound) (-lst (substitute Univ bound t))]
5858
[(? (lambda (t) (subtype t -Symbol))) -Symbol]
5959
[(== -True) -Boolean]

typed-racket-lib/typed-racket/types/kw-types.rkt

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@
3131
;; the kw protocol puts the arguments in keyword-sorted order in the
3232
;; function header, so we need to sort the types to match
3333
(define sorted-kws
34-
(sort keywords (λ (kw1 kw2) (keyword<? (Keyword-kw kw1)
35-
(Keyword-kw kw2)))))
34+
(sort keywords keyword<? #:key Keyword-kw))
3635

3736
(define pos-opt-arg-types
3837
(append (for/list ([t (in-list optional-arg-types)]
@@ -148,9 +147,7 @@
148147
(define (calculate-mandatory-args orig-arrows)
149148
;; sorted order is important, our loops below rely on this order
150149
(define arity-sorted-arrows
151-
(sort orig-arrows
152-
(λ (a1 a2) (>= (Arrow-max-arity a1)
153-
(Arrow-max-arity a2)))))
150+
(sort orig-arrows >= #:key Arrow-max-arity))
154151
(for/fold ([mand-arg-table '()])
155152
([arrow (in-list arity-sorted-arrows)])
156153
(cond
@@ -172,36 +169,38 @@
172169
;; set and set->list to retain determinism
173170
(remove-duplicates
174171
(for/list ([(arrow arrow-mand-arg-count) (in-assoc mand-arg-table)])
175-
(match arrow
176-
[(Arrow: dom rst kws rng rng-T+)
177-
(define kws* (if actual-kws
178-
(handle-extra-or-missing-kws kws actual-kws)
179-
kws))
180-
(define kw-opts-supplied (if actual-kws
181-
(lambda-kws-opt-supplied actual-kws)
182-
'()))
183-
(define mand-arg-count (if actual-kws
184-
(lambda-kws-pos-mand-count actual-kws)
185-
arrow-mand-arg-count))
186-
(define opt-arg-count (- (length dom) mand-arg-count))
187-
(define extra-opt-arg-count
188-
;; In case `dom` has too many arguments that we try to treat
189-
;; as optional:
190-
(if actual-kws
191-
(max 0 (- opt-arg-count (length (lambda-kws-pos-opt-supplied? actual-kws))))
192-
0))
193-
(convert kws*
194-
kw-opts-supplied
195-
(take dom mand-arg-count)
196-
(drop dom mand-arg-count)
197-
(if actual-kws
198-
(append (lambda-kws-pos-opt-supplied? actual-kws)
199-
(make-list extra-opt-arg-count #f))
200-
(make-list opt-arg-count #f))
201-
rng
202-
rst
203-
split?
204-
rng-T+)]))))
172+
(match-define (Arrow: dom rst kws rng rng-T+) arrow)
173+
(define kws*
174+
(if actual-kws
175+
(handle-extra-or-missing-kws kws actual-kws)
176+
kws))
177+
(define kw-opts-supplied
178+
(if actual-kws
179+
(lambda-kws-opt-supplied actual-kws)
180+
'()))
181+
(define mand-arg-count
182+
(if actual-kws
183+
(lambda-kws-pos-mand-count actual-kws)
184+
arrow-mand-arg-count))
185+
(define opt-arg-count (- (length dom) mand-arg-count))
186+
(define extra-opt-arg-count
187+
;; In case `dom` has too many arguments that we try to treat
188+
;; as optional:
189+
(if actual-kws
190+
(max 0 (- opt-arg-count (length (lambda-kws-pos-opt-supplied? actual-kws))))
191+
0))
192+
(convert kws*
193+
kw-opts-supplied
194+
(take dom mand-arg-count)
195+
(drop dom mand-arg-count)
196+
(if actual-kws
197+
(append (lambda-kws-pos-opt-supplied? actual-kws)
198+
(make-list extra-opt-arg-count #f))
199+
(make-list opt-arg-count #f))
200+
rng
201+
rst
202+
split?
203+
rng-T+))))
205204
(apply cl->* fns))
206205

207206
;; kw-convert : Type (Option LambdaKeywords) [Boolean] -> Type
@@ -269,7 +268,7 @@
269268
(take opt-types to-take))
270269
(erase-props/Values rng)
271270
#:kws actual-kws
272-
#:rest (if (= to-take opt-types-count) rest-type #f)
271+
#:rest (and (= to-take opt-types-count) rest-type)
273272
#:T+ rng-T+)))]
274273
[else (int-err "unsupported arrs in keyword function type")])]
275274
[(Poly-names: names f) (make-Poly names (loop f))]

typed-racket-lib/typed-racket/types/match-expanders.rkt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
(app (λ (t) (Listof? t #t)) (? Type? elem-pat)))])))
7676

7777

78-
(define-simple-macro (make-Listof-pred listof-pred?:id pair-matcher:id)
78+
(define-syntax-parse-rule (make-Listof-pred listof-pred?:id pair-matcher:id)
7979
(define (listof-pred? t [simple? #f])
8080
(match t
8181
[(Mu-unsafe:

0 commit comments

Comments
 (0)