From e2b5861c305c7ae8a2f514e4c1ae6492c4f41727 Mon Sep 17 00:00:00 2001 From: "resyntax-ci[bot]" <181813515+resyntax-ci[bot]@users.noreply.github.com> Date: Wed, 29 Jan 2025 00:15:45 +0000 Subject: [PATCH 01/11] Fix 2 occurrences of `quasiquote-to-list` This quasiquotation is equialent to a simple `list` call. --- scribble-html-lib/scribble/html/html.rkt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scribble-html-lib/scribble/html/html.rkt b/scribble-html-lib/scribble/html/html.rkt index 9bd71e3f96..71f1b82977 100644 --- a/scribble-html-lib/scribble/html/html.rkt +++ b/scribble-html-lib/scribble/html/html.rkt @@ -186,11 +186,11 @@ (define-values [attrs body] (attributes+body args)) (make-element 'script attrs - `("\n" ,(set-prefix 0 (apply cdata #:line-prefix "//" body)) "\n"))) + (list "\n" (set-prefix 0 (apply cdata #:line-prefix "//" body)) "\n"))) (provide style/inline) (define (style/inline . args) (define-values [attrs body] (attributes+body args)) - (make-element 'style attrs `("\n" ,body "\n"))) + (make-element 'style attrs (list "\n" body "\n"))) ;; ---------------------------------------------------------------------------- ;; Entities From a83d25bca8542e3ec3b29b753a7388e6331abe3a Mon Sep 17 00:00:00 2001 From: "resyntax-ci[bot]" <181813515+resyntax-ci[bot]@users.noreply.github.com> Date: Wed, 29 Jan 2025 00:15:45 +0000 Subject: [PATCH 02/11] Fix 2 occurrences of `if-let-to-cond` `cond` with internal definitions is preferred over `if` with `let`, to reduce nesting --- scribble-lib/scriblib/gui-eval.rkt | 112 +++++++++--------- .../scribble/text/syntax-utils.rkt | 19 +-- 2 files changed, 67 insertions(+), 64 deletions(-) diff --git a/scribble-lib/scriblib/gui-eval.rkt b/scribble-lib/scriblib/gui-eval.rkt index 69b3ee3576..9a53cb13bb 100644 --- a/scribble-lib/scriblib/gui-eval.rkt +++ b/scribble-lib/scriblib/gui-eval.rkt @@ -68,61 +68,63 @@ "exprs.dat")) (define gui-eval-handler - (if mred? - (let ([eh (scribble-eval-handler)] - [log-file (open-output-file exprs-dat-file #:exists 'truncate/replace)]) - (λ (gui-eval get-predicate? get-render get-get-width get-get-height) - (lambda (ev catching-exns? expr) - (write (serialize (if (syntax? expr) (syntax->datum expr) expr)) log-file) - (newline log-file) - (flush-output log-file) - (let ([result - (with-handlers ([exn:fail? - (lambda (exn) - (make-gui-exn (exn-message exn)))]) - ;; put the call to fixup-picts in the handlers - ;; so that errors in the user-supplied predicates & - ;; conversion functions show up in the rendered output - (fixup-picts (get-predicate?) (get-render) (get-get-width) (get-get-height) - (eh ev catching-exns? expr)))]) - (write (serialize result) log-file) - (newline log-file) - (flush-output log-file) - (if (gui-exn? result) - (raise (make-exn:fail - (gui-exn-message result) - (current-continuation-marks))) - result))))) - (let ([log-file (with-handlers ([exn:fail:filesystem? - (lambda (exn) - (open-input-string ""))]) - (open-input-file exprs-dat-file))]) - (λ (gui-eval get-predicate? get-render get-get-width get-get-height) - (lambda (ev catching-exns? expr) - (with-handlers ([exn:fail? (lambda (exn) - (if catching-exns? - (raise exn) - (void)))]) - (let ([v (read log-file)]) - (if (eof-object? v) - (error "expression not in log file") - (let ([v (deserialize v)]) - (if (equal? v (if (syntax? expr) - (syntax->datum expr) - expr)) - (let ([v (read log-file)]) - (if (eof-object? v) - (error "expression result missing in log file") - (let ([v (deserialize v)]) - (if (gui-exn? v) - (raise (make-exn:fail - (gui-exn-message v) - (current-continuation-marks))) - v)))) - (error 'mreval - "expression does not match log file: ~e versus: ~e" - expr - v))))))))))) + (cond + [mred? + (define eh (scribble-eval-handler)) + (define log-file (open-output-file exprs-dat-file #:exists 'truncate/replace)) + (λ (gui-eval get-predicate? get-render get-get-width get-get-height) + (lambda (ev catching-exns? expr) + (write (serialize (if (syntax? expr) + (syntax->datum expr) + expr)) + log-file) + (newline log-file) + (flush-output log-file) + (let ([result (with-handlers ([exn:fail? (lambda (exn) (make-gui-exn (exn-message exn)))]) + ;; put the call to fixup-picts in the handlers + ;; so that errors in the user-supplied predicates & + ;; conversion functions show up in the rendered output + (fixup-picts (get-predicate?) + (get-render) + (get-get-width) + (get-get-height) + (eh ev catching-exns? expr)))]) + (write (serialize result) log-file) + (newline log-file) + (flush-output log-file) + (if (gui-exn? result) + (raise (make-exn:fail (gui-exn-message result) (current-continuation-marks))) + result))))] + [else + (define log-file + (with-handlers ([exn:fail:filesystem? (lambda (exn) (open-input-string ""))]) + (open-input-file exprs-dat-file))) + (λ (gui-eval get-predicate? get-render get-get-width get-get-height) + (lambda (ev catching-exns? expr) + (with-handlers ([exn:fail? (lambda (exn) + (if catching-exns? + (raise exn) + (void)))]) + (let ([v (read log-file)]) + (if (eof-object? v) + (error "expression not in log file") + (let ([v (deserialize v)]) + (if (equal? v + (if (syntax? expr) + (syntax->datum expr) + expr)) + (let ([v (read log-file)]) + (if (eof-object? v) + (error "expression result missing in log file") + (let ([v (deserialize v)]) + (if (gui-exn? v) + (raise (make-exn:fail (gui-exn-message v) + (current-continuation-marks))) + v)))) + (error 'mreval + "expression does not match log file: ~e versus: ~e" + expr + v))))))))])) (define image-counter 0) diff --git a/scribble-text-lib/scribble/text/syntax-utils.rkt b/scribble-text-lib/scribble/text/syntax-utils.rkt index 0577c13783..cb62197666 100644 --- a/scribble-text-lib/scribble/text/syntax-utils.rkt +++ b/scribble-text-lib/scribble/text/syntax-utils.rkt @@ -145,15 +145,16 @@ (loop (append (syntax->list #'(x ...)) (cdr exprs)) ds es)] [(define-syntaxes (id ...) rhs) (andmap identifier? (syntax->list #'(id ...))) - (if (null? es) - (let ([ids (syntax->list #'(id ...))]) - (syntax-local-bind-syntaxes ids - (local-transformer-expand #'rhs 'expression '()) - (car ctx)) - (loop (cdr exprs) (cons (rebuild-bindings) ds) es)) - ;; return the unexpanded expr, to be re-expanded later, in the - ;; right contexts - (values (reverse ds) (reverse es) exprs))] + (cond + [(null? es) + (define ids (syntax->list #'(id ...))) + (syntax-local-bind-syntaxes ids + (local-transformer-expand #'rhs 'expression '()) + (car ctx)) + (loop (cdr exprs) (cons (rebuild-bindings) ds) es)] + ;; return the unexpanded expr, to be re-expanded later, in the + ;; right contexts + [else (values (reverse ds) (reverse es) exprs)])] [(define-values (id ...) rhs) (andmap identifier? (syntax->list #'(id ...))) (if (null? es) From 08ac0cdac4f27cdd98df4b29acd184e3d9467af8 Mon Sep 17 00:00:00 2001 From: "resyntax-ci[bot]" <181813515+resyntax-ci[bot]@users.noreply.github.com> Date: Wed, 29 Jan 2025 00:15:45 +0000 Subject: [PATCH 03/11] Fix 4 occurrences of `if-begin-to-cond` Using `cond` instead of `if` here makes `begin` unnecessary --- scribble-html-lib/scribble/html/resource.rkt | 39 ++++++++++--------- scribble-text-lib/scribble/text/output.rkt | 11 +++--- .../scribble/text/syntax-utils.rkt | 12 +++--- 3 files changed, 33 insertions(+), 29 deletions(-) diff --git a/scribble-html-lib/scribble/html/resource.rkt b/scribble-html-lib/scribble/html/resource.rkt index 454ff63393..67c8780754 100644 --- a/scribble-html-lib/scribble/html/resource.rkt +++ b/scribble-html-lib/scribble/html/resource.rkt @@ -165,9 +165,11 @@ (define t (make-hash)) (define-syntax-rule (S body) (call-with-semaphore s (lambda () body))) (values (lambda (path renderer) - (S (if (hash-ref t path #f) - (error 'resource "path used for two resources: ~e" path) - (begin (hash-set! t path #t) (set! l (cons renderer l)))))) + (S (cond + [(hash-ref t path #f) (error 'resource "path used for two resources: ~e" path)] + [else + (hash-set! t path #t) + (set! l (cons renderer l))]))) (lambda () (S (begin0 (reverse l) (set! l '()))))))) ;; `#:exists' determines what happens when the render destination exists, it @@ -191,21 +193,22 @@ (values l (car r)))) (define (render) (let loop ([ps dirpathlist]) - (if (pair? ps) - (begin (unless (directory-exists? (car ps)) - (if (or (file-exists? (car ps)) (link-exists? (car ps))) - (bad "exists as a file/link") - (make-directory (car ps)))) - (parameterize ([current-directory (car ps)]) - (loop (cdr ps)))) - (begin (cond [(not exists)] ; do nothing - [(or (file-exists? filename) (link-exists? filename)) - (delete-file filename)] - [(directory-exists? filename) - (bad "exists as directory")]) - (parameterize ([rendered-dirpath dirpathlist]) - (printf " ~a\n" path) - (renderer filename)))))) + (cond + [(pair? ps) + (unless (directory-exists? (car ps)) + (if (or (file-exists? (car ps)) (link-exists? (car ps))) + (bad "exists as a file/link") + (make-directory (car ps)))) + (parameterize ([current-directory (car ps)]) + (loop (cdr ps)))] + [else + (cond + [(not exists)] ; do nothing + [(or (file-exists? filename) (link-exists? filename)) (delete-file filename)] + [(directory-exists? filename) (bad "exists as directory")]) + (parameterize ([rendered-dirpath dirpathlist]) + (printf " ~a\n" path) + (renderer filename))]))) (define absolute-url (lazy (define url (relativize filename dirpathlist '())) (if (url-roots) diff --git a/scribble-text-lib/scribble/text/output.rkt b/scribble-text-lib/scribble/text/output.rkt index 027034b023..65bd3a244c 100644 --- a/scribble-text-lib/scribble/text/output.rkt +++ b/scribble-text-lib/scribble/text/output.rkt @@ -112,11 +112,12 @@ (cond [(pair? nls) (define nl (car nls)) - (if (regexp-match? #rx"^ *$" x start (car nl)) - (newline p) ; only spaces before the end of the line - (begin - (output-pfx col pfx lpfx) - (write x p start (cdr nl)))) + (cond + [(regexp-match? #rx"^ *$" x start (car nl)) + (newline p)] ; only spaces before the end of the line + [else + (output-pfx col pfx lpfx) + (write x p start (cdr nl))]) (loop (cdr nl) (cdr nls) 0 0)] ;; last substring from here (always set lpfx state when done) [(start . = . len) (set-mcdr! pfxs lpfx)] diff --git a/scribble-text-lib/scribble/text/syntax-utils.rkt b/scribble-text-lib/scribble/text/syntax-utils.rkt index cb62197666..955ff8c1f7 100644 --- a/scribble-text-lib/scribble/text/syntax-utils.rkt +++ b/scribble-text-lib/scribble/text/syntax-utils.rkt @@ -157,12 +157,12 @@ [else (values (reverse ds) (reverse es) exprs)])] [(define-values (id ...) rhs) (andmap identifier? (syntax->list #'(id ...))) - (if (null? es) - (begin - (syntax-local-bind-syntaxes (syntax->list #'(id ...)) #f (car ctx)) - (loop (cdr exprs) (cons (rebuild-bindings) ds) es)) - ;; same note here - (values (reverse ds) (reverse es) exprs))] + (cond + [(null? es) + (syntax-local-bind-syntaxes (syntax->list #'(id ...)) #f (car ctx)) + (loop (cdr exprs) (cons (rebuild-bindings) ds) es)] + ;; same note here + [else (values (reverse ds) (reverse es) exprs)])] [_ (loop (cdr exprs) ds (cons expr* es))])]))) (define-syntax (begin/collect* stx) ; helper, has a boolean flag first (define-values [exprs always-list?] From fc7aac70b1a22e64ce3ff0c5b504a95e34ac857c Mon Sep 17 00:00:00 2001 From: "resyntax-ci[bot]" <181813515+resyntax-ci[bot]@users.noreply.github.com> Date: Wed, 29 Jan 2025 00:15:45 +0000 Subject: [PATCH 04/11] Fix 3 occurrences of `map-to-for` This `map` operation can be replaced with a `for/list` loop. --- scribble-html-lib/scribble/html/resource.rkt | 9 ++++----- scribble-html-lib/scribble/html/xml.rkt | 18 ++++++++---------- scribble-lib/scriblib/footnote.rkt | 7 ++----- 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/scribble-html-lib/scribble/html/resource.rkt b/scribble-html-lib/scribble/html/resource.rkt index 67c8780754..db856af10d 100644 --- a/scribble-html-lib/scribble/html/resource.rkt +++ b/scribble-html-lib/scribble/html/resource.rkt @@ -57,11 +57,10 @@ (set! cached-roots (cons roots (and (list? roots) (pair? roots) - (map (lambda (root) - (list* (regexp-match* #rx"[^/]+" (car root)) - (regexp-replace #rx"/$" (cadr root) "") - (cddr root))) - roots))))) + (for/list ([root (in-list roots)]) + (list* (regexp-match* #rx"[^/]+" (car root)) + (regexp-replace #rx"/$" (cadr root) "") + (cddr root))))))) (cdr cached-roots)) ;; a utility for relative paths, taking the above `default-file' and diff --git a/scribble-html-lib/scribble/html/xml.rkt b/scribble-html-lib/scribble/html/xml.rkt index 6e4f416f96..51fa3b3ed3 100644 --- a/scribble-html-lib/scribble/html/xml.rkt +++ b/scribble-html-lib/scribble/html/xml.rkt @@ -106,16 +106,14 @@ ;; null body means a lone tag, tags that should always have a closer will ;; have a '(#f) as their body (see below) (list (with-writer #f "<" tag) - (map (lambda (attr) - (define name (car attr)) - (define val (cdr attr)) - (cond [(not val) #f] - ;; #t means just mention the attribute - [(eq? #t val) (with-writer #f (list " " name))] - [else (list (with-writer #f (list " " name "=\"")) - val - (with-writer #f "\""))])) - attrs) + (for/list ([attr (in-list attrs)]) + (define name (car attr)) + (define val (cdr attr)) + (cond + [(not val) #f] + ;; #t means just mention the attribute + [(eq? #t val) (with-writer #f (list " " name))] + [else (list (with-writer #f (list " " name "=\"")) val (with-writer #f "\""))])) (if (null? body) (with-writer #f " />") (list (with-writer #f ">") diff --git a/scribble-lib/scriblib/footnote.rkt b/scribble-lib/scriblib/footnote.rkt index c40ad6972f..2155e8860f 100644 --- a/scribble-lib/scriblib/footnote.rkt +++ b/scribble-lib/scriblib/footnote.rkt @@ -78,9 +78,6 @@ (lambda (get set) (make-compound-paragraph footnote-block-style - (map (lambda (content) - (make-paragraph - footnote-block-content-style - content)) - (reverse (get id null))))))) + (for/list ([content (in-list (reverse (get id null)))]) + (make-paragraph footnote-block-content-style content)))))) null)) From 5ce259e0099017e869574036644590f927d54b05 Mon Sep 17 00:00:00 2001 From: "resyntax-ci[bot]" <181813515+resyntax-ci[bot]@users.noreply.github.com> Date: Wed, 29 Jan 2025 00:15:45 +0000 Subject: [PATCH 05/11] Fix 1 occurrence of `define-syntax-syntax-rules-to-define-syntax-rule` This `define-syntax` macro can be replaced with a simpler, equivalent `define-syntax-rule` macro. --- scribble-lib/scriblib/gui-eval.rkt | 42 ++++++++++++++---------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/scribble-lib/scriblib/gui-eval.rkt b/scribble-lib/scriblib/gui-eval.rkt index 9a53cb13bb..631cf0f13f 100644 --- a/scribble-lib/scriblib/gui-eval.rkt +++ b/scribble-lib/scriblib/gui-eval.rkt @@ -12,28 +12,26 @@ racket/sandbox (for-syntax racket/base)) -(define-syntax define-mr - (syntax-rules () - [(_ mr orig) - (begin - (provide mr) - (define-syntax (mr stx) - (syntax-case stx () - [(_ #:eval+opts the-eval get-predicate? get-render get-get-width get-get-height x (... ...)) - #'(let ([the-eval-x the-eval]) - (parameterize ([scribble-eval-handler (gui-eval-handler the-eval-x - get-predicate? - get-render - get-get-width - get-get-height)]) - (orig #:eval the-eval-x x (... ...))))] - [(_ x (... ...)) - #'(parameterize ([scribble-eval-handler (gui-eval-handler gui-eval - (λ () (gui-eval 'pict?)) - (λ () (gui-eval 'draw-pict)) - (λ () (gui-eval 'pict-width)) - (λ () (gui-eval 'pict-height)))]) - (orig #:eval gui-eval x (... ...)))])))])) +(define-syntax-rule (define-mr mr orig) + (begin + (provide mr) + (define-syntax (mr stx) + (syntax-case stx () + [(_ #:eval+opts the-eval get-predicate? get-render get-get-width get-get-height x (... ...)) + #'(let ([the-eval-x the-eval]) + (parameterize ([scribble-eval-handler (gui-eval-handler the-eval-x + get-predicate? + get-render + get-get-width + get-get-height)]) + (orig #:eval the-eval-x x (... ...))))] + [(_ x (... ...)) + #'(parameterize ([scribble-eval-handler (gui-eval-handler gui-eval + (λ () (gui-eval 'pict?)) + (λ () (gui-eval 'draw-pict)) + (λ () (gui-eval 'pict-width)) + (λ () (gui-eval 'pict-height)))]) + (orig #:eval gui-eval x (... ...)))])))) (define gui-eval (make-base-eval #:pretty-print? #f)) From 5b7103e78106104dffc3b65b106b962a73c16a30 Mon Sep 17 00:00:00 2001 From: "resyntax-ci[bot]" <181813515+resyntax-ci[bot]@users.noreply.github.com> Date: Wed, 29 Jan 2025 00:15:45 +0000 Subject: [PATCH 06/11] Fix 1 occurrence of `cond-let-to-cond-define` Internal definitions are recommended instead of `let` expressions, to reduce nesting. --- scribble-lib/scriblib/gui-eval.rkt | 67 +++++++++++++++--------------- 1 file changed, 33 insertions(+), 34 deletions(-) diff --git a/scribble-lib/scriblib/gui-eval.rkt b/scribble-lib/scriblib/gui-eval.rkt index 631cf0f13f..1bd6567aaf 100644 --- a/scribble-lib/scriblib/gui-eval.rkt +++ b/scribble-lib/scriblib/gui-eval.rkt @@ -133,41 +133,40 @@ (let loop ([v v]) (cond [(predicate? v) - (let ([fn (build-string-path img-dir - (format "img~a.png" image-counter))]) - (set! image-counter (add1 image-counter)) - (let ([dc (let ([pss (make-object (gui-eval 'ps-setup%))]) - (send pss set-mode 'file) - (send pss set-file (path-replace-suffix fn #".pdf")) - (parameterize ([(gui-eval 'current-ps-setup) pss]) - (let ([xb (box 0)] - [yb (box 0)]) - (send pss get-scaling xb yb) - (new (gui-eval 'pdf-dc%) - [interactive #f] - [width (* (unbox xb) (get-width v))] - [height (* (unbox yb) (get-height v))]))))]) - (send dc start-doc "Image") - (send dc start-page) - (render v dc 0 0) - (send dc end-page) - (send dc end-doc)) - (let* ([bm (make-object (gui-eval 'bitmap%) + (define fn (build-string-path img-dir (format "img~a.png" image-counter))) + (set! image-counter (add1 image-counter)) + (let ([dc (let ([pss (make-object (gui-eval 'ps-setup%))]) + (send pss set-mode 'file) + (send pss set-file (path-replace-suffix fn #".pdf")) + (parameterize ([(gui-eval 'current-ps-setup) pss]) + (let ([xb (box 0)] + [yb (box 0)]) + (send pss get-scaling xb yb) + (new (gui-eval 'pdf-dc%) + [interactive #f] + [width (* (unbox xb) (get-width v))] + [height (* (unbox yb) (get-height v))]))))]) + (send dc start-doc "Image") + (send dc start-page) + (render v dc 0 0) + (send dc end-page) + (send dc end-doc)) + (define bm + (make-object (gui-eval 'bitmap%) (inexact->exact (ceiling (get-width v))) - (inexact->exact (ceiling (get-height v))))] - [dc (make-object (gui-eval 'bitmap-dc%) bm)]) - (send dc set-smoothing 'aligned) - (send dc clear) - (render v dc 0 0) - (send bm save-file fn 'png) - (make-image-element - #f - (list "[image]") - ;; Be sure to use a string rather than a path, because - ;; it gets recorded in "exprs.dat". - (path->string (path-replace-suffix fn #"")) - '(".pdf" ".png") - 1.0)))] + (inexact->exact (ceiling (get-height v))))) + (define dc (make-object (gui-eval 'bitmap-dc%) bm)) + (send dc set-smoothing 'aligned) + (send dc clear) + (render v dc 0 0) + (send bm save-file fn 'png) + (make-image-element #f + (list "[image]") + ;; Be sure to use a string rather than a path, because + ;; it gets recorded in "exprs.dat". + (path->string (path-replace-suffix fn #"")) + '(".pdf" ".png") + 1.0)] [(pair? v) (cons (loop (car v)) (loop (cdr v)))] [(serializable? v) v] From 2b06c340f15e6140cccbff656ea09baa36ac5122 Mon Sep 17 00:00:00 2001 From: "resyntax-ci[bot]" <181813515+resyntax-ci[bot]@users.noreply.github.com> Date: Wed, 29 Jan 2025 00:15:45 +0000 Subject: [PATCH 07/11] Fix 1 occurrence of `ormap-to-for/or` This `ormap` operation can be replaced with a `for/or` loop. --- scribble-html-lib/scribble/html/resource.rkt | 33 ++++++++++---------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/scribble-html-lib/scribble/html/resource.rkt b/scribble-html-lib/scribble/html/resource.rkt index db856af10d..7adbebd716 100644 --- a/scribble-html-lib/scribble/html/resource.rkt +++ b/scribble-html-lib/scribble/html/resource.rkt @@ -69,22 +69,23 @@ (define file* (if (equal? file default-file) "" file)) (define roots (current-url-roots)) (define (find-root path mode) - (ormap (lambda (root+url+flags) - (let loop ([r (car root+url+flags)] [p path]) - (if (pair? r) - (and (pair? p) (equal? (car p) (car r)) - (loop (cdr r) (cdr p))) - (case mode - [(get-path) `(,(cadr root+url+flags) - ,@p - ,(if (and (equal? file* "") - (memq 'index (cddr root+url+flags))) - default-file - file*))] - [(get-abs-or-true) - (if (memq 'abs (cddr root+url+flags)) `("" ,@p) #t)] - [else (error 'relativize "internal error: ~e" mode)])))) - roots)) + (for/or ([root+url+flags (in-list roots)]) + (let loop ([r (car root+url+flags)] + [p path]) + (if (pair? r) + (and (pair? p) (equal? (car p) (car r)) (loop (cdr r) (cdr p))) + (case mode + [(get-path) + `(,(cadr root+url+flags) ,@p + ,(if (and (equal? file* "") + (memq 'index (cddr root+url+flags))) + default-file + file*))] + [(get-abs-or-true) + (if (memq 'abs (cddr root+url+flags)) + `("" ,@p) + #t)] + [else (error 'relativize "internal error: ~e" mode)]))))) (define result (let loop ([t tgtdir] [c curdir] [pfx '()]) (cond From 141b90e447efb9c79414ee444b37ea7c91642829 Mon Sep 17 00:00:00 2001 From: "resyntax-ci[bot]" <181813515+resyntax-ci[bot]@users.noreply.github.com> Date: Wed, 29 Jan 2025 00:15:45 +0000 Subject: [PATCH 08/11] Fix 1 occurrence of `when-expression-in-for-loop-to-when-keyword` Use the `#:when` keyword instead of `when` to reduce loop body indentation. --- scribble-html-lib/scribble/html/resource.rkt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scribble-html-lib/scribble/html/resource.rkt b/scribble-html-lib/scribble/html/resource.rkt index 7adbebd716..8923f7c00c 100644 --- a/scribble-html-lib/scribble/html/resource.rkt +++ b/scribble-html-lib/scribble/html/resource.rkt @@ -182,11 +182,11 @@ (define (resource path0 renderer #:exists [exists 'delete-file]) (define (bad reason) (error 'resource "bad path, ~a: ~e" reason path0)) (unless (string? path0) (bad "must be a string")) - (for ([x (in-list '([#rx"^/" "must be relative"] - [#rx"//" "must not have empty elements"] - [#rx"(?:^|/)[.][.]?(?:/|$)" - "must not contain `.' or `..'"]))]) - (when (regexp-match? (car x) path0) (bad (cadr x)))) + (for ([x (in-list '([#rx"^/" "must be relative"] [#rx"//" "must not have empty elements"] + [#rx"(?:^|/)[.][.]?(?:/|$)" + "must not contain `.' or `..'"]))] + #:when (regexp-match? (car x) path0)) + (bad (cadr x))) (define path (regexp-replace #rx"(?<=^|/)$" path0 default-file)) (define-values [dirpathlist filename] (let-values ([(l r) (split-at-right (regexp-split #rx"/" path) 1)]) From 1177eca584eb560b55203c93d2512be3ca24df46 Mon Sep 17 00:00:00 2001 From: "resyntax-ci[bot]" <181813515+resyntax-ci[bot]@users.noreply.github.com> Date: Wed, 29 Jan 2025 00:15:45 +0000 Subject: [PATCH 09/11] Fix 3 occurrences of `let-to-define` Internal definitions are recommended instead of `let` expressions, to reduce nesting. --- .../scribblings/scribble/class-diagrams.rkt | 116 ++++++++---------- scribble-lib/scriblib/footnote.rkt | 32 ++--- 2 files changed, 64 insertions(+), 84 deletions(-) diff --git a/scribble-doc/scribblings/scribble/class-diagrams.rkt b/scribble-doc/scribblings/scribble/class-diagrams.rkt index 5f13dff7e6..ed5d4804a8 100644 --- a/scribble-doc/scribblings/scribble/class-diagrams.rkt +++ b/scribble-doc/scribblings/scribble/class-diagrams.rkt @@ -70,41 +70,32 @@ (unless (even? (length args)) (error 'method-spec "expected a list of types and argument names, but found ~a arguments" (length args))) - (let ([first-line - (hbl-append - (type-spec range) - (normal-font " ") - (var-font name) - (cond - [(null? args) - (normal-font "()")] - [else - (hbl-append - (normal-font "(") - (let loop ([args args]) - (let* ([type (car args)] - [param (cadr args)] - [single-arg - (if param - (hbl-append (type-spec type) - (normal-font " ") - (var-font param)) - (type-spec type))]) - - (cond - [(null? (cddr args)) - (hbl-append single-arg (normal-font ")"))] - [else - (hbl-append single-arg - (normal-font ", ") - (loop (cddr args)))]))))]) - (if body - (hbl-append (normal-font " {")) - (blank)))]) - (if body - (vl-append first-line - (hbl-append (blank 8 0) body (normal-font "}"))) - first-line))) + (define first-line + (hbl-append + (type-spec range) + (normal-font " ") + (var-font name) + (cond + [(null? args) (normal-font "()")] + [else + (hbl-append + (normal-font "(") + (let loop ([args args]) + (let* ([type (car args)] + [param (cadr args)] + [single-arg (if param + (hbl-append (type-spec type) (normal-font " ") (var-font param)) + (type-spec type))]) + + (cond + [(null? (cddr args)) (hbl-append single-arg (normal-font ")"))] + [else (hbl-append single-arg (normal-font ", ") (loop (cddr args)))]))))]) + (if body + (hbl-append (normal-font " {")) + (blank)))) + (if body + (vl-append first-line (hbl-append (blank 8 0) body (normal-font "}"))) + first-line)) (define (type-spec str) (cond @@ -126,35 +117,32 @@ ;; class-box : pict (or/c #f (listof pict)) (or/c #f (listof pict)) -> pict (define (class-box name fields methods) - (let* ([mk-blank (λ () (blank 0 (+ class-box-margin class-box-margin)))]) - (cond - [(and methods fields) - (let* ([top-spacer (mk-blank)] - [bottom-spacer (mk-blank)] - [main (vl-append name - top-spacer - (if (null? fields) - (blank 0 4) - (apply vl-append fields)) - bottom-spacer - (if (null? methods) - (blank 0 4) - (apply vl-append methods)))]) - (add-hline - (add-hline (frame (inset main class-box-margin)) - top-spacer) - bottom-spacer))] - [fields - (let* ([top-spacer (mk-blank)] - [main (vl-append name - top-spacer - (if (null? fields) - (blank) - (apply vl-append fields)))]) - (add-hline (frame (inset main class-box-margin)) - top-spacer))] - [methods (class-box name methods fields)] - [else (frame (inset name class-box-margin))]))) + (define (mk-blank) + (blank 0 (+ class-box-margin class-box-margin))) + (cond + [(and methods fields) + (let* ([top-spacer (mk-blank)] + [bottom-spacer (mk-blank)] + [main (vl-append name + top-spacer + (if (null? fields) + (blank 0 4) + (apply vl-append fields)) + bottom-spacer + (if (null? methods) + (blank 0 4) + (apply vl-append methods)))]) + (add-hline (add-hline (frame (inset main class-box-margin)) top-spacer) bottom-spacer))] + [fields + (let* ([top-spacer (mk-blank)] + [main (vl-append name + top-spacer + (if (null? fields) + (blank) + (apply vl-append fields)))]) + (add-hline (frame (inset main class-box-margin)) top-spacer))] + [methods (class-box name methods fields)] + [else (frame (inset name class-box-margin))])) (define (add-hline main sub) (let-values ([(x y) (cc-find main sub)]) diff --git a/scribble-lib/scriblib/footnote.rkt b/scribble-lib/scriblib/footnote.rkt index 2155e8860f..8da1d229dc 100644 --- a/scribble-lib/scriblib/footnote.rkt +++ b/scribble-lib/scriblib/footnote.rkt @@ -44,27 +44,19 @@ (define (footnote-part . text) (do-footnote-part footnotes id)))) (define (do-footnote footnotes id text) - (let ([tag (generated-tag)] - [content (decode-content text)]) - (make-traverse-element - (lambda (get set) - (set id (cons (cons - (make-element footnote-target-style - (make-element - 'superscript - (counter-target footnotes tag #f))) + (define tag (generated-tag)) + (define content (decode-content text)) + (make-traverse-element + (lambda (get set) + (set id + (cons (cons (make-element footnote-target-style + (make-element 'superscript (counter-target footnotes tag #f))) content) - (get id null))) - (make-element footnote-style - (list - (make-element - footnote-ref-style - (make-element - 'superscript - (counter-ref footnotes tag #f))) - (make-element - footnote-content-style - content))))))) + (get id null))) + (make-element footnote-style + (list (make-element footnote-ref-style + (make-element 'superscript (counter-ref footnotes tag #f))) + (make-element footnote-content-style content)))))) (define (do-footnote-part footnotes id) (make-part From 27e08dc3ca025eec9b5822aea74b95ed4a290dad Mon Sep 17 00:00:00 2001 From: "resyntax-ci[bot]" <181813515+resyntax-ci[bot]@users.noreply.github.com> Date: Wed, 29 Jan 2025 00:15:45 +0000 Subject: [PATCH 10/11] Fix 1 occurrence of `quasiquote-to-append` This quasiquotation is equialent to calling `append`. --- scribble-lib/scribble/lp/lang/common.rkt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scribble-lib/scribble/lp/lang/common.rkt b/scribble-lib/scribble/lp/lang/common.rkt index 266e5c3589..396655a97b 100644 --- a/scribble-lib/scribble/lp/lang/common.rkt +++ b/scribble-lib/scribble/lp/lang/common.rkt @@ -24,7 +24,7 @@ (cons id (mapping-get chunk-groups id))) (free-identifier-mapping-put! chunks id - `(,@(mapping-get chunks id) ,@exprs)))) + (append (mapping-get chunks id) exprs)))) (define-syntax (tangle stx) (define chunk-mentions '()) From 2b59889a71be44f231e1765f3114e8c5784a72e4 Mon Sep 17 00:00:00 2001 From: "resyntax-ci[bot]" <181813515+resyntax-ci[bot]@users.noreply.github.com> Date: Wed, 29 Jan 2025 00:15:45 +0000 Subject: [PATCH 11/11] Fix 1 occurrence of `or-hash-ref-set!-to-hash-ref!` This expression can be replaced with a simpler, equivalent `hash-ref!` expression. --- scribble-text-lib/scribble/text/output.rkt | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/scribble-text-lib/scribble/text/output.rkt b/scribble-text-lib/scribble/text/output.rkt index 65bd3a244c..d2480f4034 100644 --- a/scribble-text-lib/scribble/text/output.rkt +++ b/scribble-text-lib/scribble/text/output.rkt @@ -280,10 +280,7 @@ [(eq? p (car last)) (cdr last)] [else (define s - (or (hash-ref t p #f) - (let ([s (mcons 0 0)]) - (hash-set! t p s) - s))) + (hash-ref! t p (λ () (mcons 0 0)))) (set! last (cons p s)) s]))))