File tree Expand file tree Collapse file tree 2 files changed +19
-3
lines changed
Expand file tree Collapse file tree 2 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -162,6 +162,19 @@ test: "hash-set! with hash-ref and literal keys can be simplified to hash-update
162162------------------------------
163163
164164
165+ test: "hash-set! with hash-ref can be simplified to hash-update! without lambda "
166+ ------------------------------
167+ (define h (make-hash))
168+ (define k 'a )
169+ (hash-set! h k (add1 (hash-ref h k 0 )))
170+ ------------------------------
171+ ------------------------------
172+ (define h (make-hash))
173+ (define k 'a )
174+ (hash-update! h k add1 0 )
175+ ------------------------------
176+
177+
165178test: "hash-set! with hash-ref cannot be simplified when v would shadow "
166179------------------------------
167180(define h (make-hash))
Original file line number Diff line number Diff line change 1010
1111
1212(require (for-syntax racket/base)
13+ racket/list
1314 racket/set
1415 rebellion/private/static-name
1516 resyntax/base
107108 #:when (syntax-free-identifier=? #'k1 #'k2 )
108109 #:when (for/and ([id (in-syntax-identifiers #'(f arg-before ... arg-after ... ))])
109110 (not (equal? (syntax-e id) 'v )))
110- (hash-update! h1 k1
111- (λ (v) (f arg-before ... v arg-after ... ))
112- (~? failure-result)))
111+ #:with updater
112+ (if (and (empty? (attribute arg-before)) (empty? (attribute arg-after)))
113+ #'f
114+ #'(λ (v) (f arg-before ... v arg-after ... )))
115+ (hash-update! h1 k1 updater (~? failure-result)))
113116
114117
115118(define-refactoring-rule hash-map-to-hash-keys
You can’t perform that action at this time.
0 commit comments