Skip to content

Commit 74c174d

Browse files
Automated Resyntax fixes (#735)
* Fix 12 occurrences of `let-to-define` Internal definitions are recommended instead of `let` expressions, to reduce nesting. * Fix 3 occurrences of `cond-let-to-cond-define` Internal definitions are recommended instead of `let` expressions, to reduce nesting. * 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 `for-each-to-for` This `for-each` operation can be replaced with a `for` loop. * Fix 2 occurrences of `instantiate-to-new` The `instantiate` form is for mixing positional and by-name constructor arguments. When no positional arguments are needed, use `new` instead. * Fix 1 occurrence of `map-to-for` This `map` operation can be replaced with a `for/list` loop. --------- Co-authored-by: resyntax-ci[bot] <181813515+resyntax-ci[bot]@users.noreply.github.com>
1 parent 7916c33 commit 74c174d

File tree

4 files changed

+264
-279
lines changed

4 files changed

+264
-279
lines changed

drracket-core-lib/drracket/drracket.rkt

+33-37
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,15 @@
2424
(flush-output))
2525

2626
(define (run-trace-thread)
27-
(let ([evt (make-log-receiver (current-logger) 'info)])
28-
(void
29-
(thread
30-
(λ ()
31-
(let loop ()
32-
(define vec (sync evt))
33-
(define str (vector-ref vec 1))
34-
(when (regexp-match #rx"^cm: *compil(ing|ed)" str)
35-
(display str)
36-
(newline))
37-
(loop)))))))
27+
(define evt (make-log-receiver (current-logger) 'info))
28+
(void (thread (λ ()
29+
(let loop ()
30+
(define vec (sync evt))
31+
(define str (vector-ref vec 1))
32+
(when (regexp-match #rx"^cm: *compil(ing|ed)" str)
33+
(display str)
34+
(newline))
35+
(loop))))))
3836

3937
(cond
4038
[debugging?
@@ -57,14 +55,14 @@
5755
(run-trace-thread)))]
5856
[install-cm?
5957
(flprintf "PLTDRCM: loading compilation manager\n")
60-
(let ([make-compilation-manager-load/use-compiled-handler
61-
(parameterize ([current-namespace (make-base-empty-namespace)])
62-
(dynamic-require 'compiler/cm 'make-compilation-manager-load/use-compiled-handler))])
63-
(flprintf "PLTDRCM: installing compilation manager\n")
64-
(current-load/use-compiled (make-compilation-manager-load/use-compiled-handler))
65-
(when cm-trace?
66-
(flprintf "PLTDRCM: enabling CM tracing\n")
67-
(run-trace-thread)))]
58+
(define make-compilation-manager-load/use-compiled-handler
59+
(parameterize ([current-namespace (make-base-empty-namespace)])
60+
(dynamic-require 'compiler/cm 'make-compilation-manager-load/use-compiled-handler)))
61+
(flprintf "PLTDRCM: installing compilation manager\n")
62+
(current-load/use-compiled (make-compilation-manager-load/use-compiled-handler))
63+
(when cm-trace?
64+
(flprintf "PLTDRCM: enabling CM tracing\n")
65+
(run-trace-thread))]
6866
[first-parallel?
6967
(flprintf "PLTDRPAR: loading compilation manager\n")
7068
(define tools? (not (getenv "PLTNOTOOLS")))
@@ -90,19 +88,17 @@
9088
(define (tool-files id)
9189
(apply
9290
append
93-
(map
94-
(λ (x)
95-
(define proc (get-info/full x))
96-
(if proc
97-
(map (λ (dirs)
98-
(apply build-path
99-
x
100-
(if (list? dirs)
101-
dirs
102-
(list dirs))))
103-
(proc id (λ () '())))
104-
'()))
105-
(find-relevant-directories (list id)))))
91+
(for/list ([x (in-list (find-relevant-directories (list id)))])
92+
(define proc (get-info/full x))
93+
(if proc
94+
(map (λ (dirs)
95+
(apply build-path
96+
x
97+
(if (list? dirs)
98+
dirs
99+
(list dirs))))
100+
(proc id (λ () '())))
101+
'()))))
106102

107103
(define make-compilation-manager-load/use-compiled-handler
108104
(parameterize ([current-namespace (make-base-empty-namespace)])
@@ -146,11 +142,11 @@
146142
;; it creates a new custodian and installs it, but the
147143
;; original eventspace was created on the original custodian
148144
;; and this code does not create a new eventspace.
149-
(let ([orig-cust (current-custodian)]
150-
[orig-eventspace (current-eventspace)]
151-
[new-cust (make-custodian)])
152-
(current-custodian new-cust)
153-
((dynamic-require 'drracket/private/profile-drs 'start-profile) orig-cust)))
145+
(define orig-cust (current-custodian))
146+
(current-eventspace)
147+
(define new-cust (make-custodian))
148+
(current-custodian new-cust)
149+
((dynamic-require 'drracket/private/profile-drs 'start-profile) orig-cust))
154150

155151
(dynamic-require 'drracket/private/drracket-normal #f)
156152

drracket-core-lib/drracket/sprof.rkt

+102-109
Original file line numberDiff line numberDiff line change
@@ -14,44 +14,40 @@
1414
(define traces-table (make-hash))
1515
(let loop ([i 0])
1616
(sleep pause-time)
17-
(let ([new-traces
18-
(map (λ (t) (continuation-mark-set->context (continuation-marks t)))
19-
(get-threads))])
20-
(for-each
21-
(λ (trace)
22-
(for-each
23-
(λ (line)
24-
(hash-set! traces-table line (cons trace (hash-ref traces-table line '()))))
25-
trace))
26-
new-traces)
27-
(cond
28-
[(zero? i)
29-
(update-gui traces-table)
30-
(loop update-frequency)]
31-
[else
32-
(loop (- i 1))]))))))
17+
(define new-traces
18+
(map (λ (t) (continuation-mark-set->context (continuation-marks t))) (get-threads)))
19+
(for-each (λ (trace)
20+
(for-each (λ (line)
21+
(hash-set! traces-table
22+
line
23+
(cons trace (hash-ref traces-table line '()))))
24+
trace))
25+
new-traces)
26+
(cond
27+
[(zero? i)
28+
(update-gui traces-table)
29+
(loop update-frequency)]
30+
[else (loop (- i 1))])))))
3331

3432
(define (format-fn-name i)
35-
(let ([id (car i)]
36-
[src (cdr i)])
37-
(cond
38-
[id (format "~a" id)]
39-
[src
40-
(format "~a:~a~a"
41-
(cond
42-
[(path? (srcloc-source src))
43-
(let-values ([(base name dir?) (split-path (srcloc-source src))])
44-
name)]
45-
[else (srcloc-source src)])
46-
(if (srcloc-line src)
47-
(format "~a:~a"
48-
(srcloc-line src)
49-
(srcloc-column src))
50-
(srcloc-position src))
51-
(if id
52-
(format ": ~a" id)
53-
""))]
54-
[else "???"])))
33+
(define id (car i))
34+
(define src (cdr i))
35+
(cond
36+
[id (format "~a" id)]
37+
[src
38+
(format "~a:~a~a"
39+
(cond
40+
[(path? (srcloc-source src))
41+
(let-values ([(base name dir?) (split-path (srcloc-source src))])
42+
name)]
43+
[else (srcloc-source src)])
44+
(if (srcloc-line src)
45+
(format "~a:~a" (srcloc-line src) (srcloc-column src))
46+
(srcloc-position src))
47+
(if id
48+
(format ": ~a" id)
49+
""))]
50+
[else "???"]))
5551

5652
(define (insert-long-fn-name t i)
5753
(send t begin-edit-sequence)
@@ -76,8 +72,8 @@
7672
(send t end-edit-sequence))
7773

7874
(define (format-percentage n)
79-
(let ([trunc (floor (* n 100))])
80-
(format "~a%" (pad3 trunc))))
75+
(define trunc (floor (* n 100)))
76+
(format "~a%" (pad3 trunc)))
8177

8278
(define (pad3 n)
8379
(cond
@@ -110,16 +106,16 @@
110106
(define/override (on-event event)
111107
(cond
112108
[(send event button-up? 'left)
113-
(let ([admin (get-admin)])
114-
(when admin
115-
(let ([dc (send admin get-dc)])
116-
(let-values ([(x y) (dc-location-to-editor-location (send event get-x)
117-
(send event get-y))])
118-
(let* ([loc (find-position x y)]
119-
[para (position-paragraph loc)])
120-
(set! clicked-srcloc-pr (and (<= 0 para (last-paragraph))
121-
(car (list-ref gui-display-data para))))
122-
(update-gui-display))))))]
109+
(define admin (get-admin))
110+
(when admin
111+
(let ([dc (send admin get-dc)])
112+
(let-values ([(x y) (dc-location-to-editor-location (send event get-x)
113+
(send event get-y))])
114+
(let* ([loc (find-position x y)]
115+
[para (position-paragraph loc)])
116+
(set! clicked-srcloc-pr
117+
(and (<= 0 para (last-paragraph)) (car (list-ref gui-display-data para))))
118+
(update-gui-display)))))]
123119
[else (void)]))
124120

125121
(define/public (set-gui-display-data/refresh traces-table)
@@ -140,42 +136,42 @@
140136
(set! line-to-source (make-hasheq))
141137
(clear-old-pr)
142138
(set! clear-old-pr void)
143-
(let* ([denom-ht (make-hasheq)]
144-
[filtered-gui-display-data
145-
(map
146-
(λ (pr)
147-
(let ([id (car pr)]
148-
[stacks (filter-stacks (cdr pr))])
149-
(for-each (λ (stack) (hash-set! denom-ht stack #t)) stacks)
150-
(cons id stacks)))
151-
gui-display-data)]
152-
[denom-count (hash-count denom-ht)])
153-
(let loop ([prs filtered-gui-display-data]
154-
[first? #t]
155-
[i 0])
156-
(cond
157-
[(null? prs) (void)]
158-
[else
159-
(let* ([pr (car prs)]
160-
[fn (car pr)]
161-
[count (length (cdr pr))])
162-
(cond
163-
[(zero? count)
164-
(loop (cdr prs) first? i)]
165-
[else
166-
(unless first? (insert "\n"))
167-
(let ([before (last-position)])
168-
(hash-set! line-to-source i pr)
169-
(insert (format-percentage (/ count denom-count)))
170-
(insert (format " ~a" (format-fn-name fn)))
171-
(let ([after (last-position)])
172-
(when (equal? (car pr) clicked-srcloc-pr)
173-
(set! clear-old-pr (highlight-range before after "NavajoWhite")))))
174-
(loop (cdr prs) #f (+ i 1))]))]))
175-
(lock #t)
176-
(end-edit-sequence)
177-
(update-info-editor clicked-srcloc-pr)
178-
(send open-button enable (and clicked-srcloc-pr (path? (srcloc-source (cdr clicked-srcloc-pr)))))))
139+
(define denom-ht (make-hasheq))
140+
(define filtered-gui-display-data
141+
(map (λ (pr)
142+
(let ([id (car pr)]
143+
[stacks (filter-stacks (cdr pr))])
144+
(for-each (λ (stack) (hash-set! denom-ht stack #t)) stacks)
145+
(cons id stacks)))
146+
gui-display-data))
147+
(define denom-count (hash-count denom-ht))
148+
(let loop ([prs filtered-gui-display-data]
149+
[first? #t]
150+
[i 0])
151+
(cond
152+
[(null? prs) (void)]
153+
[else
154+
(let* ([pr (car prs)]
155+
[fn (car pr)]
156+
[count (length (cdr pr))])
157+
(cond
158+
[(zero? count) (loop (cdr prs) first? i)]
159+
[else
160+
(unless first?
161+
(insert "\n"))
162+
(let ([before (last-position)])
163+
(hash-set! line-to-source i pr)
164+
(insert (format-percentage (/ count denom-count)))
165+
(insert (format " ~a" (format-fn-name fn)))
166+
(let ([after (last-position)])
167+
(when (equal? (car pr) clicked-srcloc-pr)
168+
(set! clear-old-pr (highlight-range before after "NavajoWhite")))))
169+
(loop (cdr prs) #f (+ i 1))]))]))
170+
(lock #t)
171+
(end-edit-sequence)
172+
(update-info-editor clicked-srcloc-pr)
173+
(send open-button enable
174+
(and clicked-srcloc-pr (path? (srcloc-source (cdr clicked-srcloc-pr))))))
179175

180176
(define/private (filter-stacks stacks)
181177
(cond
@@ -187,11 +183,11 @@
187183

188184
(define/public (open-current-pr)
189185
(when clicked-srcloc-pr
190-
(let ([src (cdr clicked-srcloc-pr)])
191-
(when (path? (srcloc-source src))
192-
(printf "open ~s\n" (srcloc-source src))
193-
(when (number? (srcloc-position src))
194-
(printf "go to ~s\n" (srcloc-position src)))))))
186+
(define src (cdr clicked-srcloc-pr))
187+
(when (path? (srcloc-source src))
188+
(printf "open ~s\n" (srcloc-source src))
189+
(when (number? (srcloc-position src))
190+
(printf "go to ~s\n" (srcloc-position src))))))
195191

196192
(define/private (update-info-editor pr)
197193
(send vp change-children (λ (l) (if pr (list ec1 lp) (list ec1))))
@@ -295,17 +291,15 @@
295291
(define show/hide-menu-item #f)
296292

297293
(define/public (show/hide-sprof-panel show?)
298-
(let ([main-children (send main-panel get-children)])
299-
(send show/hide-menu-item
300-
set-label
301-
(if show? sc-hide-sprof sc-show-sprof))
302-
(unless (or (and show? (= 2 (length main-children)))
303-
(and (not show?) (= 1 (length main-children))))
304-
(send main-panel change-children
305-
(λ (l)
306-
(if show?
307-
(list everything-else sprof-main-panel)
308-
(list everything-else)))))))
294+
(define main-children (send main-panel get-children))
295+
(send show/hide-menu-item set-label (if show? sc-hide-sprof sc-show-sprof))
296+
(unless (or (and show? (= 2 (length main-children)))
297+
(and (not show?) (= 1 (length main-children))))
298+
(send main-panel change-children
299+
(λ (l)
300+
(if show?
301+
(list everything-else sprof-main-panel)
302+
(list everything-else))))))
309303

310304
(define/override (make-root-area-container cls parent)
311305
(set! main-panel (super make-root-area-container panel:horizontal-dragable% parent))
@@ -377,15 +371,14 @@
377371
(mixin (drscheme:rep:text<%>) ()
378372
(inherit get-user-custodian)
379373
(define/public (get-threads-to-profile)
380-
(let ([thds '()])
381-
(let loop ([cust (get-user-custodian)])
382-
(for-each
383-
(λ (obj)
384-
(cond
385-
[(custodian? obj) (loop obj)]
386-
[(thread? obj) (set! thds (cons obj thds))]))
387-
(custodian-managed-list cust system-custodian)))
388-
thds))
374+
(define thds '())
375+
(let loop ([cust (get-user-custodian)])
376+
(for-each (λ (obj)
377+
(cond
378+
[(custodian? obj) (loop obj)]
379+
[(thread? obj) (set! thds (cons obj thds))]))
380+
(custodian-managed-list cust system-custodian)))
381+
thds)
389382

390383
;; FIX
391384
;; something needs to happen here so that the profiling gets shutdown when the repl dies.

drracket/drracket/plt-installer-tool.rkt

+8-9
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,14 @@
7777
;; browse : -> void
7878
;; gets the name of a file from the user and updates file-text-field
7979
(define (browse)
80-
(let ([filename (parameterize ([finder:default-extension "plt"]
81-
[finder:default-filters
82-
(if (eq? (system-type) 'macosx)
83-
(finder:default-filters)
84-
'(("PLT Files" "*.plt")
85-
("Any" "*.*")))])
86-
(finder:get-file #f "" #f "" dialog))])
87-
(when filename
88-
(send file-text-field set-value (path->string filename)))))
80+
(define filename
81+
(parameterize ([finder:default-extension "plt"]
82+
[finder:default-filters (if (eq? (system-type) 'macosx)
83+
(finder:default-filters)
84+
'(("PLT Files" "*.plt") ("Any" "*.*")))])
85+
(finder:get-file #f "" #f "" dialog)))
86+
(when filename
87+
(send file-text-field set-value (path->string filename))))
8988
;; from-web? : -> boolean
9089
;; returns #t if the user has selected a web address
9190
(define (from-web?)

0 commit comments

Comments
 (0)