Skip to content

Commit

Permalink
document the primitive template forms
Browse files Browse the repository at this point in the history
with-template, semiwith-template, quote-template, semiquote-template

and make the examples more clearly demonstrate their differences
  • Loading branch information
dedbox committed Mar 9, 2020
1 parent ed2d811 commit 17948f1
Showing 1 changed file with 25 additions and 16 deletions.
41 changes: 25 additions & 16 deletions scribblings/template.scrbl
Original file line number Diff line number Diff line change
Expand Up @@ -150,42 +150,51 @@ Examples:
]
}

@defform[(semiquote-template ([var-id val-expr] ...) tpl ...)]{
@defform[(semiwith-template ([var-id val-expr] ...) tpl ...)]{

Like @racket[with-template], except sub-templates wrapped in @racket[syntax]
or @racket[quasisyntax] are not expanded, and code fragments generated from
template variables inherit the @rtech{lexical information}, source-location
Like @racket[with-template], except literals generated from template
variables inherit the @rtech{lexical information}, source-location
information, and @rtech{syntax properties} of the @var[val-expr] bound to
the first @var[var-id] used.

Example:
@example[
(semiquote-template ([$where 'here]) #'$where)
(semiwith-template ([$where 'here]) #'$where)
]

@example[
(with-template ([$where 'not--here]) #'$where)
(with-template ([$where 'not-here]) #'$where)
]

When a @racket[semiquote-template] form appears at the top level, at module
level, or in an internal-definition position (before any expression in the
internal-definition sequence), it is equivalent to splicing the expanded
@var[tpl]s into the enclosing context.
}

@defform[(quote-template ([var-id val-expr] ...) tpl ...)]{

Like @racket[semiquote-template], except sub-templates are not expanded.
Like @racket[semiwith-template], except sub-templates are not expanded.

Example:
@example[
(quote-template ([$where 'not-here]) #'(untemplate $where))
]

@example[
(semiwith-template ([$where 'there]) #'(untemplate $where))
]
}

@defform[(semiquote-template ([var-id val-expr] ...) tpl ...)]{

Like @racket[quote-template], except literals generated from template
variables inherit the @rtech{lexical information}, source-location
information, and @rtech{syntax properties} of the @var[val-expr] bound to
the first @var[var-id] used.

Example:
@example[
(quote-template ([$n 5])
'((for/template ([$k (in-range $n)]) $k)))
(semiquote-template ([$where 'not-here]) #'(untemplate $where))
]

@example[
(semiquote-template ([$n 5])
'((for/template ([$k (in-range $n)]) $k)))
(quote-template ([$where 'not-here]) #'(untemplate $where))
]
}

Expand Down

0 comments on commit 17948f1

Please sign in to comment.