From e5208294e018fed487c69d0a8817ecebcbb9f56c Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Wed, 19 Feb 2014 22:38:51 -0800 Subject: [PATCH] reversed sequence of output values in splitf-texpr --- main.rkt | 4 ++-- scribblings/txexpr.scrbl | 4 ++-- tests.rkt | 3 +-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/main.rkt b/main.rkt index c3450e0..b39f78e 100644 --- a/main.rkt +++ b/main.rkt @@ -194,7 +194,7 @@ ;; function to split tag out of txexpr (define+provide/contract (splitf-txexpr tx proc) - (txexpr? procedure? . -> . (values (listof txexpr-element?) txexpr?)) + (txexpr? procedure? . -> . (values txexpr? (listof txexpr-element?))) (define matches empty) (define (do-extraction x) (cond @@ -206,5 +206,5 @@ [(txexpr-elements? x) (filter-not empty? (map do-extraction x))] [else x])) (define tx-extracted (do-extraction tx)) ;; do this first to fill matches - (values (reverse matches) tx-extracted)) + (values tx-extracted (reverse matches))) diff --git a/scribblings/txexpr.scrbl b/scribblings/txexpr.scrbl index ba18caa..e12f017 100644 --- a/scribblings/txexpr.scrbl +++ b/scribblings/txexpr.scrbl @@ -380,8 +380,8 @@ Be careful with the wider consequences of exclusion tests. When @racket[_exclude (splitf-txexpr [tx txexpr?] [pred procedure?]) -(values (listof txexpr-element?) txexpr?)] -Recursively descend through @racket[_txexpr] and extract all elements that match @racket[_pred]. Returns two values: a list of matching elements, and the @racket[_txexpr] with the elements removed. Sort of esoteric, but I've needed it more than once, so here it is. +(values txexpr? (listof txexpr-element?))] +Recursively descend through @racket[_txexpr] and extract all elements that match @racket[_pred]. Returns two values: a @racket[_txexpr] with the matching elements removed, and the list of matching elements. Sort of esoteric, but I've needed it more than once, so here it is. @examples[#:eval my-eval (define tx '(div "Wonderful day" (meta "weather" "good") "for a walk")) diff --git a/tests.rkt b/tests.rkt index 3caed00..9d358c2 100644 --- a/tests.rkt +++ b/tests.rkt @@ -113,6 +113,5 @@ (define split-this-tx '(root (meta "foo" "bar") "hello" "world" (meta "foo2" "bar2") (em "goodnight" "moon" (meta "foo3" "bar3")))) (check-equal? (call-with-values (λ() (splitf-txexpr split-this-tx (λ(x) (and (txexpr? x) (equal? 'meta (car x)))))) list) - (list '((meta "foo" "bar") (meta "foo2" "bar2") (meta "foo3" "bar3")) - '(root "hello" "world" (em "goodnight" "moon")))) + (list '(root "hello" "world" (em "goodnight" "moon")) '((meta "foo" "bar") (meta "foo2" "bar2") (meta "foo3" "bar3"))))