Skip to content

Commit d3dc4e0

Browse files
Automated Resyntax fixes (#518)
* Fix 1 occurrence of `inline-unnecessary-begin` This `begin` form can be flattened into the surrounding definition context. * Fix 4 occurrences of `provide/contract-to-contract-out` The `provide/contract` form is a legacy form made obsolete by `contract-out`. * Fix 1 occurrence of `quasiquote-to-list` This quasiquotation is equialent to a simple `list` call. * Fix 5 occurrences of `map-to-for` This `map` operation can be replaced with a `for/list` loop. * Fix 2 occurrences of `always-throwing-if-to-when` Using `when` and `unless` is simpler than a conditional with an always-throwing branch. * Fix 1 occurrence of `or-hash-ref-set!-to-hash-ref!` This expression can be replaced with a simpler, equivalent `hash-ref!` expression. * Fix 1 occurrence of `string-append-and-string-join-to-string-join` This use of `string-append` can be removed by using `string-join`'s keyword arguments. * Fix 3 occurrences of `let-to-define` Internal definitions are recommended instead of `let` expressions, to reduce nesting. * Fix 1 occurrence of `when-expression-in-for-loop-to-when-keyword` Use the `#:when` keyword instead of `when` to reduce loop body indentation. * Fix 1 occurrence of `arrow-contract-with-rest-to-arrow-contract-with-ellipses` This `->*` contract can be rewritten using `->` with ellipses. --------- Co-authored-by: resyntax-ci[bot] <181813515+resyntax-ci[bot]@users.noreply.github.com>
1 parent 7eb0c71 commit d3dc4e0

File tree

10 files changed

+191
-218
lines changed

10 files changed

+191
-218
lines changed

scribble-lib/scribble/private/doc-begin.rkt

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -66,22 +66,15 @@
6666
#'(check-pre-part s (quote-syntax loc))))]))
6767

6868
(define (check-pre-part v loc-stx)
69-
(if (pre-part? v)
70-
v
71-
(error
72-
(format
73-
"~a: not valid in document body (need a pre-part for decode) in: ~e"
74-
(cond
75-
[(and (syntax-source loc-stx)
76-
(syntax-line loc-stx))
77-
(format "~a:~a:~a"
78-
(syntax-source loc-stx)
79-
(syntax-line loc-stx)
80-
(syntax-column loc-stx))]
81-
[(and (syntax-source loc-stx)
82-
(syntax-position loc-stx))
83-
(format "~a:::~a"
84-
(syntax-source loc-stx)
85-
(syntax-position loc-stx))]
86-
[else 'document])
87-
v))))
69+
(unless (pre-part? v)
70+
(error
71+
(format
72+
"~a: not valid in document body (need a pre-part for decode) in: ~e"
73+
(cond
74+
[(and (syntax-source loc-stx) (syntax-line loc-stx))
75+
(format "~a:~a:~a" (syntax-source loc-stx) (syntax-line loc-stx) (syntax-column loc-stx))]
76+
[(and (syntax-source loc-stx) (syntax-position loc-stx))
77+
(format "~a:::~a" (syntax-source loc-stx) (syntax-position loc-stx))]
78+
[else 'document])
79+
v)))
80+
v)

scribble-lib/scribble/private/manual-bib.rkt

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,21 @@
1111

1212
(define-struct a-bib-entry (key val))
1313

14-
(provide/contract
15-
[cite ((string?) () #:rest (listof string?) . ->* . element?)]
16-
[bib-entry ((#:key string? #:title (or/c #f pre-content?))
17-
(#:is-book? boolean? #:author (or/c #f pre-content?)
18-
#:location (or/c #f pre-content?)
19-
#:date (or/c #f pre-content?)
20-
#:url (or/c #f pre-content?)
21-
#:note (or/c #f pre-content?))
22-
. ->* .
23-
a-bib-entry?)]
24-
[rename a-bib-entry? bib-entry? predicate/c]
25-
[bibliography (() (#:tag string?) #:rest (listof a-bib-entry?) . ->* . part?)])
14+
(provide (contract-out
15+
[cite ((string?) () #:rest (listof string?) . ->* . element?)]
16+
[bib-entry
17+
((#:key string? #:title (or/c #f pre-content?)) (#:is-book? boolean?
18+
#:author (or/c #f pre-content?)
19+
#:location (or/c #f pre-content?)
20+
#:date (or/c #f pre-content?)
21+
#:url (or/c #f pre-content?)
22+
#:note (or/c #f pre-content?))
23+
. ->* .
24+
a-bib-entry?)]
25+
(rename a-bib-entry?
26+
bib-entry?
27+
predicate/c)
28+
[bibliography (() (#:tag string?) #:rest (listof a-bib-entry?) . ->* . part?)]))
2629

2730
(define (cite key . keys)
2831
(make-element
@@ -65,7 +68,9 @@
6568
`(" " ,@(decode-content (list location)) ,(if date "," "."))
6669
null)
6770
(if date `(" " ,@(decode-content (list date)) ".") null)
68-
(if url `(" " ,(link url (tt url))) null)
71+
(if url (list " "
72+
(link url
73+
(tt url))) null)
6974
(if note (decode-content (list note)) null)))))
7075

7176
(define-on-demand bib-style (make-style "RBibliography" scheme-properties))
@@ -81,12 +86,10 @@
8186
(list
8287
(make-table
8388
bib-style
84-
(map (lambda (c)
85-
(define key (a-bib-entry-key c))
86-
(define val (a-bib-entry-val c))
87-
(list
88-
(to-flow (make-target-element #f `("[" ,key "]") `(cite ,key)))
89+
(for/list ([c (in-list citations)])
90+
(define key (a-bib-entry-key c))
91+
(define val (a-bib-entry-val c))
92+
(list (to-flow (make-target-element #f `("[" ,key "]") `(cite ,key)))
8993
flow-spacer
90-
(to-flow val)))
91-
citations))))
94+
(to-flow val))))))
9295
null))

scribble-lib/scribble/private/manual-bind.rkt

Lines changed: 85 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,7 @@
5959
(define hovers (make-weak-hasheq))
6060
(define (intern-hover-style text)
6161
(let ([text (datum-intern-literal text)])
62-
(or (hash-ref hovers text #f)
63-
(let ([s (make-style #f (list (make-hover-property text)))])
64-
(hash-set! hovers text s)
65-
s))))
62+
(hash-ref! hovers text (λ () (make-style #f (list (make-hover-property text)))))))
6663

6764
(define (annote-exporting-library e)
6865
(make-delayed-element
@@ -71,15 +68,14 @@
7168
(if (and from (pair? from))
7269
(make-element
7370
(intern-hover-style
74-
(string-append
75-
"Provided from: "
76-
(string-join (map ~s from) ", ")
77-
(let ([from-pkgs (resolve-get/tentative p ri '(exporting-packages #f))])
78-
(if (and from-pkgs (pair? from-pkgs))
79-
(string-append
80-
" | Package: "
81-
(string-join (map ~a from-pkgs) ", "))
82-
""))))
71+
(string-join (map ~s from)
72+
", "
73+
#:before-first "Provided from: "
74+
#:after-last
75+
(let ([from-pkgs (resolve-get/tentative p ri '(exporting-packages #f))])
76+
(if (and from-pkgs (pair? from-pkgs))
77+
(string-append " | Package: " (string-join (map ~a from-pkgs) ", "))
78+
""))))
8379
e)
8480
e))
8581
(lambda () e)
@@ -114,30 +110,30 @@
114110
(lambda (x add) x)))
115111
(let ([lib
116112
(or (for/or ([lib (in-list (or source-libs null))])
117-
(let ([checker
118-
(hash-ref
119-
checkers lib
120-
(lambda ()
121-
(define ns-id
122-
(let ([ns (make-base-empty-namespace)])
123-
(parameterize ([current-namespace ns])
124-
;; A `(namespace-require `(for-label ,lib))` can
125-
;; fail if `lib` provides different bindings of the
126-
;; same name at different phases. We can require phases
127-
;; 1 and 0 separately, in which case the phase-0
128-
;; binding shadows the phase-1 one in that case.
129-
;; This strategy only works for documenting bindings
130-
;; at phases 0 and 1, though.
131-
(namespace-require `(just-meta 1 (for-label ,lib)))
132-
(namespace-require `(just-meta 0 (for-label ,lib)))
133-
(namespace-syntax-introduce (datum->syntax #f 'x)))))
134-
(define (checker id intro)
135-
(free-label-identifier=?
136-
(intro (datum->syntax ns-id (syntax-e id)) 'add)
137-
(intro id 'add)))
138-
(hash-set! checkers lib checker)
139-
checker))])
140-
(and (checker id intro) lib)))
113+
(define checker
114+
(hash-ref checkers
115+
lib
116+
(lambda ()
117+
(define ns-id
118+
(let ([ns (make-base-empty-namespace)])
119+
(parameterize ([current-namespace ns])
120+
;; A `(namespace-require `(for-label ,lib))` can
121+
;; fail if `lib` provides different bindings of the
122+
;; same name at different phases. We can require phases
123+
;; 1 and 0 separately, in which case the phase-0
124+
;; binding shadows the phase-1 one in that case.
125+
;; This strategy only works for documenting bindings
126+
;; at phases 0 and 1, though.
127+
(namespace-require `(just-meta 1 (for-label ,lib)))
128+
(namespace-require `(just-meta 0 (for-label ,lib)))
129+
(namespace-syntax-introduce (datum->syntax #f 'x)))))
130+
(define (checker id intro)
131+
(free-label-identifier=? (intro (datum->syntax ns-id (syntax-e id))
132+
'add)
133+
(intro id 'add)))
134+
(hash-set! checkers lib checker)
135+
checker)))
136+
(and (checker id intro) lib))
141137
(and (pair? libs) (car libs)))])
142138
(and lib (module-path-index->taglet
143139
(module-path-index-join lib #f)))))
@@ -198,79 +194,64 @@
198194
#:show-libs? [show-libs? #t])
199195
;; This function could have more optional argument to select
200196
;; whether to index the id, include a toc link, etc.
201-
(let ([dep? #t])
202-
(define maker
203-
(if form?
204-
(id-to-form-target-maker id dep?)
205-
(id-to-target-maker id dep?)))
206-
(define-values (elem elem-ref)
207-
(if show-libs?
208-
(definition-site (syntax-e id) id form?)
209-
(values (to-element id #:defn? #t)
210-
(to-element id))))
211-
(if maker
212-
(maker elem
213-
(lambda (tag)
214-
(let ([elem
215-
(if index?
216-
(make-index-element
217-
#f (list elem) tag
218-
(list (datum-intern-literal (symbol->string (syntax-e id))))
219-
(list elem)
220-
(and show-libs?
221-
(with-exporting-libraries
222-
(lambda (libs)
223-
(make-exported-index-desc (syntax-e id)
224-
libs)))))
225-
elem)])
226-
(make-target-element #f (list elem) tag))))
227-
elem)))
197+
(define dep? #t)
198+
(define maker
199+
(if form?
200+
(id-to-form-target-maker id dep?)
201+
(id-to-target-maker id dep?)))
202+
(define-values (elem elem-ref)
203+
(if show-libs?
204+
(definition-site (syntax-e id) id form?)
205+
(values (to-element id #:defn? #t) (to-element id))))
206+
(if maker
207+
(maker elem
208+
(lambda (tag)
209+
(let ([elem (if index?
210+
(make-index-element
211+
#f
212+
(list elem)
213+
tag
214+
(list (datum-intern-literal (symbol->string (syntax-e id))))
215+
(list elem)
216+
(and show-libs?
217+
(with-exporting-libraries
218+
(lambda (libs) (make-exported-index-desc (syntax-e id) libs)))))
219+
elem)])
220+
(make-target-element #f (list elem) tag))))
221+
elem))
228222

229223
(define (make-binding-redirect-elements mod-path redirects)
230224
(define taglet (module-path-index->taglet
231225
(module-path-index-join mod-path #f)))
232226
(make-element
233227
#f
234-
(map
235-
(lambda (redirect)
236-
(define id (car redirect))
237-
(define form? (cadr redirect))
238-
(define path (caddr redirect))
239-
(define anchor (cadddr redirect))
240-
(define (make-one kind)
241-
(make-redirect-target-element
242-
#f
243-
null
244-
(intern-taglet (list kind (list taglet id)))
245-
path
246-
anchor))
247-
(make-element
248-
#f
249-
(list (make-one (if form? 'form 'def))
250-
(make-dep (list taglet id) null)
251-
(let ([str (datum-intern-literal (symbol->string id))])
252-
(make-index-element #f
253-
null
254-
(intern-taglet
255-
(list (if form? 'form 'def)
256-
(list taglet id)))
257-
(list str)
258-
(list
259-
(make-element
260-
symbol-color
261-
(list
262-
(make-element
263-
(if form?
264-
syntax-link-color
265-
value-link-color)
266-
(list str)))))
267-
(make-exported-index-desc*
268-
id
269-
(list mod-path)
270-
(hash 'kind (if form?
271-
"syntax"
272-
"procedure"))))))))
273-
redirects)))
228+
(for/list ([redirect (in-list redirects)])
229+
(define id (car redirect))
230+
(define form? (cadr redirect))
231+
(define path (caddr redirect))
232+
(define anchor (cadddr redirect))
233+
(define (make-one kind)
234+
(make-redirect-target-element #f
235+
null
236+
(intern-taglet (list kind (list taglet id)))
237+
path
238+
anchor))
239+
(make-element
240+
#f
241+
(list (make-one (if form? 'form 'def))
242+
(make-dep (list taglet id) null)
243+
(let ([str (datum-intern-literal (symbol->string id))])
244+
(make-index-element
245+
#f
246+
null
247+
(intern-taglet (list (if form? 'form 'def) (list taglet id)))
248+
(list str)
249+
(list (make-element symbol-color
250+
(list (make-element (if form? syntax-link-color value-link-color)
251+
(list str)))))
252+
(make-exported-index-desc* id
253+
(list mod-path)
254+
(hash 'kind (if form? "syntax" "procedure"))))))))))
274255

275256

276257
(define (make-dep t content)

scribble-lib/scribble/private/manual-form.rkt

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -413,11 +413,12 @@
413413
flow-empty-line flow-empty-line)
414414
(list (to-flow nonterm) flow-empty-line (to-flow "=") flow-empty-line
415415
(make-flow (list (car clauses))))
416-
(map (lambda (clause)
417-
(list flow-empty-line flow-empty-line
418-
(to-flow "|") flow-empty-line
419-
(make-flow (list clause))))
420-
(cdr clauses))))
416+
(for/list ([clause (in-list (cdr clauses))])
417+
(list flow-empty-line
418+
flow-empty-line
419+
(to-flow "|")
420+
flow-empty-line
421+
(make-flow (list clause))))))
421422
nonterms clauseses))))
422423

423424
(define (*racketrawgrammar style nonterm clause1 . clauses)
@@ -426,11 +427,8 @@
426427
(define (*racketgrammar lits s-expr clauseses-thunk)
427428
(define l (clauseses-thunk))
428429
(*racketrawgrammars #f
429-
(map (lambda (x)
430-
(make-element #f
431-
(list (hspace 2)
432-
(car x))))
433-
l)
430+
(for/list ([x (in-list l)])
431+
(make-element #f (list (hspace 2) (car x))))
434432
(map cdr l)))
435433

436434
(define (*var id)
@@ -445,14 +443,11 @@
445443
(append
446444
(list (list flow-empty-line))
447445
(list (list (make-flow
448-
(map (lambda (c)
449-
(make-table
450-
"argcontract"
451-
(list
452-
(list (to-flow (hspace 2))
453-
(to-flow ((car c)))
454-
flow-spacer
455-
(to-flow ":")
456-
flow-spacer
457-
(make-flow (list ((cadr c))))))))
458-
contract-procs)))))))
446+
(for/list ([c (in-list contract-procs)])
447+
(make-table "argcontract"
448+
(list (list (to-flow (hspace 2))
449+
(to-flow ((car c)))
450+
flow-spacer
451+
(to-flow ":")
452+
flow-spacer
453+
(make-flow (list ((cadr c))))))))))))))

0 commit comments

Comments
 (0)