Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions test.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#lang racket/base


(define (distance x1 y1 x2 y2)
(let ([dx (- x1 x2)]
[dy (- y1 y2)])
(sqrt (+ (* dx dx) (* dy dy)))))
Comment on lines +4 to +7

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let-to-define Internal definitions are recommended instead of let expressions, to reduce nesting.

Suggested change
(define (distance x1 y1 x2 y2)
(let ([dx (- x1 x2)]
[dy (- y1 y2)])
(sqrt (+ (* dx dx) (* dy dy)))))
(define (distance x1 y1 x2 y2)
(define dx (- x1 x2))
(define dy (- y1 y2))
(sqrt (+ (* dx dx) (* dy dy))))

Debugging details below:

Textual replacement
(line-replacement
  #:new-lines
    '#("(define (distance x1 y1 x2 y2)"
       "  (define dx (- x1 x2))"
       "  (define dy (- y1 y2))"
       "  (sqrt (+ (* dx dx) (* dy dy))))")
  #:original-lines
    '#("(define (distance x1 y1 x2 y2)"
       "  (let ([dx (- x1 x2)]"
       "        [dy (- y1 y2)])"
       "    (sqrt (+ (* dx dx) (* dy dy)))))")
  #:start-line 4)
Syntactic replacement
(syntax-replacement
  #:new-syntax
    #<syntax:/home/runner/.local/share/racket/8.5/pkgs/resyntax/default-recommendations/let-binding-suggestions.rkt:44:3 (define (distance x1 y1 x2 y2) NEWLINE (define dx (- x1 x2)) NEWLINE (define dy (- y1 y2)) NEWLINE (sqrt (+ (* dx dx) (* dy dy))))>
  #:original-syntax
    #<syntax:test.rkt:4:0 (define (distance x1 y1 x2 y2) (let ((dx (- x1 x2)) (dy (- y1 y2))) (sqrt (+ (* dx dx) (* dy dy)))))>)



(or 1 (or 2 3))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nested-or-to-flat-or Nested or expressions can be flattened to a single, equivalent or expression.

Suggested change
(or 1 (or 2 3))
(or 1 2 3)

Debugging details below:

Textual replacement
(line-replacement
  #:new-lines '#("(or 1 2 3)")
  #:original-lines '#("(or 1 (or 2 3))")
  #:start-line 10)
Syntactic replacement
(syntax-replacement
  #:new-syntax
    #<syntax:/home/runner/.local/share/racket/8.5/pkgs/resyntax/default-recommendations/boolean-shortcuts.rkt:34:3 (or 1 2 3)>
  #:original-syntax #<syntax:test.rkt:10:0 (or 1 (or 2 3))>)



(if 'cond 'then (if 'cond2 'then2 'else))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nested-if-to-cond This if-else chain can be converted to a cond expression.

Suggested change
(if 'cond 'then (if 'cond2 'then2 'else))
(cond
['cond 'then]
['cond2 'then2]
[else 'else])

Debugging details below:

Textual replacement
(line-replacement
  #:new-lines
    '#("(cond" "  ['cond 'then]" "  ['cond2 'then2]" "  [else 'else])")
  #:original-lines '#("(if 'cond 'then (if 'cond2 'then2 'else))")
  #:start-line 13)
Syntactic replacement
(syntax-replacement
  #:new-syntax
    #<syntax:/home/runner/.local/share/racket/8.5/pkgs/resyntax/default-recommendations/conditional-shortcuts.rkt:45:3 (cond NEWLINE ((quote cond) (quote then)) NEWLINE ((quote cond2) (quote then2)) NEWLINE (else (quote else)))>
  #:original-syntax
    #<syntax:test.rkt:13:0 (if (quote cond) (quote then) (if (quote cond2) (quote then2) (quote else)))>)



(if 'a
(println "true branch")
#f)
Comment on lines +16 to +18

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if-else-false-to-and This if expression can be refactored to an equivalent expression using and.

Suggested change
(if 'a
(println "true branch")
#f)
(and 'a
(println "true branch"))

Debugging details below:

Textual replacement
(line-replacement
  #:new-lines '#("(and 'a" "     (println \"true branch\"))")
  #:original-lines '#("(if 'a" "    (println \"true branch\")" "    #f)")
  #:start-line 16)
Syntactic replacement
(syntax-replacement
  #:new-syntax
    #<syntax:/home/runner/.local/share/racket/8.5/pkgs/resyntax/default-recommendations/boolean-shortcuts.rkt:84:3 (and (ORIGINAL-SPLICE (quote a) (println "true branch")))>
  #:original-syntax
    #<syntax:test.rkt:16:0 (if (quote a) (println "true branch") #f)>)



(define some-list (list 1 2 3))
(for-each
(λ (x)
(displayln x)
(displayln x))
some-list)
Comment on lines +22 to +26

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for-each-to-for This for-each operation can be replaced with a for loop.

Suggested change
(for-each
(λ (x)
(displayln x)
(displayln x))
some-list)
(for ([x (in-list some-list)])
(displayln x)
(displayln x))

Debugging details below:

Textual replacement
(line-replacement
  #:new-lines
    '#("(for ([x (in-list some-list)])" "  (displayln x)" "  (displayln x))")
  #:original-lines
    '#("(for-each"
       " (λ (x)"
       "   (displayln x)"
       "   (displayln x))"
       " some-list)")
  #:start-line 22)
Syntactic replacement
(syntax-replacement
  #:new-syntax
    #<syntax:/home/runner/.local/share/racket/8.5/pkgs/resyntax/default-recommendations/for-loop-shortcuts.rkt:149:3 (for ((x (in-list some-list))) NEWLINE (ORIGINAL-SPLICE (displayln x) (displayln x)))>
  #:original-syntax
    #<syntax:test.rkt:22:0 (for-each (λ (x) (displayln x) (displayln x)) some-list)>)



(define some-list2 (list 3 5 14 10 6 5 2))
(ormap
(λ (x)
(and (number? x)
(positive? x)
(even? x)
(< x 10)))
some-list2)
Comment on lines +30 to +36

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ormap-to-for/or This ormap operation can be replaced with a for/or loop.

Suggested change
(ormap
(λ (x)
(and (number? x)
(positive? x)
(even? x)
(< x 10)))
some-list2)
(for/or ([x (in-list some-list2)])
(and (number? x)
(positive? x)
(even? x)
(< x 10)))

Debugging details below:

Textual replacement
(line-replacement
  #:new-lines
    '#("(for/or ([x (in-list some-list2)])"
       "  (and (number? x)"
       "       (positive? x)"
       "       (even? x)"
       "       (< x 10)))")
  #:original-lines
    '#("(ormap"
       " (λ (x)"
       "   (and (number? x)"
       "        (positive? x)"
       "        (even? x)"
       "        (< x 10)))"
       " some-list2)")
  #:start-line 30)
Syntactic replacement
(syntax-replacement
  #:new-syntax
    #<syntax:/home/runner/.local/share/racket/8.5/pkgs/resyntax/default-recommendations/for-loop-shortcuts.rkt:158:3 (for/or ((x (in-list some-list2))) NEWLINE (and (number? x) (positive? x) (even? x) (< x 10)))>
  #:original-syntax
    #<syntax:test.rkt:30:0 (ormap (λ (x) (and (number? x) (positive? x) (even? x) (< x 10))) some-list2)>)

Copy link
Owner Author

@jackfirth jackfirth Jun 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sorawee fixed 😄