fix `map-elements`

dev-fixit
Matthew Butterick 9 years ago
parent 7b3d3abee6
commit 5131a8564f

@ -289,23 +289,13 @@
x))) x)))
(define (map-elements/exclude proc x exclude-test)
(procedure? txexpr? procedure? . -> . txexpr?)
(cond
[(txexpr? x)
(if (exclude-test x)
x
(let-values ([(tag attr elements) (txexpr->values x)])
(txexpr tag attr
(map (λ(x)(map-elements/exclude proc x exclude-test)) elements))))]
;; externally the function only accepts txexpr,
;; but internally we don't care
[else (proc x)]))
(define+provide+safe (map-elements proc x) (define+provide+safe (map-elements proc x)
(procedure? txexpr? . -> . txexpr?) (procedure? txexpr? . -> . txexpr?)
(map-elements/exclude proc x (λ _ #f))) (proc (if (txexpr? x)
(let-values ([(tag attr elements) (txexpr->values x)])
(txexpr tag attr (map (λ(e)(map-elements proc e)) elements)))
x)))
;; function to split tag out of txexpr ;; function to split tag out of txexpr

@ -187,8 +187,8 @@
(check-txexprs-equal? (map-elements (λ(x) (if (string? x) "boing" x)) (check-txexprs-equal? (map-elements (λ(x) (if (string? x) "boing" x))
'(p "foo" "bar" (em "square"))) '(p ((id "zam")) "foo" "bar" (em "square")))
'(p "boing" "boing" (em "boing"))) '(p ((id "zam")) "boing" "boing" (em "boing")))
(check-equal? (attr-set '(p) 'foo "zim") '(p ((foo "zim")))) (check-equal? (attr-set '(p) 'foo "zim") '(p ((foo "zim"))))
(check-equal? (attr-set '(p ((foo "bar")(foo "zam"))) 'foo "zim") '(p ((foo "zim")))) (check-equal? (attr-set '(p ((foo "bar")(foo "zam"))) 'foo "zim") '(p ((foo "zim"))))

Loading…
Cancel
Save