File tree Expand file tree Collapse file tree 2 files changed +23
-7
lines changed
Expand file tree Collapse file tree 2 files changed +23
-7
lines changed Original file line number Diff line number Diff line change @@ -62,6 +62,11 @@ test: "multi-line if else false can be refactored to a multi-line and expression
6262------------------------------
6363
6464
65+ test: "if and else false can be refactored to a single and expression "
66+ - (if (and 'a 'b ) 'c #f )
67+ - (and 'a 'b 'c )
68+
69+
6570test: "if x else x can be refactored to an and expression "
6671------------------------------
6772(define x 'a )
@@ -87,6 +92,17 @@ test: "multi-line if x else x can be refactored to a multi-line and expression"
8792------------------------------
8893
8994
95+ test: "if x then and expression else x can be refactored to a single and expression "
96+ ------------------------------
97+ (define x 'a )
98+ (if x (and 'b 'c 'd ) x)
99+ ------------------------------
100+ ------------------------------
101+ (define x 'a )
102+ (and x 'b 'c 'd )
103+ ------------------------------
104+
105+
90106test: "if expressions can be refactored to when expressions when equivalent "
91107------------------------------
92108(if #true
Original file line number Diff line number Diff line change 4949
5050(define-refactoring-rule if-else-false-to-and
5151 #:description equivalent-conditional-description
52- #:literals (if )
53- (if condition then-branch #false )
54- (and condition then-branch))
52+ #:literals (if and )
53+ (if (~or ( and condition-part:expr ... ) condition:expr) then-branch #false )
54+ (and (~? (~@ condition-part ... ) condition) then-branch))
5555
5656
5757(define-refactoring-rule if-x-else-x-to-and
5858 #:description equivalent-conditional-description
59- #:literals (if )
60- (if x:id then-branch:expr y:id)
61- #:when (free-identifier=? #'x #'y )
62- (and x then-branch))
59+ #:literals (if and )
60+ (if x:id (~or ( and then-part ... ) then- branch:expr) y:id)
61+ #:when (free-identifier=? (attribute x) (attribute y) )
62+ (and x (~? (~@ then-part ... ) then- branch) ))
6363
6464
6565(define-syntax-class block-expression
You can’t perform that action at this time.
0 commit comments