6.3.90.900
14.8 Tag
Convenience functions for working with tags.
Make a default tag function for
id. The new tag function takes an optional set of X-expression attributes (
txexpr-attrs?) followed by X-expression elements (
txexpr-elements?). From these, the tag function creates a tagged X-expression using
id as the tag.
Examples:
> (require pollen/tag) |
|
> (define beaucoup (default-tag-function 'em)) |
|
> (beaucoup "Bonjour") |
'(em "Bonjour") |
> (beaucoup '((id "greeting")) "Bonjour") |
'(em ((id "greeting")) "Bonjour") |
Entering attributes this way can be cumbersome. So for convenience, the new tag function provides an alternative: any keyword arguments and their values will be interpreted as attributes.
Examples:
> (require pollen/tag) |
|
> (define beaucoup (default-tag-function 'em)) |
|
> (beaucoup #:id "greeting" #:class "large" "Bonjour") |
'(em ((class "large") (id "greeting")) "Bonjour") |
You can also provide keyword arguments to default-tag-function itself, and they will become default attributes for every use of the tag function.
Examples:
> (require pollen/tag) |
|
> (define beaucoup-small (default-tag-function 'em #:class "small")) |
|
> (beaucoup-small #:id "greeting" "Bonjour") |
'(em ((class "small") (id "greeting")) "Bonjour") |
Pollen also uses this function to provide the default behavior for undefined tags. See #%top.
Note that while default tag functions are typically used to generate tagged X-expressions, they don’t enforce any restrictions on input, so they also do not guarantee that you will in fact get a valid tagged X-expression as output. This is intentional — default tag functions are a coding convenience, and their output is likely to be processed by other tag functions, so raising the error here would be premature.
Examples:
> (require pollen/tag) |
|
> (define strange (default-tag-function 'div #:class "bizarre")) |
|
; Invalid data types for elements |
> (strange + *) |
'(div ((class "bizarre")) #<procedure:+> #<procedure:*>) |
; Double "class" attribute |
> (strange #:class "spooky") |
'(div ((class "bizarre") (class "spooky"))) |
Helper function for making custom tag functions. Handles parsing chores, including conversion of keyword arguments into attributes (described in
default-tag-function), and parses other attributes and elements normally.
Examples:
> (require pollen/tag) |
|
|
|
> (tag-name "Hello world") |
'(new-name ((zim "zam")) "Hello world") |
> (tag-name '((key "value")) "Hello world") |
'(new-name ((zim "zam") (key "value")) "Hello world") |
> (tag-name #:key "value" "Hello world") |
'(new-name ((zim "zam") (key "value")) "Hello world") |