Overview
| Comment: | Variadic make-tag-predicate | 
|---|---|
| Timelines: | family | ancestors | descendants | both | trunk | 
| Files: | files | file ages | folders | 
| SHA3-256: | 3ed1107392e620952a40a0ae558708db | 
| User & Date: | joel on 2020-02-24 07:35:08 | 
| Other Links: | manifest | tags | 
Context
| 2020-02-26 | ||
| 01:15 | Don't recompute article ids every time check-in: 49e661b8 user: joel tags: trunk | |
| 2020-02-24 | ||
| 07:35 | Variadic make-tag-predicate check-in: 3ed11073 user: joel tags: trunk | |
| 2020-02-22 | ||
| 00:04 | Minor code doc edits check-in: e538e325 user: joel tags: trunk | |
Changes
Modified code-docs/dust.scrbl from [c0b36b73] to [73710a17].
| ︙ | ︙ | |||
| 99 100 101 102 103 104 105 | 
Finds all the strings from the @emph{elements} of @racket[_tx] (ignoring attributes) and
concatenates them together.
@examples[#:eval dust-eval
(tx-strs '(p [[class "intro"]] 
             (em "I’m not opening the safe") ", Wilson remembers thinking."))]
 | | | | | | > | 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | 
Finds all the strings from the @emph{elements} of @racket[_tx] (ignoring attributes) and
concatenates them together.
@examples[#:eval dust-eval
(tx-strs '(p [[class "intro"]] 
             (em "I’m not opening the safe") ", Wilson remembers thinking."))]
@defproc[(make-tag-predicate [sym symbol?] ...) (-> any/c boolean?)]
Returns a function (or @italic{predicate}) that returns @racket[#t] if its argument is
a @racket[_txexpr] whose tag matches any @racket[_sym]. This predicate is useful for passing as the
@racket[_pred] expression in functions @racket[splitf-txexpr] and @racket[findf-txexpr].
@examples[#:eval dust-eval 
(define is-aside? (make-tag-predicate 'aside 'sidebar))
(is-aside? '(q "I am not mad, Sir Topas. I say to you this house is dark."))
(is-aside? '(aside "How smart a lash that speech doth give my Conscience?"))
(is-aside? '(sidebar "Many copies that we use today are conflated texts."))]
@defproc[(first-words [txprs (listof txexpr?)] [n exact-nonnegative-integer?]) string?]
Given a list of tagged X-expressions, returns a string containing the first @racket[_n] words found
in the string elements of @racket[_txprs], or all of the words if there are less than @racket[_n]
words available. Used by @racket[default-title].
 | 
| ︙ | ︙ | 
Modified dust.rkt from [dffdbbe2] to [e986dd0a].
| ︙ | ︙ | |||
| 134 135 136 137 138 139 140 | 
(define (maybe-attr name attrs [missing ""])
  (define result (assoc name attrs))
  (cond
    [(pair? result) (cadr result)]
    [else missing]))
;; Returns a function will test if a txexpr's tag matches the given symbol.
 | | | | 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | 
(define (maybe-attr name attrs [missing ""])
  (define result (assoc name attrs))
  (cond
    [(pair? result) (cadr result)]
    [else missing]))
;; Returns a function will test if a txexpr's tag matches the given symbol.
(define (make-tag-predicate . tagsyms)
  (lambda (tx) (if (and (txexpr? tx) (member (get-tag tx) tagsyms)) #t #f)))
(define (tx-strs xpr)
  (cond
    [(txexpr? xpr) (apply string-append (map tx-strs (get-elements xpr)))]
    [(string? xpr) xpr]
    [else ""]))
 | 
| ︙ | ︙ |