103 lines
67 KiB
HTML
103 lines
67 KiB
HTML
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||
|
<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"/><meta name="viewport" content="width=device-width, initial-scale=0.8"/><title>5.7 Structure Type Transformer Binding</title><link rel="stylesheet" type="text/css" href="../scribble.css" title="default"/><link rel="stylesheet" type="text/css" href="extras.css" title="default"/><link rel="stylesheet" type="text/css" href="../racket.css" title="default"/><link rel="stylesheet" type="text/css" href="../manual-style.css" title="default"/><link rel="stylesheet" type="text/css" href="../manual-racket.css" title="default"/><link rel="stylesheet" type="text/css" href="../manual-racket.css" title="default"/><link rel="stylesheet" type="text/css" href="../doc-site.css" title="default"/><script type="text/javascript" src="../scribble-common.js"></script><script type="text/javascript" src="../manual-racket.js"></script><script type="text/javascript" src="../manual-racket.js"></script><script type="text/javascript" src="../doc-site.js"></script><script type="text/javascript" src="../local-redirect/local-redirect.js"></script><script type="text/javascript" src="../local-redirect/local-user-redirect.js"></script><!--[if IE 6]><style type="text/css">.SIEHidden { overflow: hidden; }</style><![endif]--></head><body id="doc-racket-lang-org"><div class="tocset"><div class="tocview"><div class="tocviewlist tocviewlisttopspace"><div class="tocviewtitle"><table cellspacing="0" cellpadding="0"><tr><td style="width: 1em;"><a href="javascript:void(0);" title="Expand/Collapse" class="tocviewtoggle" onclick="TocviewToggle(this,"tocview_0");">►</a></td><td></td><td><a href="index.html" class="tocviewlink" data-pltdoc="x">The Racket Reference</a></td></tr></table></div><div class="tocviewsublisttop" style="display: none;" id="tocview_0"><table cellspacing="0" cellpadding="0"><tr><td align="right">1 </td><td><a href="model.html" class="tocviewlink" data-pltdoc="x">Language Model</a></td></tr><tr><td align="right">2 </td><td><a href="notation.html" class="tocviewlink" data-pltdoc="x">Notation for Documentation</a></td></tr><tr><td align="right">3 </td><td><a href="syntax.html" class="tocviewlink" data-pltdoc="x">Syntactic Forms</a></td></tr><tr><td align="right">4 </td><td><a href="data.html" class="tocviewlink" data-pltdoc="x">Datatypes</a></td></tr><tr><td align="right">5 </td><td><a href="structures.html" class="tocviewselflink" data-pltdoc="x">Structures</a></td></tr><tr><td align="right">6 </td><td><a href="mzlib_class.html" class="tocviewlink" data-pltdoc="x">Classes and Objects</a></td></tr><tr><td align="right">7 </td><td><a href="mzlib_unit.html" class="tocviewlink" data-pltdoc="x">Units</a></td></tr><tr><td align="right">8 </td><td><a href="contracts.html" class="tocviewlink" data-pltdoc="x">Contracts</a></td></tr><tr><td align="right">9 </td><td><a href="match.html" class="tocviewlink" data-pltdoc="x">Pattern Matching</a></td></tr><tr><td align="right">10 </td><td><a href="control.html" class="tocviewlink" data-pltdoc="x">Control Flow</a></td></tr><tr><td align="right">11 </td><td><a href="concurrency.html" class="tocviewlink" data-pltdoc="x">Concurrency and Parallelism</a></td></tr><tr><td align="right">12 </td><td><a href="Macros.html" class="tocviewlink" data-pltdoc="x">Macros</a></td></tr><tr><td align="right">13 </td><td><a href="input-and-output.html" class="tocviewlink" data-pltdoc="x">Input and Output</a></td></tr><tr><td align="right">14 </td><td><a href="security.html" class="tocviewlink" data-pltdoc="x">Reflection and Security</a></td></tr><tr><td align="right">15 </td><td><a href="os.html" class="tocviewlink" data-pltdoc="x">Operating System</a></td></tr><tr><td align="right">16 </td><td><a href="memory.html" class="tocviewlink" data-pltdoc="x">Memory Management</a></td></tr><tr><td align="right">17 </td><td><a href="unsafe.html" class="tocviewlink" data-pltdoc="x">Unsafe Operations</a></td></tr><tr><td align="right">18 </td><td><a href="runn
|
||
|
a <a href="syntax-model.html#%28tech._transformer%29" class="techoutside" data-pltdoc="x"><span class="techinside">transformer</span></a> binding that records the other identifiers bound
|
||
|
to the structure type, the constructor procedure, the predicate
|
||
|
procedure, and the field accessor and mutator procedures. This
|
||
|
information can be used during the expansion of other expressions via
|
||
|
<span class="RktSym"><a href="stxtrans.html#%28def._%28%28quote._~23~25kernel%29._syntax-local-value%29%29" class="RktValLink" data-pltdoc="x">syntax-local-value</a></span>.</p><p>For example, the <span class="RktSym"><a href="define-struct.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._struct%29%29" class="RktStxLink" data-pltdoc="x">struct</a></span> variant for subtypes uses the
|
||
|
base type name <span class="RktVar">t</span> to find the variable
|
||
|
<span class="RktSym">struct:</span><span class="RktVar">t</span> containing the base type’s descriptor; it
|
||
|
also folds the field accessor and mutator information for the base
|
||
|
type into the information for the subtype. As another example, the
|
||
|
<span class="RktSym"><a href="match.html#%28form._%28%28lib._racket%2Fmatch..rkt%29._match%29%29" class="RktStxLink" data-pltdoc="x">match</a></span> form uses a type name to find the predicates and field
|
||
|
accessors for the structure type. The <span class="RktSym"><a href="define-struct.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._struct%29%29" class="RktStxLink" data-pltdoc="x">struct</a></span> form in an
|
||
|
imported signature for <span class="RktSym"><a href="creatingunits.html#%28form._%28%28lib._racket%2Funit..rkt%29._unit%29%29" class="RktStxLink" data-pltdoc="x">unit</a></span> causes the <span class="RktSym"><a href="creatingunits.html#%28form._%28%28lib._racket%2Funit..rkt%29._unit%29%29" class="RktStxLink" data-pltdoc="x">unit</a></span>
|
||
|
transformer to generate information about imported structure types, so
|
||
|
that <span class="RktSym"><a href="match.html#%28form._%28%28lib._racket%2Fmatch..rkt%29._match%29%29" class="RktStxLink" data-pltdoc="x">match</a></span> and subtyping <span class="RktSym"><a href="define-struct.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._struct%29%29" class="RktStxLink" data-pltdoc="x">struct</a></span> forms work
|
||
|
within the unit.</p><p>The expansion-time information for a structure type can be represented
|
||
|
directly as a list of six elements (of the same sort that the
|
||
|
encapsulated procedure must return):</p><ul><li><p>an identifier that is bound to the structure type’s descriptor,
|
||
|
or <span class="RktVal">#f</span> if none is known;</p></li><li><p>an identifier that is bound to the structure type’s constructor,
|
||
|
or <span class="RktVal">#f</span> if none is known;</p></li><li><p>an identifier that is bound to the structure type’s predicate,
|
||
|
or <span class="RktVal">#f</span> if none is known;</p></li><li><p>a list of identifiers bound to the field accessors of the
|
||
|
structure type, optionally with <span class="RktVal">#f</span> as the list’s last
|
||
|
element. A <span class="RktVal">#f</span> as the last element indicates that the
|
||
|
structure type may have additional fields, otherwise the list is a
|
||
|
reliable indicator of the number of fields in the structure
|
||
|
type. Furthermore, the accessors are listed in reverse order for the
|
||
|
corresponding constructor arguments. (The reverse order enables
|
||
|
sharing in the lists for a subtype and its base type.)</p></li><li><p>a list of identifiers bound to the field mutators of
|
||
|
the structure type, or <span class="RktVal">#f</span> for each field that has no known
|
||
|
mutator, and optionally with an extra <span class="RktVal">#f</span> as the list’s last
|
||
|
element (if the accessor list has such a <span class="RktVal">#f</span>). The list’s
|
||
|
order and the meaning of a final <span class="RktVal">#f</span> are the same as for the
|
||
|
accessor identifiers, and the length of the mutator list is the same
|
||
|
as the accessor list’s length.</p></li><li><p>an identifier that determines a super-type for the structure
|
||
|
type, <span class="RktVal">#f</span> if the super-type (if any) is unknown, or
|
||
|
<span class="RktVal">#t</span> if there is no super-type. If a super-type is specified,
|
||
|
the identifier is also bound to structure-type expansion-time
|
||
|
information.</p></li></ul><p>Instead of this direct representation, the representation can be a
|
||
|
structure created by <span class="RktSym"><a href="structinfo.html#%28def._%28%28lib._racket%2Fstruct-info..rkt%29._make-struct-info%29%29" class="RktValLink" data-pltdoc="x">make-struct-info</a></span> (or an instance of a
|
||
|
subtype of <span class="RktSym"><a href="structinfo.html#%28def._%28%28lib._racket%2Fstruct-info..rkt%29._struct~3astruct-info%29%29" class="RktValLink" data-pltdoc="x">struct:struct-info</a></span>), which encapsulates a
|
||
|
procedure that takes no arguments and returns a list of six
|
||
|
elements. Alternately, the representation can be a structure whose
|
||
|
type has the <span class="RktSym"><a href="structinfo.html#%28def._%28%28lib._racket%2Fstruct-info..rkt%29._prop~3astruct-info%29%29" class="RktValLink" data-pltdoc="x">prop:struct-info</a></span> <a href="structprops.html#%28tech._structure._type._property%29" class="techoutside" data-pltdoc="x"><span class="techinside">structure type property</span></a>.
|
||
|
Finally, the representation can be an instance of a structure type
|
||
|
derived from <span class="RktSym"><a href="structinfo.html#%28def._%28%28lib._racket%2Fstruct-info..rkt%29._struct~3astruct-info%29%29" class="RktValLink" data-pltdoc="x">struct:struct-info</a></span> or with the
|
||
|
<span class="RktSym"><a href="structinfo.html#%28def._%28%28lib._racket%2Fstruct-info..rkt%29._prop~3astruct-info%29%29" class="RktValLink" data-pltdoc="x">prop:struct-info</a></span> property that also implements
|
||
|
<span class="RktSym"><a href="procedures.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._prop~3aprocedure%29%29" class="RktValLink" data-pltdoc="x">prop:procedure</a></span>, and where the instance is further is wrapped
|
||
|
by <span class="RktSym"><a href="stxtrans.html#%28def._%28%28quote._~23~25kernel%29._make-set%21-transformer%29%29" class="RktValLink" data-pltdoc="x">make-set!-transformer</a></span>. In addition, the representation may
|
||
|
implement the <span class="RktSym"><a href="structinfo.html#%28def._%28%28lib._racket%2Fstruct-info..rkt%29._prop~3astruct-auto-info%29%29" class="RktValLink" data-pltdoc="x">prop:struct-auto-info</a></span> and
|
||
|
<span class="RktSym"><a href="structinfo.html#%28def._%28%28lib._racket%2Fstruct-info..rkt%29._prop~3astruct-field-info%29%29" class="RktValLink" data-pltdoc="x">prop:struct-field-info</a></span> properties.</p><p>Use <span class="RktSym"><a href="structinfo.html#%28def._%28%28lib._racket%2Fstruct-info..rkt%29._struct-info~3f%29%29" class="RktValLink" data-pltdoc="x">struct-info?</a></span> to recognize all allowed forms of the
|
||
|
information, and use <span class="RktSym"><a href="structinfo.html#%28def._%28%28lib._racket%2Fstruct-info..rkt%29._extract-struct-info%29%29" class="RktValLink" data-pltdoc="x">extract-struct-info</a></span> to obtain a list
|
||
|
from any representation.</p><p>The implementor of a syntactic form can expect users of the form to
|
||
|
know what kind of information is available about a structure type. For
|
||
|
example, the <span class="RktSym"><a href="match.html#%28form._%28%28lib._racket%2Fmatch..rkt%29._match%29%29" class="RktStxLink" data-pltdoc="x">match</a></span> implementation works with structure
|
||
|
information containing an incomplete set of accessor bindings, because
|
||
|
the user is assumed to know what information is available in the
|
||
|
context of the <span class="RktSym"><a href="match.html#%28form._%28%28lib._racket%2Fmatch..rkt%29._match%29%29" class="RktStxLink" data-pltdoc="x">match</a></span> expression. In particular, the
|
||
|
<span class="RktSym"><a href="match.html#%28form._%28%28lib._racket%2Fmatch..rkt%29._match%29%29" class="RktStxLink" data-pltdoc="x">match</a></span> expression can appear in a <span class="RktSym"><a href="creatingunits.html#%28form._%28%28lib._racket%2Funit..rkt%29._unit%29%29" class="RktStxLink" data-pltdoc="x">unit</a></span> form with an
|
||
|
imported structure type, in which case the user is expected to know
|
||
|
the set of fields that are listed in the signature for the structure
|
||
|
type.</p><p><div class="SIntrapara"><table cellspacing="0" cellpadding="0" class="defmodule"><tr><td align="left"><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym"><a href="require.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._require%29%29" class="RktStxLink" data-pltdoc="x">require</a></span><span class="stt"> </span><a href="structinfo.html" class="RktModLink" data-pltdoc="x"><span class="RktSym">racket/struct-info</span></a><span class="RktPn">)</span></td><td align="right"><span class="RpackageSpec"><span class="Smaller"> package:</span> <a href="https://pkgs.racket-lang.org/package/base" title="Install this package using `raco pkg install base`"><span class="stt">base</span></a></span></td></tr></table></div><div class="SIntrapara">The bindings documented in this section are provided by the <a href="structinfo.html" class="RktModLink" data-pltdoc="x"><span class="RktSym">racket/struct-info</span></a> library, not <a href="index.html" class="RktModLink" data-pltdoc="x"><span class="RktSym">racket/base</span></a> or <a href="index.html" class="RktModLink" data-pltdoc="x"><span class="RktSym">racket</span></a>.</div></p><p><div class="SIntrapara"><blockquote class="SVInsetFlow"><table cellspacing="0" cellpadding="0" class="boxed RBoxed"><tr><td><blockquote class="SubFlow"><div class="RBackgroundLabel SIEHidden"><div class="RBackgroundLabelInner"><p>procedure</p></div></div><p class="RForeground"><span class="RktPn">(</span><a name="(def._((lib._racket/struct-info..rkt)._struct-info~3f))"></a><span title="Provided from: racket/struct-info | Package: base"><span class="RktSym"><a href="structinfo.html#%28def._%28%28lib._racket%2Fstruct-info..rkt%29._struct-info~3f%29%29" class="RktValDef RktValLink" data-pltdoc="x">struct-info?</a></span></span><span class="hspace"> </span><span class="RktVar">v</span><span class="RktPn">)</span><span class="hspace"> </span>→<span class="hspace"> </span><span class="RktSym"><a href="booleans.html#%28def._%28%28quote._~23~25kernel%29._boolean~3f%29%29" class="RktValLink" data-pltdoc="x">boolean?</a></span></p></blockquote></td></tr><tr><td><span class="hspace"> </span><span class="RktVar">v</span><span class="hspace"> </span>:<span class="hspace"> </span><span class="RktSym"><a href="data-structure-contracts.html#%28def._%28%28lib._racket%2Fcontract%2Fprivate%2Fmisc..rkt%29._any%2Fc%29%29" class="RktValLink" data-pltdoc="x">any/c</a></span></td></tr></table></blockquote></div><div class="SIntrapara">Returns <span class="RktVal">#t</span> if <span class="RktVar">v</span> is either a six-element list with
|
||
|
the correct shape for representing structure-type information, a
|
||
|
procedure encapsulated by <span class="RktSym"><a href="structinfo.html#%28def._%28%28lib._racket%2Fstruct-info..rkt%29._make-struct-info%29%29" class="RktValLink" data-pltdoc="x">make-struct-info</a></span>, a structure with
|
||
|
the <span class="RktSym"><a href="structinfo.html#%28def._%28%28lib._racket%2Fstruct-info..rkt%29._prop~3astruct-info%29%29" class="RktValLink" data-pltdoc="x">prop:struct-info</a></span> property, or a structure type derived
|
||
|
from <span class="RktSym"><a href="structinfo.html#%28def._%28%28lib._racket%2Fstruct-info..rkt%29._struct~3astruct-info%29%29" class="RktValLink" data-pltdoc="x">struct:struct-info</a></span> or with <span class="RktSym"><a href="structinfo.html#%28def._%28%28lib._racket%2Fstruct-info..rkt%29._prop~3astruct-info%29%29" class="RktValLink" data-pltdoc="x">prop:struct-info</a></span> and
|
||
|
wrapped with <span class="RktSym"><a href="stxtrans.html#%28def._%28%28quote._~23~25kernel%29._make-set%21-transformer%29%29" class="RktValLink" data-pltdoc="x">make-set!-transformer</a></span>.</div></p><p><div class="SIntrapara"><blockquote class="SVInsetFlow"><table cellspacing="0" cellpadding="0" class="boxed RBoxed"><tr><td><blockquote class="SubFlow"><div class="RBackgroundLabel SIEHidden"><div class="RBackgroundLabelInner"><p>procedure</p></div></div><p class="RForeground"><span class="RktPn">(</span><a name="(def._((lib._racket/struct-info..rkt)._checked-struct-info~3f))"></a><span title="Provided from: racket/struct-info | Package: base"><span class="RktSym"><a href="structinfo.html#%28def._%28%28lib._racket%2Fstruct-info..rkt%29._checked-struct-info~3f%29%29" class="RktValDef RktValLink" data-pltdoc="x">checked-struct-info?</a></span></span><span class="hspace"> </span><span class="RktVar">v</span><span class="RktPn">)</span><span class="hspace"> </span>→<span class="hspace"> </span><span class="RktSym"><a href="booleans.html#%28def._%28%28quote._~23~25kernel%29._boolean~3f%29%29" class="RktValLink" data-pltdoc="x">boolean?</a></span></p></blockquote></td></tr><tr><td><span class="hspace"> </span><span class="RktVar">v</span><span class="hspace"> </span>:<span class="hspace"> </span><span class="RktSym"><a href="data-structure-contracts.html#%28def._%28%28lib._racket%2Fcontract%2Fprivate%2Fmisc..rkt%29._any%2Fc%29%29" class="RktValLink" data-pltdoc="x">any/c</a></span></td></tr></table></blockquote></div><div class="SIntrapara">Returns <span class="RktVal">#t</span> if <span class="RktVar">v</span> is a procedure encapsulated by
|
||
|
<span class="RktSym"><a href="structinfo.html#%28def._%28%28lib._racket%2Fstruct-info..rkt%29._make-struct-info%29%29" class="RktValLink" data-pltdoc="x">make-struct-info</a></span> and produced by <span class="RktSym"><a href="define-struct.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._struct%29%29" class="RktStxLink" data-pltdoc="x">struct</a></span>, but
|
||
|
only when no parent type is specified or the parent type is also
|
||
|
specified through a transformer binding to such a value.</div></p><p><div class="SIntrapara"><blockquote class="SVInsetFlow"><table cellspacing="0" cellpadding="0" class="boxed RBoxed"><tr><td><blockquote class="SubFlow"><div class="RBackgroundLabel SIEHidden"><div class="RBackgroundLabelInner"><p>procedure</p></div></div><p class="RForeground"><span class="RktPn">(</span><a name="(def._((lib._racket/struct-info..rkt)._make-struct-info))"></a><span title="Provided from: racket/struct-info | Package: base"><span class="RktSym"><a href="structinfo.html#%28def._%28%28lib._racket%2Fstruct-info..rkt%29._make-struct-info%29%29" class="RktValDef RktValLink" data-pltdoc="x">make-struct-info</a></span></span><span class="hspace"> </span><span class="RktVar">thunk</span><span class="RktPn">)</span><span class="hspace"> </span>→<span class="hspace"> </span><span class="RktSym"><a href="structinfo.html#%28def._%28%28lib._racket%2Fstruct-info..rkt%29._struct-info~3f%29%29" class="RktValLink" data-pltdoc="x">struct-info?</a></span></p></blockquote></td></tr><tr><td><span class="hspace"> </span><span class="RktVar">thunk</span><span class="hspace"> </span>:<span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym"><a href="function-contracts.html#%28form._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._-~3e%29%29" class="RktStxLink" data-pltdoc="x"><span class="nobreak">-></span></a></span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym"><a href="data-structure-contracts.html#%28def._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._and%2Fc%29%29" class="RktValLink" data-pltdoc="x">and/c</a></span><span class="hspace"> </span><span class="RktSym"><a href="structinfo.html#%28def._%28%28lib._racket%2Fstruct-info..rkt%29._struct-info~3f%29%29" class="RktValLink" data-pltdoc="x">struct-info?</a></span><span class="hspace"> </span><span class="RktSym"><a href="pairs.html#%28def._%28%28quote._~23~25kernel%29._list~3f%29%29" class="RktValLink" data-pltdoc="x">list?</a></span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr></table></blockquote></div><div class="SIntrapara">Encapsulates a thunk that returns structure-type information in list
|
||
|
form. Note that accessors are listed in reverse order, as mentioned in <a href="structinfo.html" data-pltdoc="x">Structure Type Transformer Binding</a>.
|
||
|
Note that the field names are not well-defined for struct-type informations
|
||
|
that are created with this method, so it is likely not going to work well
|
||
|
with forms like <span class="RktSym"><a href="struct-copy.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._struct-copy%29%29" class="RktStxLink" data-pltdoc="x">struct-copy</a></span> and <span class="RktSym"><a href="match.html#%28form._%28%28lib._racket%2Fmatch..rkt%29._struct%2A%29%29" class="RktStxLink" data-pltdoc="x">struct*</a></span>.</div></p><p><div class="SIntrapara">Examples:</div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="stt">> </span><span class="RktPn">(</span><span class="RktSym"><a href="define.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define%29%29" class="RktStxLink" data-pltdoc="x">define</a></span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym">new-pair?</span><span class="hspace"> </span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym"><a href="Writing.html#%28def._%28%28lib._racket%2Fprivate%2Fmisc..rkt%29._displayln%29%29" class="RktValLink" data-pltdoc="x">displayln</a></span><span class="hspace"> </span><span class="RktVal">"new pair?"</span><span class="RktPn">)</span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym"><a href="pairs.html#%28def._%28%28quote._~23~25kernel%29._pair~3f%29%29" class="RktValLink" data-pltdoc="x">pair?</a></span><span class="hspace"> </span><span class="RktSym">x</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="stt">> </span><span class="RktPn">(</span><span class="RktSym"><a href="define.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define%29%29" class="RktStxLink" data-pltdoc="x">define</a></span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym">new-car</span><span class="hspace"> </span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym"><a href="Writing.html#%28def._%28%28lib._racket%2Fprivate%2Fmisc..rkt%29._displayln%29%29" class="RktValLink" data-pltdoc="x">displayln</a></span><span class="hspace"> </span><span class="RktVal">"new car"</span><span class="RktPn">)</span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym"><a href="pairs.html#%28def._%28%28quote._~23~25kernel%29._car%29%29" class="RktValLink" data-pltdoc="x">car</a></span><span class="hspace"> </span><span class="RktSym">x</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="stt">> </span><span class="RktPn">(</span><span class="RktSym"><a href="define.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define%29%29" class="RktStxLink" data-pltdoc="x">define</a></span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym">new-cdr</span><span class="hspace"> </span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym"><a href="Writing.html#%28def._%28%28lib._racket%2Fprivate%2Fmisc..rkt%29._displayln%29%29" class="RktValLink" data-pltdoc="x">displayln</a></span><span class="hspace"> </span><span class="RktVal">"new cdr"</span><span class="RktPn">)</span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym"><a href="pairs.html#%28def._%28%28quote._~23~25kernel%29._cdr%29%29" class="RktValLink" data-pltdoc="x">cdr</a></span><span class="hspace"> </span><span class="RktSym">x</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="stt">> </span><span class="RktPn">(</span><span class="RktSym"><a href="define.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define-syntax%29%29" class="RktStxLink" data-pltdoc="x">define-syntax</a></span><span class="hspace"> </span><span class="Rkt
|
||
|
by <span class="RktVar">v</span>.</div></p><p><div class="SIntrapara"><blockquote class="SVInsetFlow"><table cellspacing="0" cellpadding="0" class="boxed RBoxed"><tr><td><blockquote class="SubFlow"><div class="RBackgroundLabel SIEHidden"><div class="RBackgroundLabelInner"><p>value</p></div></div><p class="RForeground"><a name="(def._((lib._racket/struct-info..rkt)._struct~3astruct-info))"></a><span title="Provided from: racket/struct-info | Package: base"><span class="RktSym"><a href="structinfo.html#%28def._%28%28lib._racket%2Fstruct-info..rkt%29._struct~3astruct-info%29%29" class="RktValDef RktValLink" data-pltdoc="x">struct:struct-info</a></span></span><span class="hspace"> </span>:<span class="hspace"> </span><span class="RktSym"><a href="structutils.html#%28def._%28%28quote._~23~25kernel%29._struct-type~3f%29%29" class="RktValLink" data-pltdoc="x">struct-type?</a></span></p></blockquote></td></tr></table></blockquote></div><div class="SIntrapara">The <a href="define-struct.html#%28tech._structure._type._descriptor%29" class="techoutside" data-pltdoc="x"><span class="techinside">structure type descriptor</span></a> for the structure type returned
|
||
|
by <span class="RktSym"><a href="structinfo.html#%28def._%28%28lib._racket%2Fstruct-info..rkt%29._make-struct-info%29%29" class="RktValLink" data-pltdoc="x">make-struct-info</a></span>. This <a href="define-struct.html#%28tech._structure._type._descriptor%29" class="techoutside" data-pltdoc="x"><span class="techinside">structure type descriptor</span></a> is
|
||
|
mostly useful for creating structure subtypes. The structure type
|
||
|
includes a guard that checks an instance’s first field in the same way
|
||
|
as <span class="RktSym"><a href="structinfo.html#%28def._%28%28lib._racket%2Fstruct-info..rkt%29._make-struct-info%29%29" class="RktValLink" data-pltdoc="x">make-struct-info</a></span>.</div></p><p><div class="SIntrapara"><blockquote class="SVInsetFlow"><table cellspacing="0" cellpadding="0" class="boxed RBoxed"><tr><td><blockquote class="SubFlow"><div class="RBackgroundLabel SIEHidden"><div class="RBackgroundLabelInner"><p>value</p></div></div><p class="RForeground"><a name="(def._((lib._racket/struct-info..rkt)._prop~3astruct-info))"></a><span title="Provided from: racket/struct-info | Package: base"><span class="RktSym"><a href="structinfo.html#%28def._%28%28lib._racket%2Fstruct-info..rkt%29._prop~3astruct-info%29%29" class="RktValDef RktValLink" data-pltdoc="x">prop:struct-info</a></span></span><span class="hspace"> </span>:<span class="hspace"> </span><span class="RktSym"><a href="structprops.html#%28def._%28%28quote._~23~25kernel%29._struct-type-property~3f%29%29" class="RktValLink" data-pltdoc="x">struct-type-property?</a></span></p></blockquote></td></tr></table></blockquote></div><div class="SIntrapara">The <a href="structprops.html#%28tech._structure._type._property%29" class="techoutside" data-pltdoc="x"><span class="techinside">structure type property</span></a> for creating new structure types
|
||
|
like <span class="RktSym"><a href="structinfo.html#%28def._%28%28lib._racket%2Fstruct-info..rkt%29._struct~3astruct-info%29%29" class="RktValLink" data-pltdoc="x">struct:struct-info</a></span>. The property value must be a procedure
|
||
|
of one argument that takes an instance structure and returns
|
||
|
structure-type information in list form.</div></p><p><div class="SIntrapara"><blockquote class="SVInsetFlow"><table cellspacing="0" cellpadding="0" class="boxed RBoxed"><tr><td><table cellspacing="0" cellpadding="0" class="together"><tr><td><blockquote class="SubFlow"><div class="RBackgroundLabel SIEHidden"><div class="RBackgroundLabelInner"><p>value</p></div></div><p class="RForeground"><a name="(def._((lib._racket/struct-info..rkt)._prop~3astruct-auto-info))"></a><span title="Provided from: racket/struct-info | Package: base"><span class="RktSym"><a href="structinfo.html#%28def._%28%28lib._racket%2Fstruct-info..rkt%29._prop~3astruct-auto-info%29%29" class="RktValDef RktValLink" data-pltdoc="x">prop:struct-auto-info</a></span></span><span class="hspace"> </span>:<span class="hspace"> </span><span class="RktSym"><a href="structprops.html#%28def._%28%28quote._~23~25kernel%29._struct-type-property~3f%29%29" class="RktValLink" data-pltdoc="x">struct-type-property?</a></span></p></blockquote></td></tr></table></td></tr><tr><td><table cellspacing="0" cellpadding="0" class="together"><tr><td><blockquote class="SubFlow"><div class="RBackgroundLabel SIEHidden"><div class="RBackgroundLabelInner"><p>procedure</p></div></div><p class="RForeground"><span class="RktPn">(</span><a name="(def._((lib._racket/struct-info..rkt)._struct-auto-info~3f))"></a><span title="Provided from: racket/struct-info | Package: base"><span class="RktSym"><a href="structinfo.html#%28def._%28%28lib._racket%2Fstruct-info..rkt%29._struct-auto-info~3f%29%29" class="RktValDef RktValLink" data-pltdoc="x">struct-auto-info?</a></span></span><span class="hspace"> </span><span class="RktVar">v</span><span class="RktPn">)</span><span class="hspace"> </span>→<span class="hspace"> </span><span class="RktSym"><a href="booleans.html#%28def._%28%28quote._~23~25kernel%29._boolean~3f%29%29" class="RktValLink" data-pltdoc="x">boolean?</a></span></p></blockquote></td></tr><tr><td><span class="hspace"> </span><span class="RktVar">v</span><span class="hspace"> </span>:<span class="hspace"> </span><span class="RktSym"><a href="data-structure-contracts.html#%28def._%28%28lib._racket%2Fcontract%2Fprivate%2Fmisc..rkt%29._any%2Fc%29%29" class="RktValLink" data-pltdoc="x">any/c</a></span></td></tr></table></td></tr><tr><td><table cellspacing="0" cellpadding="0" class="together"><tr><td><blockquote class="SubFlow"><div class="RBackgroundLabel SIEHidden"><div class="RBackgroundLabelInner"><p>procedure</p></div></div><p class="RForeground"><span class="RktPn">(</span><a name="(def._((lib._racket/struct-info..rkt)._struct-auto-info-lists))"></a><span title="Provided from: racket/struct-info | Package: base"><span class="RktSym"><a href="structinfo.html#%28def._%28%28lib._racket%2Fstruct-info..rkt%29._struct-auto-info-lists%29%29" class="RktValDef RktValLink" data-pltdoc="x">struct-auto-info-lists</a></span></span><span class="hspace"> </span><span class="RktVar">sai</span><span class="RktPn">)</span></p></blockquote></td></tr><tr><td><span class="hspace"> </span>→<span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym"><a href="data-structure-contracts.html#%28def._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._list%2Fc%29%29" class="RktValLink" data-pltdoc="x">list/c</a></span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym"><a href="data-structure-contracts.html#%28def._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._listof%29%29" class="RktValLink" data-pltdoc="x">listof</a></span><span class="hspace"> </span><span class="RktSym"><a href="stxops.html#%28def._%28%28lib._racket%2Fprivate%2Fstx..rkt%29._identifier~3f%29%29" class="RktValLink" data-pltdoc="x">identifier?</a></span><span class="RktPn">)</span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym"><a href="data-structure-contracts.html#%28def._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._listof%29%29" class="RktValLink" data-pltdoc="x">listof</a></span><span class="hspac
|
||
|
static information about which of the accessor and mutator identifiers
|
||
|
for a structure type correspond to <span class="RktPn">#:auto</span> fields (so that
|
||
|
they have no corresponding argument in the constructor). The property
|
||
|
value must be a procedure that accepts an instance structure to which
|
||
|
the property is given, and the result must be two lists of identifiers
|
||
|
suitable as a result from <span class="RktSym"><a href="structinfo.html#%28def._%28%28lib._racket%2Fstruct-info..rkt%29._struct-auto-info-lists%29%29" class="RktValLink" data-pltdoc="x">struct-auto-info-lists</a></span>.</div></p><p>The <span class="RktSym"><a href="structinfo.html#%28def._%28%28lib._racket%2Fstruct-info..rkt%29._struct-auto-info~3f%29%29" class="RktValLink" data-pltdoc="x">struct-auto-info?</a></span> predicate recognizes values that
|
||
|
implement the <span class="RktSym"><a href="structinfo.html#%28def._%28%28lib._racket%2Fstruct-info..rkt%29._prop~3astruct-auto-info%29%29" class="RktValLink" data-pltdoc="x">prop:struct-auto-info</a></span> property.</p><p>The <span class="RktSym"><a href="structinfo.html#%28def._%28%28lib._racket%2Fstruct-info..rkt%29._struct-auto-info-lists%29%29" class="RktValLink" data-pltdoc="x">struct-auto-info-lists</a></span> function extracts two lists of
|
||
|
identifiers from a value that implements the
|
||
|
<span class="RktSym"><a href="structinfo.html#%28def._%28%28lib._racket%2Fstruct-info..rkt%29._prop~3astruct-auto-info%29%29" class="RktValLink" data-pltdoc="x">prop:struct-auto-info</a></span> property. The first list should be a
|
||
|
subset of the accessor identifiers for the structure type described by
|
||
|
<span class="RktVar">sai</span>, and the second list should be a subset of the mutator
|
||
|
identifiers. The two subsets correspond to <span class="RktPn">#:auto</span> fields.</p><p><div class="SIntrapara"><blockquote class="SVInsetFlow"><table cellspacing="0" cellpadding="0" class="boxed RBoxed"><tr><td><table cellspacing="0" cellpadding="0" class="together"><tr><td><blockquote class="SubFlow"><div class="RBackgroundLabel SIEHidden"><div class="RBackgroundLabelInner"><p>value</p></div></div><p class="RForeground"><a name="(def._((lib._racket/struct-info..rkt)._prop~3astruct-field-info))"></a><span title="Provided from: racket/struct-info | Package: base"><span class="RktSym"><a href="structinfo.html#%28def._%28%28lib._racket%2Fstruct-info..rkt%29._prop~3astruct-field-info%29%29" class="RktValDef RktValLink" data-pltdoc="x">prop:struct-field-info</a></span></span><span class="hspace"> </span>:<span class="hspace"> </span><span class="RktSym"><a href="structprops.html#%28def._%28%28quote._~23~25kernel%29._struct-type-property~3f%29%29" class="RktValLink" data-pltdoc="x">struct-type-property?</a></span></p></blockquote></td></tr></table></td></tr><tr><td><table cellspacing="0" cellpadding="0" class="together"><tr><td><blockquote class="SubFlow"><div class="RBackgroundLabel SIEHidden"><div class="RBackgroundLabelInner"><p>procedure</p></div></div><p class="RForeground"><span class="RktPn">(</span><a name="(def._((lib._racket/struct-info..rkt)._struct-field-info~3f))"></a><span title="Provided from: racket/struct-info | Package: base"><span class="RktSym"><a href="structinfo.html#%28def._%28%28lib._racket%2Fstruct-info..rkt%29._struct-field-info~3f%29%29" class="RktValDef RktValLink" data-pltdoc="x">struct-field-info?</a></span></span><span class="hspace"> </span><span class="RktVar">v</span><span class="RktPn">)</span><span class="hspace"> </span>→<span class="hspace"> </span><span class="RktSym"><a href="booleans.html#%28def._%28%28quote._~23~25kernel%29._boolean~3f%29%29" class="RktValLink" data-pltdoc="x">boolean?</a></span></p></blockquote></td></tr><tr><td><span class="hspace"> </span><span class="RktVar">v</span><span class="hspace"> </span>:<span class="hspace"> </span><span class="RktSym"><a href="data-structure-contracts.html#%28def._%28%28lib._racket%2Fcontract%2Fprivate%2Fmisc..rkt%29._any%2Fc%29%29" class="RktValLink" data-pltdoc="x">any/c</a></span></td></tr></table></td></tr><tr><td><table cellspacing="0" cellpadding="0" class="together"><tr><td><blockquote class="SubFlow"><div class="RBackgroundLabel SIEHidden"><div class="RBackgroundLabelInner"><p>procedure</p></div></div><p class="RForeground"><span class="RktPn">(</span><a name="(def._((lib._racket/struct-info..rkt)._struct-field-info-list))"></a><span title="Provided from: racket/struct-info | Package: base"><span class="RktSym"><a href="structinfo.html#%28def._%28%28lib._racket%2Fstruct-info..rkt%29._struct-field-info-list%29%29" class="RktValDef RktValLink" data-pltdoc="x">struct-field-info-list</a></span></span><span class="hspace"> </span><span class="RktVar">sfi</span><span class="RktPn">)</span><span class="hspace"> </span>→<span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym"><a href="data-structure-contracts.html#%28def._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._listof%29%29" class="RktValLink" data-pltdoc="x">listof</a></span><span class="hspace"> </span><span class="RktSym"><a href="symbols.html#%28def._%28%28quote._~23~25kernel%29._symbol~3f%29%29" class="RktValLink" data-pltdoc="x">symbol?</a></span><span class="RktPn">)</span></p></blockquote></td></tr><tr><td><span class="hspace"> </span><span class="RktVar">sfi</span><span class="hspace"> </span>:<span class="hspace"> </span><span class="RktSym"><a href="structinfo.html#%28def._%28%28lib._racket%2Fstruct-info..rkt%29._struct-field-info~3f%29%29" class="RktValLink" data-pltdoc="x">struct-field-info?</a></span></td></tr></table></td></tr></table></blockquote></div><div class="SIntrapara">The <span class="RktSym"><a href="structinfo.html#%28def._%28%28lib._rac
|
||
|
static information about field names in a structure type. The property
|
||
|
value must be a procedure that accepts an instance structure to which
|
||
|
the property is given, and the result must be a list of symbols
|
||
|
suitable as a result from <span class="RktSym"><a href="structinfo.html#%28def._%28%28lib._racket%2Fstruct-info..rkt%29._struct-field-info-list%29%29" class="RktValLink" data-pltdoc="x">struct-field-info-list</a></span>.</div></p><p>The <span class="RktSym"><a href="structinfo.html#%28def._%28%28lib._racket%2Fstruct-info..rkt%29._struct-field-info~3f%29%29" class="RktValLink" data-pltdoc="x">struct-field-info?</a></span> predicate recognizes values that
|
||
|
implement the <span class="RktSym"><a href="structinfo.html#%28def._%28%28lib._racket%2Fstruct-info..rkt%29._prop~3astruct-field-info%29%29" class="RktValLink" data-pltdoc="x">prop:struct-field-info</a></span> property.</p><p>The <span class="RktSym"><a href="structinfo.html#%28def._%28%28lib._racket%2Fstruct-info..rkt%29._struct-field-info-list%29%29" class="RktValLink" data-pltdoc="x">struct-field-info-list</a></span> function extracts a list of
|
||
|
symbols from a value that implements the <span class="RktSym"><a href="structinfo.html#%28def._%28%28lib._racket%2Fstruct-info..rkt%29._prop~3astruct-field-info%29%29" class="RktValLink" data-pltdoc="x">prop:struct-field-info</a></span> property.
|
||
|
The list should contain every immediate field name
|
||
|
(that is, not including fields from its super struct type)
|
||
|
in the reverse order.</p><p><div class="SIntrapara">Examples:</div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="stt">> </span><span class="RktPn">(</span><span class="RktSym"><a href="define-struct.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._struct%29%29" class="RktStxLink" data-pltdoc="x">struct</a></span><span class="hspace"> </span><span class="RktSym">foo</span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="stt">> </span><span class="RktPn">(</span><span class="RktSym"><a href="define-struct.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._struct%29%29" class="RktStxLink" data-pltdoc="x">struct</a></span><span class="hspace"> </span><span class="RktSym">bar</span><span class="hspace"> </span><span class="RktSym">foo</span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym">y</span><span class="hspace"> </span><span class="RktSym">z</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="stt">> </span><span class="RktPn">(</span><span class="RktSym"><a href="define.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define-syntax%29%29" class="RktStxLink" data-pltdoc="x">define-syntax</a></span><span class="hspace"> </span><span class="RktPn">(</span><span class="RktSym">get-bar-field-names</span><span class="hspace"> </span><span class="RktSym">stx</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace"> </span><span class="hspace"> </span><span class="RktRdr">#`</span><span class="RktVal">'</span><span class="RktVal">#,</span><span class="RktVal">(</span><span class="RktVal">struct-field-info-list</span><span class="hspace"> </span><span class="RktVal">(</span><span class="RktVal">syntax-local-value</span><span class="hspace"> </span><span class="RktVal">#'</span><span class="RktVal">bar</span><span class="RktVal">)</span><span class="RktVal">)</span><span class="RktPn">)</span></td></tr></table></td></tr><tr><td><span class="stt">> </span><span class="RktPn">(</span><span class="RktSym">get-bar-field-names</span><span class="RktPn">)</span></td></tr><tr><td><p><span class="RktRes">'(z y)</span></p></td></tr></table></blockquote></div></p><p class="SHistory">Added in version 7.7.0.9 of package <span class="stt">base</span>.</p><div class="navsetbottom"><span class="navleft"><form class="searchform"><input class="searchbox" id="searchbox" type="text" tabindex="1" placeholder="...search manuals..." title="Enter a search string to search the manuals" onkeypress="return DoSearchKey(event, this, "8.6", "../");"/></form> <a href="https://docs.racket-lang.org/index.html" title="up to the documentation top" data-pltdoc="x" onclick="return GotoPLTRoot("8.6");">top</a><span class="tocsettoggle"> <a href="javascript:void(0);" title="show/hide table of contents" onclick="TocsetToggle();">contents</a></span></span><span class="navright"> <a href="structutils.html" title="backward to "5.6 Structure Utilities"" data-pltdoc="x">← prev</a> <a href="structures.html" title="up to "5 Structures"" data-pltdoc="x">up</a> <a href="mzlib_class.html" title="forward to "6 Classes and Objects"" data-pltdoc="x">next →</a></span> </div></div></div><div id="contextindicator"> </div></body></html>
|