From 5131a8564f454e3769622681888b2df3fb8f2fe5 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Sat, 20 Feb 2016 12:10:06 -0800 Subject: [PATCH] fix `map-elements` --- main.rkt | 18 ++++-------------- tests.rkt | 4 ++-- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/main.rkt b/main.rkt index 4728a36..c9524d8 100644 --- a/main.rkt +++ b/main.rkt @@ -289,23 +289,13 @@ 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) (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 diff --git a/tests.rkt b/tests.rkt index b716a00..19edca7 100644 --- a/tests.rkt +++ b/tests.rkt @@ -187,8 +187,8 @@ (check-txexprs-equal? (map-elements (λ(x) (if (string? x) "boing" x)) - '(p "foo" "bar" (em "square"))) - '(p "boing" "boing" (em "boing"))) + '(p ((id "zam")) "foo" "bar" (em "square"))) + '(p ((id "zam")) "boing" "boing" (em "boing"))) (check-equal? (attr-set '(p) 'foo "zim") '(p ((foo "zim")))) (check-equal? (attr-set '(p ((foo "bar")(foo "zam"))) 'foo "zim") '(p ((foo "zim"))))