From a9beb1604121157a99fe1acbe556c497952daa5d Mon Sep 17 00:00:00 2001 From: "resyntax-ci[bot]" <181813515+resyntax-ci[bot]@users.noreply.github.com> Date: Sun, 28 Sep 2025 00:14:23 +0000 Subject: [PATCH 1/7] Fix 6 occurrences of `let-to-define` Internal definitions are recommended instead of `let` expressions, to reduce nesting. --- drracket-core-lib/browser/external.rkt | 27 +++--- .../drracket/private/honu-logo.rkt | 88 +++++++++---------- drracket-core-lib/drracket/sprof.rkt | 6 +- drracket/setup/plt-installer-unit.rkt | 12 ++- 4 files changed, 66 insertions(+), 67 deletions(-) diff --git a/drracket-core-lib/browser/external.rkt b/drracket-core-lib/browser/external.rkt index bf8a53219..abc426e0e 100644 --- a/drracket-core-lib/browser/external.rkt +++ b/drracket-core-lib/browser/external.rkt @@ -252,11 +252,11 @@ (string-constant proxy-use-proxy)) p (lambda (r e) - (let ([proxy? (= 1 (send r get-selection))]) - (send proxy-spec enable proxy?) - (if proxy? - (update-proxy) - (fw:preferences:set http-proxy-preference #f)))))] + (define proxy? (= 1 (send r get-selection))) + (send proxy-spec enable proxy?) + (if proxy? + (update-proxy) + (fw:preferences:set http-proxy-preference #f))))] [proxy-spec (instantiate horizontal-panel% (p) [stretchable-width #f] [stretchable-height #f] @@ -264,14 +264,15 @@ [update-proxy (lambda () (let ([host (send host get-value)] [port (send port get-value)]) - (let ([ok? (and (regexp-match? #rx"^[-0-9a-zA-Z.]+$" host) - (regexp-match? #rx"^[0-9]+$" port) - (string->number port) - (<= 1 (string->number port) 65535))]) - (when ok? - (fw:preferences:set http-proxy-preference - (list "http" host (string->number port)))) - (send bad-host show (not ok?)))))] + (define ok? + (and (regexp-match? #rx"^[-0-9a-zA-Z.]+$" host) + (regexp-match? #rx"^[0-9]+$" port) + (string->number port) + (<= 1 (string->number port) 65535))) + (when ok? + (fw:preferences:set http-proxy-preference + (list "http" host (string->number port)))) + (send bad-host show (not ok?))))] [host (make-object text-field% (string-constant proxy-host) proxy-spec diff --git a/drracket-core-lib/drracket/private/honu-logo.rkt b/drracket-core-lib/drracket/private/honu-logo.rkt index eae214ae5..6ab357d4c 100644 --- a/drracket-core-lib/drracket/private/honu-logo.rkt +++ b/drracket-core-lib/drracket/private/honu-logo.rkt @@ -15,36 +15,41 @@ (values (+ x (* w 1/2) (* w 1/2 ce)) (+ y (* h 1/2) (* h 1/2 se)))) (define (weighted-arc path x y w h start end ccw? [dx1 0.0] [dy1 0.2] [dx2 dx1] [dy2 (- dy1)]) - (let ([sweep (let loop ([s (if ccw? (- end start) (- start end))]) - (if (< s 0) (loop (+ s (* 2 pi))) s))]) - (if (> sweep pi) - (let ([halfway ((if ccw? + -) start (/ sweep 2))]) - (weighted-arc path x y w h start halfway ccw? dx1 dy1 dx2 dy2) - (weighted-arc path x y w h halfway end ccw? dx2 (- dy2) dx1 (- dy1))) - (let ([p (new dc-path%)]) - ;; Set p to be the arc for a unit circle, - ;; centered on the X-axis: - (let* ([x0 (cos (/ sweep 2))] - [y0 (sin (/ sweep 2))] - [x1 (/ (- 4 x0) 3)] - [y1 (/ (* (- 1 x0) (- 3 x0)) (* 3 y0))] - [x2 x1] - [y2 (- y1)] - [x3 x0] - [y3 (- y0)] - [sw (/ w 2)] - [sh (/ h 2)]) - (send p move-to x0 y0) - (send p curve-to (+ x1 dx1) (+ y1 dy1) (+ x2 dx2) (+ y2 dy2) x3 y3) - ;; Rotate to match start: - (send p rotate (+ (if ccw? start end) (/ sweep 2))) - ;; Scale to match width and height: - (send p scale (/ w 2) (/ h 2)) - ;; Translate to match x and y - (send p translate (+ x (/ w 2)) (+ y (/ h 2))) - (unless ccw? - (send p reverse))) - (send path append p))))) + (define sweep + (let loop ([s (if ccw? + (- end start) + (- start end))]) + (if (< s 0) + (loop (+ s (* 2 pi))) + s))) + (if (> sweep pi) + (let ([halfway ((if ccw? + -) start (/ sweep 2))]) + (weighted-arc path x y w h start halfway ccw? dx1 dy1 dx2 dy2) + (weighted-arc path x y w h halfway end ccw? dx2 (- dy2) dx1 (- dy1))) + (let ([p (new dc-path%)]) + ;; Set p to be the arc for a unit circle, + ;; centered on the X-axis: + (let* ([x0 (cos (/ sweep 2))] + [y0 (sin (/ sweep 2))] + [x1 (/ (- 4 x0) 3)] + [y1 (/ (* (- 1 x0) (- 3 x0)) (* 3 y0))] + [x2 x1] + [y2 (- y1)] + [x3 x0] + [y3 (- y0)] + [sw (/ w 2)] + [sh (/ h 2)]) + (send p move-to x0 y0) + (send p curve-to (+ x1 dx1) (+ y1 dy1) (+ x2 dx2) (+ y2 dy2) x3 y3) + ;; Rotate to match start: + (send p rotate (+ (if ccw? start end) (/ sweep 2))) + ;; Scale to match width and height: + (send p scale (/ w 2) (/ h 2)) + ;; Translate to match x and y + (send p translate (+ x (/ w 2)) (+ y (/ h 2))) + (unless ccw? + (send p reverse))) + (send path append p)))) (define overall-rotation (- (* pi 1/2 3/8))) @@ -133,20 +138,15 @@ (+ big-fin-bottom-y 10))) (define (add-big-fin-bottom add) - (let ([fin-width (- big-fin-right-edge big-fin-bottom-x)]) - (add - (+ big-fin-bottom-x fin-width) - (+ big-fin-bottom-y 10) - - (+ big-fin-bottom-x (* 1/3 fin-width)) - (- (/ (+ big-fin-bottom-y big-fin-top-y) 2) - big-fin-curve-bottom-offset) - - (+ big-fin-bottom-x (* 1/5 fin-width)) - (/ (+ big-fin-bottom-y big-fin-top-y) 2) - - big-fin-bottom-x - big-fin-bottom-y))) + (define fin-width (- big-fin-right-edge big-fin-bottom-x)) + (add (+ big-fin-bottom-x fin-width) + (+ big-fin-bottom-y 10) + (+ big-fin-bottom-x (* 1/3 fin-width)) + (- (/ (+ big-fin-bottom-y big-fin-top-y) 2) big-fin-curve-bottom-offset) + (+ big-fin-bottom-x (* 1/5 fin-width)) + (/ (+ big-fin-bottom-y big-fin-top-y) 2) + big-fin-bottom-x + big-fin-bottom-y)) (define (add-little-fin-top add) (add diff --git a/drracket-core-lib/drracket/sprof.rkt b/drracket-core-lib/drracket/sprof.rkt index 695dce023..c5e3f21e4 100644 --- a/drracket-core-lib/drracket/sprof.rkt +++ b/drracket-core-lib/drracket/sprof.rkt @@ -160,9 +160,9 @@ (hash-set! line-to-source i pr) (insert (format-percentage (/ count denom-count))) (insert (format " ~a" (format-fn-name fn))) - (let ([after (last-position)]) - (when (equal? (car pr) clicked-srcloc-pr) - (set! clear-old-pr (highlight-range before after "NavajoWhite"))))) + (define after (last-position)) + (when (equal? (car pr) clicked-srcloc-pr) + (set! clear-old-pr (highlight-range before after "NavajoWhite")))) (loop (cdr prs) #f (+ i 1))])])) (lock #t) (end-edit-sequence) diff --git a/drracket/setup/plt-installer-unit.rkt b/drracket/setup/plt-installer-unit.rkt index a31eee5f8..aba9b2ca9 100644 --- a/drracket/setup/plt-installer-unit.rkt +++ b/drracket/setup/plt-installer-unit.rkt @@ -41,12 +41,10 @@ (sleep 0.2) ; kludge to allow f to appear first (end-busy-cursor) ;; do these strings ever appear? (should move to string-constants, if so) - (let ([d (get-directory - "Select the destination for unpacking" - frame)]) - (unless d - (printf ">>> Cancelled <<<\n")) - (begin-busy-cursor) - d)) + (define d (get-directory "Select the destination for unpacking" frame)) + (unless d + (printf ">>> Cancelled <<<\n")) + (begin-busy-cursor) + d) #:show-beginning-of-file? #t)) cleanup-thunk))) From 1e386a776a363229f21d3db188f2c9b326345c5a Mon Sep 17 00:00:00 2001 From: "resyntax-ci[bot]" <181813515+resyntax-ci[bot]@users.noreply.github.com> Date: Sun, 28 Sep 2025 00:14:23 +0000 Subject: [PATCH 2/7] Fix 1 occurrence of `for-each-to-for` This `for-each` operation can be replaced with a `for` loop. --- drracket-core-lib/drracket/sprof.rkt | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drracket-core-lib/drracket/sprof.rkt b/drracket-core-lib/drracket/sprof.rkt index c5e3f21e4..6245bdfd0 100644 --- a/drracket-core-lib/drracket/sprof.rkt +++ b/drracket-core-lib/drracket/sprof.rkt @@ -17,10 +17,8 @@ (define new-traces (map (λ (t) (continuation-mark-set->context (continuation-marks t))) (get-threads))) (for ([trace (in-list new-traces)]) - (for-each - (λ (line) - (hash-set! traces-table line (cons trace (hash-ref traces-table line '())))) - trace)) + (for ([line (in-list trace)]) + (hash-set! traces-table line (cons trace (hash-ref traces-table line '()))))) (cond [(zero? i) (update-gui traces-table) From fc086a834f46cab5dc9e292e9f7366fb536d289a Mon Sep 17 00:00:00 2001 From: "resyntax-ci[bot]" <181813515+resyntax-ci[bot]@users.noreply.github.com> Date: Sun, 28 Sep 2025 00:14:23 +0000 Subject: [PATCH 3/7] Fix 1 occurrence of `nested-when-to-compound-when` Nested `when` expressions can be merged into a single compound `when` expression. --- drracket/macro-debugger/tool.rkt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drracket/macro-debugger/tool.rkt b/drracket/macro-debugger/tool.rkt index 65fefede6..c9e6c9635 100644 --- a/drracket/macro-debugger/tool.rkt +++ b/drracket/macro-debugger/tool.rkt @@ -461,9 +461,9 @@ (define canvas (send obj get-canvas)) (when canvas (define frame (send canvas get-top-level-window)) - (when (is-a? frame frame/supports-macro-stepper<%>) - (when (send frame allow-macro-stepper?) - (send frame run-macro-stepper))))))) + (when (and (is-a? frame frame/supports-macro-stepper<%>) + (send frame allow-macro-stepper?)) + (send frame run-macro-stepper)))))) (send keymap map-function "c:c;c:m" "macro stepper")) (add-macro-stepper-key-bindings (drracket:rep:get-drs-bindings-keymap)) From daca2ac8df8996c625f5b8345c0fde298757fac3 Mon Sep 17 00:00:00 2001 From: "resyntax-ci[bot]" <181813515+resyntax-ci[bot]@users.noreply.github.com> Date: Sun, 28 Sep 2025 00:14:23 +0000 Subject: [PATCH 4/7] Fix 1 occurrence of `string-append-with-format-to-format` This `string-append` with `format` expression can be simplified to a single `format` call. --- drracket/help/private/bug-report-controls.rkt | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/drracket/help/private/bug-report-controls.rkt b/drracket/help/private/bug-report-controls.rkt index c673f0fb0..8084912b5 100644 --- a/drracket/help/private/bug-report-controls.rkt +++ b/drracket/help/private/bug-report-controls.rkt @@ -296,19 +296,15 @@ (cons (string->symbol (format "~a" (bri-label bri))) (bri-value bri))))) (define (get-environment) - (string-append (send environment get-value) - "\n" - (format "Human Language: ~a\n" (send human-language get-value)) - (format "(current-memory-use) ~a\n" (send memory-use get-value)) - (format "raco pkg (show):\n~a\n" (send (send pkg-info get-editor) get-text)) - "\n" - "\nCollections:\n" - (format "~a" (send (send collections get-editor) get-text)) - "\n" - (apply - string-append - (for/list ([extra (in-list extras)]) - (format "~a: ~a\n" (car extra) (send (cdr extra) get-value)))))) + (format "~a\n~a~a~a\n\nCollections:\n~a\n~a" + (send environment get-value) + (format "Human Language: ~a\n" (send human-language get-value)) + (format "(current-memory-use) ~a\n" (send memory-use get-value)) + (format "raco pkg (show):\n~a\n" (send (send pkg-info get-editor) get-text)) + (send (send collections get-editor) get-text) + (apply string-append + (for/list ([extra (in-list extras)]) + (format "~a: ~a\n" (car extra) (send (cdr extra) get-value)))))) (define (get-content canvas) (define t (send canvas get-editor)) From 93a56f16335afff85b98d38954c5a43f2c4aa541 Mon Sep 17 00:00:00 2001 From: "resyntax-ci[bot]" <181813515+resyntax-ci[bot]@users.noreply.github.com> Date: Sun, 28 Sep 2025 00:14:23 +0000 Subject: [PATCH 5/7] Fix 7 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. --- drracket-core-lib/browser/external.rkt | 77 ++++++++++++-------------- 1 file changed, 36 insertions(+), 41 deletions(-) diff --git a/drracket-core-lib/browser/external.rkt b/drracket-core-lib/browser/external.rkt index abc426e0e..0903c139e 100644 --- a/drracket-core-lib/browser/external.rkt +++ b/drracket-core-lib/browser/external.rkt @@ -166,30 +166,28 @@ (lambda (name browser) (try-put-preferences (list 'external-browser) (list browser))))) (letrec - ([v-panel (instantiate group-box-panel% () - [parent pref-panel] - [alignment '(right center)] - [stretchable-height #f] - [label (string-constant external-browser-choice-title)])] - [h-panel (instantiate horizontal-panel% () - [parent v-panel] - [alignment '(center bottom)])] + ([v-panel (new group-box-panel% + [parent pref-panel] + [alignment '(right center)] + [stretchable-height #f] + [label (string-constant external-browser-choice-title)])] + [h-panel (new horizontal-panel% [parent v-panel] [alignment '(center bottom)])] [none-index (length raw:unix-browser-list)] [custom-index (add1 none-index)] - [r (instantiate radio-box% () - [label #f] - [choices - (append unix-browser-names - (list (string-constant no-browser) - (string-constant browser-command-line-label)))] - [parent h-panel] - [callback - (lambda (radio event) - (let ([n (send radio get-selection)]) - (set-browser! (cond - [(= n none-index) #f] - [(= n custom-index) (get-custom)] - [else (list-ref raw:unix-browser-list n)]))))])] + [r (new radio-box% + [label #f] + [choices + (append unix-browser-names + (list (string-constant no-browser) + (string-constant browser-command-line-label)))] + [parent h-panel] + [callback + (lambda (radio event) + (let ([n (send radio get-selection)]) + (set-browser! (cond + [(= n none-index) #f] + [(= n custom-index) (get-custom)] + [else (list-ref raw:unix-browser-list n)]))))])] [select-custom (lambda (_ __) (send r set-selection custom-index) (set-browser! (get-custom)))] @@ -197,20 +195,17 @@ [template-panel (instantiate horizontal-panel% (h-panel) [spacing 0] [stretchable-height #f])] - [pre (instantiate text-field% () - [label #f] - [parent template-panel] - [callback select-custom] - [horiz-margin 0])] - [mess (instantiate message% () - [label ""] - [parent template-panel] - [horiz-margin 0])] - [post (instantiate text-field% () - [label #f] - [parent template-panel] - [callback select-custom] - [horiz-margin 0])] + [pre (new text-field% + [label #f] + [parent template-panel] + [callback select-custom] + [horiz-margin 0])] + [mess (new message% [label ""] [parent template-panel] [horiz-margin 0])] + [post (new text-field% + [label #f] + [parent template-panel] + [callback select-custom] + [horiz-margin 0])] [note1 (instantiate message% ((string-constant browser-cmdline-expl-line-1) v-panel))] [note2 (instantiate message% ((string-constant browser-cmdline-expl-line-2) v-panel))] [refresh-controls (lambda (pref) @@ -241,11 +236,11 @@ ;; -------------------- proxy for doc downloads -------------------- (when set-help? - (letrec ([p (instantiate group-box-panel% () - [label (string-constant http-proxy)] - [parent pref-panel] - [stretchable-height #f] - [alignment '(left top)])] + (letrec ([p (new group-box-panel% + [label (string-constant http-proxy)] + [parent pref-panel] + [stretchable-height #f] + [alignment '(left top)])] [rb (make-object radio-box% #f (list (string-constant proxy-direct-connection) From fb66a23aa79df668f9361c493b6427c6c3954b44 Mon Sep 17 00:00:00 2001 From: "resyntax-ci[bot]" <181813515+resyntax-ci[bot]@users.noreply.github.com> Date: Sun, 28 Sep 2025 00:14:23 +0000 Subject: [PATCH 6/7] Fix 2 occurrences of `instantiate-to-make-object` The `instantiate` form is for mixing positional and by-name constructor arguments. When no by-name arguments are needed, use `make-object` instead. --- drracket-core-lib/browser/external.rkt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drracket-core-lib/browser/external.rkt b/drracket-core-lib/browser/external.rkt index 0903c139e..370a563db 100644 --- a/drracket-core-lib/browser/external.rkt +++ b/drracket-core-lib/browser/external.rkt @@ -206,8 +206,8 @@ [parent template-panel] [callback select-custom] [horiz-margin 0])] - [note1 (instantiate message% ((string-constant browser-cmdline-expl-line-1) v-panel))] - [note2 (instantiate message% ((string-constant browser-cmdline-expl-line-2) v-panel))] + [note1 (make-object message% (string-constant browser-cmdline-expl-line-1) v-panel)] + [note2 (make-object message% (string-constant browser-cmdline-expl-line-2) v-panel)] [refresh-controls (lambda (pref) (if (pair? pref) (begin From da801d4e0512ca83c8d148a3e0d1a4166b0643c6 Mon Sep 17 00:00:00 2001 From: "resyntax-ci[bot]" <181813515+resyntax-ci[bot]@users.noreply.github.com> Date: Sun, 28 Sep 2025 00:14:23 +0000 Subject: [PATCH 7/7] Fix 2 occurrences of `if-begin-to-cond` Using `cond` instead of `if` here makes `begin` unnecessary --- drracket-core-lib/browser/external.rkt | 57 +++++++++++++------------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/drracket-core-lib/browser/external.rkt b/drracket-core-lib/browser/external.rkt index 370a563db..15da0c670 100644 --- a/drracket-core-lib/browser/external.rkt +++ b/drracket-core-lib/browser/external.rkt @@ -209,20 +209,21 @@ [note1 (make-object message% (string-constant browser-cmdline-expl-line-1) v-panel)] [note2 (make-object message% (string-constant browser-cmdline-expl-line-2) v-panel)] [refresh-controls (lambda (pref) - (if (pair? pref) - (begin - (send r set-selection custom-index) - (send pre set-value (car pref)) - (send post set-value (cdr pref))) - (let init ([x raw:unix-browser-list] - [n 0]) - (cond - [(null? x) (send r set-selection n)] - [else - (if (eq? pref (car x)) - (send r set-selection n) - (init (cdr x) - (add1 n)))]))))]) + (cond + [(pair? pref) + (send r set-selection custom-index) + (send pre set-value (car pref)) + (send post set-value (cdr pref))] + [else + (let init ([x raw:unix-browser-list] + [n 0]) + (cond + [(null? x) (send r set-selection n)] + [else + (if (eq? pref (car x)) + (send r set-selection n) + (init (cdr x) + (add1 n)))]))]))]) (unless ask-later? (send r enable none-index #f)) @@ -281,20 +282,20 @@ [bad-host (make-object message% (string-constant proxy-bad-host) p)] [update-gui (lambda (proxy-val) (send bad-host show #f) - (if proxy-val - (begin - (send rb set-selection 1) - (send proxy-spec enable #t) - (unless (string=? (cadr proxy-val) (send host get-value)) - (send host set-value (cadr proxy-val))) - (unless (equal? (caddr proxy-val) - (string->number (send port get-value))) - (send port set-value (number->string (caddr proxy-val))))) - (begin - (send rb set-selection 0) - (send proxy-spec enable #f) - (send host set-value "") - (send port set-value ""))))]) + (cond + [proxy-val + (send rb set-selection 1) + (send proxy-spec enable #t) + (unless (string=? (cadr proxy-val) (send host get-value)) + (send host set-value (cadr proxy-val))) + (unless (equal? (caddr proxy-val) + (string->number (send port get-value))) + (send port set-value (number->string (caddr proxy-val))))] + [else + (send rb set-selection 0) + (send proxy-spec enable #f) + (send host set-value "") + (send port set-value "")]))]) (fw:preferences:add-callback http-proxy-preference (lambda (name val) (update-gui val))) (update-gui (fw:preferences:get http-proxy-preference))