October 9th Tuesday (十月 九日 火曜日)

来源:互联网 发布:中国从非洲进口数据 编辑:程序博客网 时间:2024/05/16 20:37
A syntax expression is similar to a quote expression except that (1)the values of pattern variables
appearing within <template> are inserted into template, (2) contextual information associated both with
the input and with the template is retained in the output to support lexical scoping, and (3) the value
of a syntax expression is a syntax object.

  The value of a syntax form is a copy of <template> in which the pattern variables appearing within the
template are replaced with the input subforms to which they are bound.  Pattern data and identifiers that
are not pattern variables or ellipses are copied directly into the output.  A subtemplate followed by an
ellipsis into zero or more occurrences of the subtemplate.

  (bound-identifier=? id1 id2)

  Id1 and Id2 must be identifiers.  The procedure bound-identifier=? returns #t if a binding for one would
capture a reference to the other in the output of the transformer, assuming that the reference appears
within the scope of the binding, and #f otherwise.  In general, two identifiers are bound-identifier=?
only if both are introduced by the same transformer application.  Operationally, two identifiers are
considered equivalent by bound-identifier=? if and only if they have the same name and same marks.

  (free-identifier=? id1 id2)

  Id1 and Id2 must be identifiers.  The free-identifier=? procedure returns #t if and only if the two
identifiers would resolve to the same binding if both were to appear in the output of a transformer
outside of any bindings inserted by the transformer.  (If neither of two like-named identifiers resolves
to a binding, i.e., both are unbound, they are considered to resolve to the same binding.) Operationally,
two identifiers are considered equivalent by free-identifier=? if and only the topmost matching substitution
for each maps to the same binding or the identifiers have the same name and no matching substitution.

  (syntax->datum syntax-object)

  Strips all syntactic information from a syntax object and returns the corresponding Scheme datum.

  (datum->syntax template-id datum)

  Template-id must be a template identifier and datum should be a datum value.  The datum->syntax procedure
returns a syntax-object representation of datum that contains the same contextual information as template-id,
with the effect that the syntax object behaves as if it were introduced into the code when template-id was
introduced.

  (with-syntax ((<pattern> <expression>) ...) <body>)

  The with-syntax form is used to bind pattern variables, just as let is used to bind variables.  This allows
a transformer to construct its output in separate pieces, then put the pieces together.

  Each <pattern> is identical in form to a syntax-case pattern.  The value of each <expression> is computed
and destructed according to the corresponding <pattern>, and pattern variables within the <pattern> are bound
as with syntax-case to the corresponding portions of the value within <body>.

(define-syntax with-syntax
  (lambda (x)
    (syntax-case x ()
      ((_ ((p e0) ...) e1 e2 ...)
        (syntax (syntax-case (list e0 ...) ()
                  ((p ...) (let () e1 e2 ...))))))))


October 10th Wednesday (十月 十日 水曜日)

  (syntax datum)                #'datum

  (quasisyntax <template>)      #`<template>
  unsyntax                      #,<template>
  unsyntax-splicing             #,@<template>

  The quasisyntax form is similar to syntax, but it allows parts of the quoted text to be evaluated, in a
manner similar to the operation of quasiquoted.

  Within a quasisyntax template, subforms of unsyntax and unsyntax-splicing forms are evaluated, and every-
thing else is treated as ordinary template material, as with "syntax".  The value of each unsyntax subform is
inserted into the output in place of the unsyntax form, while the value of each unsyntax-splicing subform is
spliced into the surrounding list or vector structure.  Uses of unsyntax and unsyntax-splicing are vaild only
within quasisyntax expressions.

  A quasisyntax expression may be nested, with each quasisyntax introducing a new level of syntax quotation
and each unsyntax or unsyntax-splicing taking away a level of quotation.  An expression nested within n quasi-
syntax expressions must be within n unsyntax or unsyntax-splicing expressions to be evaluated.

  Use of unsyntax and unsyntax-splicing with zero or more than one subform are vaild only in splicing (list or
vector) contexts.  (unsyntax template ...) is equivalent to (unsyntax template) ..., and (unsyntax-splicing
template ...) is equivalent to (unsyntax-splicing template) ... .  These forms are primarily useful as intermediate forms in the output of the quasisyntax expander.

 
原创粉丝点击