|
214 | 214 | (take target-list-with-prefix-dropped amount-to-take)) |
215 | 215 |
|
216 | 216 |
|
| 217 | +(define-syntax-class static-list-expression |
| 218 | + #:literals (cons list list*) |
| 219 | + #:attributes ([element 1] maker improper-tail simplifiable?) |
| 220 | + |
| 221 | + (pattern ((~and list maker) ~! element ...) |
| 222 | + #:attr improper-tail #false |
| 223 | + #:attr simplifiable? #false) |
| 224 | + |
| 225 | + (pattern ((~and list* maker) element ... (~and improper-tail (~not :static-list-expression))) |
| 226 | + #:attr simplifiable? #false) |
| 227 | + |
| 228 | + (pattern (cons ~! head tail:static-list-expression) |
| 229 | + #:attr [element 1] (cons #'head (attribute tail.element)) |
| 230 | + #:attr maker (attribute tail.maker) |
| 231 | + #:attr improper-tail (attribute tail.improper-tail) |
| 232 | + #:attr simplifiable? #true) |
| 233 | + |
| 234 | + (pattern (list* head ... tail:static-list-expression) |
| 235 | + #:attr [element 1] (append (attribute head) (attribute tail.element)) |
| 236 | + #:attr maker (attribute tail.maker) |
| 237 | + #:attr improper-tail (attribute tail.improper-tail) |
| 238 | + #:attr simplifiable? #true)) |
| 239 | + |
| 240 | + |
| 241 | +(define-refactoring-rule consing-onto-static-list |
| 242 | + #:description "This list-constructing expression can be simplified" |
| 243 | + #:literals (cons list) |
| 244 | + expr:static-list-expression |
| 245 | + #:when (attribute expr.simplifiable?) |
| 246 | + (expr.maker expr.element ... (~? expr.improper-tail))) |
| 247 | + |
| 248 | + |
217 | 249 | (define-refactoring-suite list-shortcuts |
218 | 250 | #:rules (append-single-list-to-single-list |
219 | 251 | append*-and-map-to-append-map |
220 | 252 | build-list-const-to-make-list |
| 253 | + consing-onto-static-list |
221 | 254 | equal-null-list-to-null-predicate |
222 | 255 | filter-to-remove* |
223 | 256 | filter-to-remq* |
|
0 commit comments