Skip to content

Commit

Permalink
Add begin0-begin-extraction rule (#407)
Browse files Browse the repository at this point in the history
Closes #404.
  • Loading branch information
jackfirth authored Nov 20, 2024
1 parent 7cc7166 commit 8b9b7cb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
16 changes: 16 additions & 0 deletions default-recommendations/definition-shortcuts-test.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,19 @@ test: "begin0 in right hand side of definition can be removed"
(displayln "foo")
(* x 2))
--------------------


test: "begin inside begin0 in definition context should be extractable"
--------------------
(define (f x)
(displayln "starting")
(begin0 (begin (displayln "before") (* x 2))
(displayln "after")))
--------------------
--------------------
(define (f x)
(displayln "starting")
(displayln "before")
(begin0 (* x 2)
(displayln "after")))
--------------------
16 changes: 15 additions & 1 deletion default-recommendations/definition-shortcuts.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,22 @@
(body-before ... replacement ... body-after ...))


(define-definition-context-refactoring-rule begin0-begin-extraction
#:description
"The `begin` form inside this `begin0` form can be extracted into the surrounding definition\
context."
#:literals (begin0 begin)
(~seq body-before ...
(~and outer-form (begin0 (begin pre-body ... expr) post-body ...)))
#:with (replacement ...)
#'(~focus-replacement-on
(~splicing-replacement (pre-body ... (begin0 expr post-body ...)) #:original outer-form))
(body-before ... replacement ...))


(define-refactoring-suite definition-shortcuts
#:rules (define-begin-extraction
#:rules (begin0-begin-extraction
define-begin-extraction
define-begin0-extraction
define-values-values-to-define
inline-unnecessary-define))

0 comments on commit 8b9b7cb

Please sign in to comment.