From 6226db2ceb1185c435387bcbd8ee3ebf92b0567b Mon Sep 17 00:00:00 2001 From: Sage Gerard <[email]> Date: Sat, 10 Aug 2019 20:04:12 -0400 Subject: [PATCH 1/4] Expose deleted-signal with docs correction MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The docs say that `(λ (x) null)` is the default `replace-proc` for `splitf-txexpr`. This disagrees with the code, which uses `deleted-signal`. Since there is a use case for conditionally removing elements, `(provide deleted-signal)` and correct the docs. --- txexpr/base.rkt | 1 + txexpr/scribblings/txexpr.scrbl | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/txexpr/base.rkt b/txexpr/base.rkt index cd1eced..32bd9e8 100644 --- a/txexpr/base.rkt +++ b/txexpr/base.rkt @@ -6,6 +6,7 @@ (for-syntax racket/base syntax/parse)) (provide cdata? cdata valid-char? xexpr->string xexpr?) ; from xml (provide empty) ; from racket/list +(provide deleted-signal) ;; Section 2.2 of XML 1.1 ;; (XML 1.0 is slightly different and more restrictive) diff --git a/txexpr/scribblings/txexpr.scrbl b/txexpr/scribblings/txexpr.scrbl index 17e0f74..f02cf33 100644 --- a/txexpr/scribblings/txexpr.scrbl +++ b/txexpr/scribblings/txexpr.scrbl @@ -469,12 +469,18 @@ In practice, most @racket[_txexpr-element]s are strings. But it's unwise to pass ] +@deftogether[( + +@defthing[deleted-signal symbol?] + @defproc[ (splitf-txexpr [tx txexpr?] [pred procedure?] -[replace-proc procedure? (λ (x) null)]) +[replace-proc procedure? (λ (x) deleted-signal)]) (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 @@ -483,7 +489,7 @@ Recursively descend through @racket[_txexpr] and extract all elements that match (splitf-txexpr tx is-meta?) ] -Ordinarily, the result of the split operation is to remove the elements that match @racket[_pred]. But you can change this behavior with the optional @racket[_replace-proc] argument. +Ordinarily, the result of the split operation is to remove the elements that match @racket[_pred]. This happens only when returning @racket[_deleted-signal]. You can change this behavior with the optional @racket[_replace-proc] argument. @examples[#:eval my-eval (define tx '(div "Wonderful day" (meta "weather" "good") "for a walk")) -- 2.25.1 From d559d568e135630399807cb86cfdda742ab23bf3 Mon Sep 17 00:00:00 2001 From: Sage Gerard <[email]> Date: Sat, 10 Aug 2019 20:27:18 -0400 Subject: [PATCH 2/4] Use define+provide+safe --- txexpr/base.rkt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/txexpr/base.rkt b/txexpr/base.rkt index 32bd9e8..267c08e 100644 --- a/txexpr/base.rkt +++ b/txexpr/base.rkt @@ -6,7 +6,6 @@ (for-syntax racket/base syntax/parse)) (provide cdata? cdata valid-char? xexpr->string xexpr?) ; from xml (provide empty) ; from racket/list -(provide deleted-signal) ;; Section 2.2 of XML 1.1 ;; (XML 1.0 is slightly different and more restrictive) @@ -262,7 +261,7 @@ x)))) ;; function to split tag out of txexpr -(define deleted-signal (gensym)) +(define+provide+safe deleted-signal symbol? (gensym)) (define+provide+safe (splitf-txexpr tx pred [proc (λ (x) deleted-signal)]) ((txexpr? procedure?) (procedure?) . ->* . (values txexpr? txexpr-elements?)) (unless (txexpr? tx) -- 2.25.1 From e6d64fe7f1ca5c6ef0e16d948eb5e9daad6d7198 Mon Sep 17 00:00:00 2001 From: Sage Gerard <[email]> Date: Sat, 10 Aug 2019 20:48:48 -0400 Subject: [PATCH 3/4] Use #f --- txexpr/base.rkt | 2 +- txexpr/scribblings/txexpr.scrbl | 10 ++-------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/txexpr/base.rkt b/txexpr/base.rkt index 267c08e..fd2559c 100644 --- a/txexpr/base.rkt +++ b/txexpr/base.rkt @@ -261,7 +261,7 @@ x)))) ;; function to split tag out of txexpr -(define+provide+safe deleted-signal symbol? (gensym)) +(define deleted-signal #f) (define+provide+safe (splitf-txexpr tx pred [proc (λ (x) deleted-signal)]) ((txexpr? procedure?) (procedure?) . ->* . (values txexpr? txexpr-elements?)) (unless (txexpr? tx) diff --git a/txexpr/scribblings/txexpr.scrbl b/txexpr/scribblings/txexpr.scrbl index f02cf33..5a1f62c 100644 --- a/txexpr/scribblings/txexpr.scrbl +++ b/txexpr/scribblings/txexpr.scrbl @@ -469,18 +469,12 @@ In practice, most @racket[_txexpr-element]s are strings. But it's unwise to pass ] -@deftogether[( - -@defthing[deleted-signal symbol?] - @defproc[ (splitf-txexpr [tx txexpr?] [pred procedure?] -[replace-proc procedure? (λ (x) deleted-signal)]) +[replace-proc procedure? (λ (x) #f)]) (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 @@ -489,7 +483,7 @@ Recursively descend through @racket[_txexpr] and extract all elements that match (splitf-txexpr tx is-meta?) ] -Ordinarily, the result of the split operation is to remove the elements that match @racket[_pred]. This happens only when returning @racket[_deleted-signal]. You can change this behavior with the optional @racket[_replace-proc] argument. +Ordinarily, the result of the split operation is to remove the elements that match @racket[_pred]. But you can change this behavior with the optional @racket[_replace-proc] argument. @examples[#:eval my-eval (define tx '(div "Wonderful day" (meta "weather" "good") "for a walk")) -- 2.25.1 From c87250f630303e772c572c1853d36815ba1091ff Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Wed, 11 Sep 2019 17:27:42 -0400 Subject: [PATCH 4/4] Omit `deleted-signal` --- txexpr/base.rkt | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/txexpr/base.rkt b/txexpr/base.rkt index fd2559c..80ed2a8 100644 --- a/txexpr/base.rkt +++ b/txexpr/base.rkt @@ -261,8 +261,7 @@ x)))) ;; function to split tag out of txexpr -(define deleted-signal #f) -(define+provide+safe (splitf-txexpr tx pred [proc (λ (x) deleted-signal)]) +(define+provide+safe (splitf-txexpr tx pred [proc (λ (x) #f)]) ((txexpr? procedure?) (procedure?) . ->* . (values txexpr? txexpr-elements?)) (unless (txexpr? tx) (raise-argument-error 'splitf-txexpr "txexpr?" tx)) @@ -273,8 +272,7 @@ (set! matches (cons x matches)) (proc x)] [(? txexpr?) (let-values ([(tag attrs elements) (txexpr->values x)]) - (txexpr-unsafe tag attrs (filter-not (λ (e) (eq? e deleted-signal)) - (map extract! elements))))] + (txexpr-unsafe tag attrs (filter values (map extract! elements))))] [_ x])) (define tx-extracted (extract! tx)) ;; do this first to fill matches (values tx-extracted (reverse matches))) -- 2.25.1