Skip to content

Commit

Permalink
Add a rule for single-case case-lambda (#260)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackfirth authored Aug 31, 2024
1 parent 30a0a7d commit b4dbc97
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions default-recommendations/function-shortcuts-test.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,8 @@ test: "apply with recursive list* can be flattened"
test: "apply with quasiquoted list can be flattened"
- (apply + 0 `(1 2 ,@'(3 4)))
- (apply + 0 1 2 '(3 4))


test: "single-case case-lambda refactorable to regular lambda"
- (case-lambda [(x y z) (+ x y z)])
- (λ (x y z) (+ x y z))
9 changes: 8 additions & 1 deletion default-recommendations/function-shortcuts.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,15 @@
(id function arg ... trailing-arg.lifted ... trailing-arg.trailing)])


(define-refactoring-rule case-lambda-with-single-case-to-lambda
#:description "This `case-lambda` form only has one case. Use a regular lambda instead."
#:literals (case-lambda)
[(case-lambda [args body ...]) (λ args body ...)])


(define function-shortcuts
(refactoring-suite
#:name (name function-shortcuts)
#:rules
(list apply-flattening)))
(list apply-flattening
case-lambda-with-single-case-to-lambda)))

0 comments on commit b4dbc97

Please sign in to comment.