add `txexpr*` (closes #4)

pull/5/head
Matthew Butterick 9 years ago
parent 0e2203ea7c
commit 5e384b1980

@ -164,6 +164,11 @@
[else ""]))))
(define+provide+safe (txexpr* tag [attrs null] . elements)
((symbol?) (txexpr-attrs?) #:rest txexpr-elements? . ->* . txexpr?)
(txexpr tag attrs elements))
(define make-txexpr txexpr) ; for backward compatability
(provide+safe make-txexpr)

@ -228,6 +228,24 @@ Assemble a @racket[_txexpr] from its parts. If you don't have attributes, but yo
(get-attrs tx) (get-elements tx))
]
@defproc[
(txexpr*
[tag txexpr-tag?]
[attrs txexpr-attrs? @empty]
[element txexpr-element?] ...)
txexpr?]
Like @racket[txexpr], but takes an indefinite number of @racket[_element] arguments, which together are treated as the list of elements for the resulting @racket[_txexpr]. A notational convenience.
@examples[#:eval my-eval
(txexpr* 'div)
(txexpr* 'div '() "Hello" '(p "World"))
(txexpr* 'div '((id "top")))
(txexpr* 'div '((id "top")) "Hello" '(p "World"))
(define tx '(div ((id "top")) "Hello" (p "World")))
(apply txexpr* (get-tag tx)
(get-attrs tx) (get-elements tx))
]
@deftogether[(
@defproc[

@ -89,6 +89,12 @@
(check-txexprs-equal? (txexpr 'p null '("foo" "bar")) '(p "foo" "bar"))
(check-txexprs-equal? (txexpr 'p '((key "value")) (list "foo" "bar"))
'(p ((key "value")) "foo" "bar"))
(check-txexprs-equal? (txexpr* 'p) '(p))
(check-txexprs-equal? (txexpr* 'p '((key "value"))) '(p ((key "value"))))
(check-txexprs-equal? (txexpr* 'p null "foo" "bar") '(p "foo" "bar"))
(check-txexprs-equal? (txexpr* 'p '((key "value")) "foo" "bar")
'(p ((key "value")) "foo" "bar"))
(check-equal? (values->list (txexpr->values '(p)))
(values->list (values 'p null null)))

Loading…
Cancel
Save