This file is indexed.

/usr/share/doc/racket/redex/redex2015.html is in racket-doc 6.3-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
<!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"/><title>2&nbsp;Long Tutorial</title><link rel="stylesheet" type="text/css" href="../scribble.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,&quot;tocview_0&quot;);">&#9660;</a></td><td></td><td><a href="index.html" class="tocviewlink" data-pltdoc="x">Redex:<span class="mywbr"> &nbsp;</span> Practical Semantics Engineering</a></td></tr></table></div><div class="tocviewsublisttop" style="display: block;" id="tocview_0"><table cellspacing="0" cellpadding="0"><tr><td align="right">1&nbsp;</td><td><a href="tutorial.html" class="tocviewlink" data-pltdoc="x">Amb:<span class="mywbr"> &nbsp;</span> A Redex Tutorial</a></td></tr><tr><td align="right">2&nbsp;</td><td><a href="" class="tocviewselflink" data-pltdoc="x">Long Tutorial</a></td></tr><tr><td align="right">3&nbsp;</td><td><a href="fri-mor.html" class="tocviewlink" data-pltdoc="x">Extended Exercises</a></td></tr><tr><td align="right">4&nbsp;</td><td><a href="The_Redex_Reference.html" class="tocviewlink" data-pltdoc="x">The Redex Reference</a></td></tr><tr><td align="right">5&nbsp;</td><td><a href="benchmark.html" class="tocviewlink" data-pltdoc="x">Automated Testing Benchmark</a></td></tr><tr><td align="right"></td><td><a href="doc-bibliography.html" class="tocviewlink" data-pltdoc="x">Bibliography</a></td></tr><tr><td align="right"></td><td><a href="doc-index.html" class="tocviewlink" data-pltdoc="x">Index</a></td></tr></table></div></div><div class="tocviewlist"><table cellspacing="0" cellpadding="0"><tr><td style="width: 1em;"><a href="javascript:void(0);" title="Expand/Collapse" class="tocviewtoggle" onclick="TocviewToggle(this,&quot;tocview_1&quot;);">&#9658;</a></td><td>2&nbsp;</td><td><a href="" class="tocviewselflink" data-pltdoc="x">Long Tutorial</a></td></tr></table><div class="tocviewsublistbottom" style="display: none;" id="tocview_1"><table cellspacing="0" cellpadding="0"><tr><td align="right">2.1&nbsp;</td><td><a href="#%28part._mon-mor%29" class="tocviewlink" data-pltdoc="x">The Theoretical Framework</a></td></tr><tr><td align="right">2.2&nbsp;</td><td><a href="#%28part._mon-aft%29" class="tocviewlink" data-pltdoc="x">Syntax and Metafunctions</a></td></tr><tr><td align="right">2.3&nbsp;</td><td><a href="#%28part._lab-mon-aft%29" class="tocviewlink" data-pltdoc="x"><span style="font-weight: bold">Lab</span> Designing Metafunctions</a></td></tr><tr><td align="right">2.4&nbsp;</td><td><a href="#%28part._tue-mor%29" class="tocviewlink" data-pltdoc="x">Reductions and Semantics</a></td></tr><tr><td align="right">2.5&nbsp;</td><td><a href="#%28part._lab-tue-mor%29" class="tocviewlink" data-pltdoc="x"><span style="font-weight: bold">Lab</span> Designing Reductions</a></td></tr><tr><td align="right">2.6&nbsp;</td><td><a href="#%28part._tue-aft%29" class="tocviewlink" data-pltdoc="x">Types and Property Testing</a></td></tr><tr><td align="right">2.7&nbsp;</td><td><a href="#%28part._lab-tue-aft%29" class="tocviewlink" data-pltdoc="x"><span style="font-weight: bold">Lab</span> Type Checking</a></td></tr><tr><td align="right">2.8&nbsp;</td><td><a href="#%28part._wed-mor%29" class="tocviewlink" data-pltdoc="x">Imperative Extensions</a></td></tr><tr><td align="right">2.9&nbsp;</td><td><a href="#%28part._lab-wed-mor%29" class="tocviewlink" data-pltdoc="x"><span style="font-weight: bold">Lab</span> Contexts and Stores</a></td></tr><tr><td align="right">2.10&nbsp;</td><td><a href="#%28part._wed-aft%29" class="tocviewlink" data-pltdoc="x">Abstract Machines</a></td></tr><tr><td align="right">2.11&nbsp;</td><td><a href="#%28part._lab-wed-aft%29" class="tocviewlink" data-pltdoc="x"><span style="font-weight: bold">Lab</span> Machine Transitions</a></td></tr><tr><td align="right">2.12&nbsp;</td><td><a href="#%28part._thu-mor%29" class="tocviewlink" data-pltdoc="x">Abstracting Abstract Machines I</a></td></tr><tr><td align="right">2.13&nbsp;</td><td><a href="#%28part._lab-thu-mor%29" class="tocviewlink" data-pltdoc="x"><span style="font-weight: bold">Lab</span> Abstracting Abstract Machines I</a></td></tr><tr><td align="right">2.14&nbsp;</td><td><a href="#%28part._thu-aft%29" class="tocviewlink" data-pltdoc="x">Abstracting Abstract Machines II</a></td></tr><tr><td align="right">2.15&nbsp;</td><td><a href="#%28part._lab-thu-aft%29" class="tocviewlink" data-pltdoc="x"><span style="font-weight: bold">Lab</span> Abstracting Abstract Machines II</a></td></tr></table></div></div></div><div class="tocsub"><div class="tocsubtitle">On this page:</div><table class="tocsublist" cellspacing="0"><tr><td><span class="tocsublinknumber">2.1<tt>&nbsp;</tt></span><a href="#%28part._mon-mor%29" class="tocsubseclink" data-pltdoc="x">The Theoretical Framework</a></td></tr><tr><td><span class="tocsublinknumber">2.2<tt>&nbsp;</tt></span><a href="#%28part._mon-aft%29" class="tocsubseclink" data-pltdoc="x">Syntax and Metafunctions</a></td></tr><tr><td><span class="tocsublinknumber">2.2.1<tt>&nbsp;</tt></span><a href="#%28part._.Developing_a_.Language%29" class="tocsubseclink" data-pltdoc="x">Developing a Language</a></td></tr><tr><td><span class="tocsublinknumber">2.2.2<tt>&nbsp;</tt></span><a href="#%28part._.Developing_.Metafunctions%29" class="tocsubseclink" data-pltdoc="x">Developing Metafunctions</a></td></tr><tr><td><span class="tocsublinknumber">2.2.3<tt>&nbsp;</tt></span><a href="#%28part._.Developing_a_.Language_2%29" class="tocsubseclink" data-pltdoc="x">Developing a Language 2</a></td></tr><tr><td><span class="tocsublinknumber">2.2.4<tt>&nbsp;</tt></span><a href="#%28part._.Extending_a_.Language__any%29" class="tocsubseclink" data-pltdoc="x">Extending a Language:<span class="mywbr"> &nbsp;</span> <span class="RktSym">any</span></a></td></tr><tr><td><span class="tocsublinknumber">2.2.5<tt>&nbsp;</tt></span><a href="#%28part._.Substitution%29" class="tocsubseclink" data-pltdoc="x">Substitution</a></td></tr><tr><td><span class="tocsublinknumber">2.3<tt>&nbsp;</tt></span><a href="#%28part._lab-mon-aft%29" class="tocsubseclink" data-pltdoc="x"><span style="font-weight: bold">Lab</span> Designing Metafunctions</a></td></tr><tr><td><span class="tocsublinknumber"></span><a href="#%28part._lma%29" class="tocsubseclink" data-pltdoc="x">Exercises</a></td></tr><tr><td><span class="tocsublinknumber">2.4<tt>&nbsp;</tt></span><a href="#%28part._tue-mor%29" class="tocsubseclink" data-pltdoc="x">Reductions and Semantics</a></td></tr><tr><td><span class="tocsublinknumber">2.4.1<tt>&nbsp;</tt></span><a href="#%28part._.Contexts__.Values%29" class="tocsubseclink" data-pltdoc="x">Contexts, Values</a></td></tr><tr><td><span class="tocsublinknumber">2.4.2<tt>&nbsp;</tt></span><a href="#%28part._.Long_.Tutorial_.Reduction_.Relations%29" class="tocsubseclink" data-pltdoc="x">Reduction Relations</a></td></tr><tr><td><span class="tocsublinknumber">2.4.3<tt>&nbsp;</tt></span><a href="#%28part._.Semantics%29" class="tocsubseclink" data-pltdoc="x">Semantics</a></td></tr><tr><td><span class="tocsublinknumber">2.4.4<tt>&nbsp;</tt></span><a href="#%28part._.What_are_.Models%29" class="tocsubseclink" data-pltdoc="x">What are Models</a></td></tr><tr><td><span class="tocsublinknumber">2.5<tt>&nbsp;</tt></span><a href="#%28part._lab-tue-mor%29" class="tocsubseclink" data-pltdoc="x"><span style="font-weight: bold">Lab</span> Designing Reductions</a></td></tr><tr><td><span class="tocsublinknumber"></span><a href="#%28part._ltm%29" class="tocsubseclink" data-pltdoc="x">Exercises</a></td></tr><tr><td><span class="tocsublinknumber">2.6<tt>&nbsp;</tt></span><a href="#%28part._tue-aft%29" class="tocsubseclink" data-pltdoc="x">Types and Property Testing</a></td></tr><tr><td><span class="tocsublinknumber">2.6.1<tt>&nbsp;</tt></span><a href="#%28part._.Types%29" class="tocsubseclink" data-pltdoc="x">Types</a></td></tr><tr><td><span class="tocsublinknumber">2.6.2<tt>&nbsp;</tt></span><a href="#%28part._.Developing_.Type_.Judgments%29" class="tocsubseclink" data-pltdoc="x">Developing Type Judgments</a></td></tr><tr><td><span class="tocsublinknumber">2.6.3<tt>&nbsp;</tt></span><a href="#%28part._.Subjection_.Reduction%29" class="tocsubseclink" data-pltdoc="x">Subjection Reduction</a></td></tr><tr><td><span class="tocsublinknumber">2.7<tt>&nbsp;</tt></span><a href="#%28part._lab-tue-aft%29" class="tocsubseclink" data-pltdoc="x"><span style="font-weight: bold">Lab</span> Type Checking</a></td></tr><tr><td><span class="tocsublinknumber"></span><a href="#%28part._lta%29" class="tocsubseclink" data-pltdoc="x">Exercises</a></td></tr><tr><td><span class="tocsublinknumber">2.8<tt>&nbsp;</tt></span><a href="#%28part._wed-mor%29" class="tocsubseclink" data-pltdoc="x">Imperative Extensions</a></td></tr><tr><td><span class="tocsublinknumber">2.8.1<tt>&nbsp;</tt></span><a href="#%28part._.Variable_.Assignment%29" class="tocsubseclink" data-pltdoc="x">Variable Assignment</a></td></tr><tr><td><span class="tocsublinknumber">2.8.2<tt>&nbsp;</tt></span><a href="#%28part._.Raising_.Exceptions%29" class="tocsubseclink" data-pltdoc="x">Raising Exceptions</a></td></tr><tr><td><span class="tocsublinknumber">2.9<tt>&nbsp;</tt></span><a href="#%28part._lab-wed-mor%29" class="tocsubseclink" data-pltdoc="x"><span style="font-weight: bold">Lab</span> Contexts and Stores</a></td></tr><tr><td><span class="tocsublinknumber"></span><a href="#%28part._lwm%29" class="tocsubseclink" data-pltdoc="x">Exercises</a></td></tr><tr><td><span class="tocsublinknumber">2.10<tt>&nbsp;</tt></span><a href="#%28part._wed-aft%29" class="tocsubseclink" data-pltdoc="x">Abstract Machines</a></td></tr><tr><td><span class="tocsublinknumber">2.10.1<tt>&nbsp;</tt></span><a href="#%28part._.C.C_.Machine%29" class="tocsubseclink" data-pltdoc="x">CC Machine</a></td></tr><tr><td><span class="tocsublinknumber">2.10.2<tt>&nbsp;</tt></span><a href="#%28part._.The_.C.K_.Machine%29" class="tocsubseclink" data-pltdoc="x">The CK Machine</a></td></tr><tr><td><span class="tocsublinknumber">2.10.3<tt>&nbsp;</tt></span><a href="#%28part._.The_.C.C-.C.K_.Theorem%29" class="tocsubseclink" data-pltdoc="x">The CC-<wbr></wbr>CK Theorem</a></td></tr><tr><td><span class="tocsublinknumber">2.10.4<tt>&nbsp;</tt></span><a href="#%28part._.The_.C.E.K_machine%29" class="tocsubseclink" data-pltdoc="x">The CEK machine</a></td></tr><tr><td><span class="tocsublinknumber">2.10.5<tt>&nbsp;</tt></span><a href="#%28part._.The_.C.E.K-.C.K_.Theorem%29" class="tocsubseclink" data-pltdoc="x">The CEK-<wbr></wbr>CK Theorem</a></td></tr><tr><td><span class="tocsublinknumber">2.11<tt>&nbsp;</tt></span><a href="#%28part._lab-wed-aft%29" class="tocsubseclink" data-pltdoc="x"><span style="font-weight: bold">Lab</span> Machine Transitions</a></td></tr><tr><td><span class="tocsublinknumber"></span><a href="#%28part._lwa%29" class="tocsubseclink" data-pltdoc="x">Exercises</a></td></tr><tr><td><span class="tocsublinknumber">2.12<tt>&nbsp;</tt></span><a href="#%28part._thu-mor%29" class="tocsubseclink" data-pltdoc="x">Abstracting Abstract Machines I</a></td></tr><tr><td><span class="tocsublinknumber">2.13<tt>&nbsp;</tt></span><a href="#%28part._lab-thu-mor%29" class="tocsubseclink" data-pltdoc="x"><span style="font-weight: bold">Lab</span> Abstracting Abstract Machines I</a></td></tr><tr><td><span class="tocsublinknumber"></span><a href="#%28part._lthm%29" class="tocsubseclink" data-pltdoc="x">Exercises</a></td></tr><tr><td><span class="tocsublinknumber">2.14<tt>&nbsp;</tt></span><a href="#%28part._thu-aft%29" class="tocsubseclink" data-pltdoc="x">Abstracting Abstract Machines II</a></td></tr><tr><td><span class="tocsublinknumber">2.15<tt>&nbsp;</tt></span><a href="#%28part._lab-thu-aft%29" class="tocsubseclink" data-pltdoc="x"><span style="font-weight: bold">Lab</span> Abstracting Abstract Machines II</a></td></tr><tr><td><span class="tocsublinknumber"></span><a href="#%28part._ltha%29" class="tocsubseclink" data-pltdoc="x">Exercises</a></td></tr></table></div></div><div class="maincolumn"><div class="main"><div class="versionbox"><span class="version">6.3</span></div><div class="navsettop"><span class="navleft"><form class="searchform"><input class="searchbox" style="color: #888;" type="text" value="...search manuals..." title="Enter a search string to search the manuals" onkeypress="return DoSearchKey(event, this, &quot;6.3&quot;, &quot;../&quot;);" onfocus="this.style.color=&quot;black&quot;; this.style.textAlign=&quot;left&quot;; if (this.value == &quot;...search manuals...&quot;) this.value=&quot;&quot;;" onblur="if (this.value.match(/^ *$/)) { this.style.color=&quot;#888&quot;; this.style.textAlign=&quot;center&quot;; this.value=&quot;...search manuals...&quot;; }"/></form>&nbsp;&nbsp;<a href="../index.html" title="up to the documentation top" data-pltdoc="x" onclick="return GotoPLTRoot(&quot;6.3&quot;);">top</a></span><span class="navright">&nbsp;&nbsp;<a href="tutorial.html" title="backward to &quot;1 Amb: A Redex Tutorial&quot;" data-pltdoc="x">&larr; prev</a>&nbsp;&nbsp;<a href="index.html" title="up to &quot;Redex: Practical Semantics Engineering&quot;" data-pltdoc="x">up</a>&nbsp;&nbsp;<a href="fri-mor.html" title="forward to &quot;3 Extended Exercises&quot;" data-pltdoc="x">next &rarr;</a></span>&nbsp;</div><h3 x-source-module="(lib &quot;redex/redex.scrbl&quot;)" x-source-pkg="redex-doc" x-part-tag="&quot;redex2015&quot;">2<tt>&nbsp;</tt><a name="(part._redex2015)"></a>Long Tutorial</h3><p>This tutorial is derived from a week-long Redex summer school,
run July 27&#8211;31, 2015 at the University of Utah.</p><h4 x-source-module="(lib &quot;redex/redex.scrbl&quot;)" x-source-pkg="redex-doc" x-part-tag="&quot;mon-mor&quot;">2.1<tt>&nbsp;</tt><a name="(part._mon-mor)"></a>The Theoretical Framework</h4><p><table cellspacing="0" cellpadding="0" class="boxed"><tr><td><p><span style="font-weight: bold">Goals</span></p></td></tr><tr><td><p> &#8212;<wbr></wbr> abstract syntax</p></td></tr><tr><td><p> &#8212;<wbr></wbr> notions of reduction, substitution</p></td></tr><tr><td><p> &#8212;<wbr></wbr> reductions and calculations</p></td></tr><tr><td><p> &#8212;<wbr></wbr> semantics</p></td></tr><tr><td><p> &#8212;<wbr></wbr> standard reduction</p></td></tr><tr><td><p> &#8212;<wbr></wbr> abstract register machines</p></td></tr><tr><td><p> &#8212;<wbr></wbr> types</p></td></tr></table></p><p>The lambda calculus:</p><blockquote><p><span class="stt">e = x | (\x.e) | (e e)</span></p></blockquote><p>Terms vs trees, abstract over concrete syntax</p><p>Encode some forms of primitives: numbers, booleans &ndash; good for theory of
computation; mostly irrelevant for PL. extensions with primitive data</p><blockquote><p><span class="stt">e = x | (\x.e) | (e e) | tt | ff | (if e e e)</span></p></blockquote><p>What we want: develop LC as a <span style="font-style: italic">model</span> of a PL. Because of history,
this means two things: a simple logic for calculating with the terms of the
language <span class="stt">e == e</span><span class="stt">&rsquo;</span><span class="stt"></span> and a system for determining the value of a
program. The former is the <a name="(tech._calculu)"></a><span style="font-style: italic">calculus</span>, the latter is the
<a name="(tech._semantic)"></a><span style="font-style: italic">semantics</span>.</p><p>Both start with basic notions of reduction (axioms). They are just relation
on terms:</p><p><div class="SIntrapara"><blockquote><p><span class="hspace">&nbsp;</span><span class="stt">((\x.e) e</span><span class="stt">&rsquo;</span><span class="stt">) beta e[x=e</span><span class="stt">&rsquo;</span><span class="stt">] </span></p></blockquote></div><div class="SIntrapara"> pronounced: e with x replaced by e&rsquo;
</div><div class="SIntrapara"><blockquote><p><span class="hspace">&nbsp;</span><span class="stt">((\x.e) e</span><span class="stt">&rsquo;</span><span class="stt">) beta [e</span><span class="stt">&rsquo;</span><span class="stt">/x]e</span></p></blockquote></div><div class="SIntrapara"> pronounced substitute e&rsquo; for x in e</div></p><p><span style="font-weight: bold">Think</span> substitution via tree surgery, preserving bindings</p><p>Here are two more, often done via external interpretation functions (&#948;)</p><p><div class="SIntrapara"><blockquote><p><span class="stt">(if tt e e</span><span class="stt">&rsquo;</span><span class="stt">) if-tt e</span></p></blockquote></div><div class="SIntrapara"><blockquote><p><span class="stt">(if ff e e</span><span class="stt">&rsquo;</span><span class="stt">) if-ff e</span><span class="stt">&rsquo;</span><span class="stt"></span></p></blockquote></div></p><p>If this is supposed to be a theory of functions (and if expressions) we
need to be able to use this relations <span style="font-style: italic">in context</span></p><p><div class="SIntrapara"><table cellspacing="0" cellpadding="0"><tr><td><p><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="stt"></span><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="stt">e xyz e'</span></p></td></tr><tr><td><p><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="stt">--------------</span></p></td></tr><tr><td><p><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="stt"></span><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="stt">e</span><span class="hspace">&nbsp;&nbsp;</span><span class="stt">=</span><span class="hspace">&nbsp;&nbsp;</span><span class="stt">e'</span></p></td></tr><tr><td><p><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="stt"></span></p></td></tr><tr><td><p><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="stt"></span><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="stt">e = e'</span><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="stt">e = e'</span><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="stt">e = e'</span></p></td></tr><tr><td><p><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="stt">--------------</span><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="stt">--------------	</span><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="stt">--------------</span></p></td></tr><tr><td><p><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="stt">e e'' = e' e''</span><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="stt">e'' e = e'' e'	</span><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="stt">\x.e</span><span class="hspace">&nbsp;&nbsp;</span><span class="stt">= \x.e'</span></p></td></tr><tr><td><p><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="stt"></span></p></td></tr><tr><td><p><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="stt">plus reflexivity, symmetry, and transitivity</span></p></td></tr></table></div><div class="SIntrapara">for any relation <span class="stt">xyz</span></div></p><p>Now you have an equational system. what&rsquo;s it good for? you can prove such
facts as</p><blockquote><p><span class="stt">e (Y e) = (Y e)</span></p></blockquote><p>meaning <span style="font-style: italic">every single term has a fixpoint</span></p><p>All of the above is mathematics but it is just that,
mathematics. It might be considered theory of computation,
but it is not theory of programming languages. But we can
use these ideas to create a theory of programming languages.
Plotkin&rsquo;s 1974 TCS paper on call-by-name versus
call-by-value shows how to create a theory of programming
languages.</p><p>In addition, Plotkin&rsquo;s paper also sketches several research programs,
mostly on scaling up his ideas to the full spectrum of languages but also
on the precise connection between by-value and by-name their relationship,
both at the proof-theoretical level as well as at the model-theoretic
level.</p><p><div class="SIntrapara">Here is Plotkin&rsquo;s idea as a quasi-algorithm:
</div><div class="SIntrapara"><ol><li><p>Start from an abstract syntax, plus notions of scope and
scope-preserving substitution. Consider closed terms <a name="(tech._program)"></a><span style="font-style: italic">Program</span>s.</p></li><li><p>Identify a subset of expressions as <a name="(tech._value)"></a><span style="font-style: italic">Value</span>s. Use <span class="stt">v</span> to
range over <a href="#%28tech._value%29" class="techoutside" data-pltdoc="x"><span class="techinside">Value</span></a>s.</p><p><span style="font-weight: bold">Note</span> The complement of this set was (later) dubbed
<a name="(tech._computation)"></a><span style="font-style: italic">computations</span>, due to Moggi&rsquo;s work under Plotkin.</p></li><li><p>Define basic notions of reduction (axioms). Examples:</p><p><div class="SIntrapara"><blockquote><p><span class="stt">((\x.e) e</span><span class="stt">&rsquo;</span><span class="stt">) beta-name e[x=e</span><span class="stt">&rsquo;</span><span class="stt">]</span></p></blockquote></div><div class="SIntrapara"><blockquote><p><span class="stt">((\x.e) v) beta-value e[x=v]</span></p></blockquote></div></p></li><li><p>Inductively generate an equational theory from the basic notions of
reduction.</p></li><li><p>This theory defines a semantics, that is, a relation <span style="font-style: italic">eval</span>
from programs to values:</p><p><div class="SIntrapara"><blockquote><p><span class="stt">eval : Program x Value</span></p></blockquote></div><div class="SIntrapara"><blockquote><p><span style="font-weight: bold">def</span><span class="stt"> e eval v iff e = v</span></p></blockquote></div></p></li><li><p>Prove that <span style="font-style: italic">eval</span> is a function, and you have got yourself a
<span style="font-style: italic">specification</span> of an interpreter.</p><p><div class="SIntrapara"><blockquote><p><span class="stt">eval : Program -&gt; Value</span></p></blockquote></div><div class="SIntrapara"><blockquote><p><span class="stt">eval(e) = v</span></p></blockquote></div></p><p><span style="font-weight: bold">Note</span> This step often reuses a variant of the Church-Rosser theorem
of the mathematical theory of lambda calculus.</p></li><li><p>Prove that the calculus satisfies a Curry-Feys standard reduction
property. This gives you a second semantics:</p><p><div class="SIntrapara"><blockquote><p><span class="stt">eval-standard : Program -&gt; Value</span></p></blockquote></div><div class="SIntrapara"><blockquote><p><span style="font-weight: bold">def</span><span class="stt"> eval-standard(e) = v iff e standard reduces to v</span></p></blockquote></div></p><p><div class="SIntrapara">The new semantics is correct:
</div><div class="SIntrapara"><blockquote><p><span style="font-weight: bold">Theorem</span><span class="stt"> eval-standard = eval</span></p></blockquote></div></p><p><a name="(tech._standard._reduction)"></a><span style="font-style: italic">Standard reduction</span> is a strategy for the lambda calculus, that
is, a function that picks the next reducible expression (called
<a name="(tech._redex)"></a><span style="font-style: italic">redex</span>) to reduce. Plotkin specifically uses the
leftmost-outermost strategy but others may work, too.</p></li></ol></div><div class="SIntrapara">Plotkin also shows&#8212;<wbr></wbr>on an ad hoc basis&#8212;<wbr></wbr>that this evaluator function is
equivalent to Landin&rsquo;s evaluator based on the SECD machine, an abstract
register machine.</div></p><p><div class="SIntrapara">Plotkin (following Morris, 1968) uses step 6 from above to add two ideas:
</div><div class="SIntrapara"><ul><li><p>The interpreter of a programming language (non-constructively)
 generates a theory of equivalence on phrases.</p><blockquote><p><span style="font-weight: bold">def</span><span class="stt"> e ~ e</span><span class="stt">&rsquo;</span><span class="stt"> iff placing e and e</span><span class="stt">&rsquo;</span><span class="stt"> into any context yields</span><span class="stt">
</span><span class="stt">programs that produce the same observable behavior according to eval</span></p></blockquote><p><span style="font-weight: bold">Theorem</span> <span class="stt">~</span> is the coarsest equivalence theory and thus unique.</p><p>Let&rsquo;s call <span class="stt">~</span> the <a name="(tech._truth)"></a><span style="font-style: italic">Truth</span>.</p></li><li><p><span style="font-weight: bold">Theorem</span> e = e&rsquo; implies e ~ e&rsquo;. Naturally the reverse doesn&rsquo;t hold.</p></li></ul></div></p><p><div class="SIntrapara">Matthias&rsquo;s (post)dissertation research extends Plotkin&rsquo;s work in two
directions:
</div><div class="SIntrapara"><ol><li><p>Plotkin&rsquo;s &ldquo;algorithm&rdquo; applies to imperative programming language,
 especially those extending the lambda calculus syntax with (variable)
 assignment and non-local control operators.</p><p><a href="#%28part._wed-mor%29" data-pltdoc="x">Imperative Extensions</a> explains how two of these work.</p></li><li><p>It is possible to derive useful abstract register machines from the
standard reduction semantics of the programming language</p><p><div class="SIntrapara">Each machine <span class="stt">M</span> defines a new semantics:
</div><div class="SIntrapara"><blockquote><p><span style="font-weight: bold">def</span><span class="stt"> eval-M(e) = v iff load M with e, run, unload, yields v</span></p></blockquote></div></p><p>For each of these functions, we can prove an equivalence theorem.</p><blockquote><p><span style="font-weight: bold">Theorem</span><span class="stt"> eval-M = eval-standard = eval</span></p></blockquote></li></ol></div><div class="SIntrapara">His work also shows how this approach greatly simplifies proofs of
consistency for the semantics of programming languages and especially
so-called type soundness theorems.</div></p><h4 x-source-module="(lib &quot;redex/redex.scrbl&quot;)" x-source-pkg="redex-doc" x-part-tag="&quot;mon-aft&quot;">2.2<tt>&nbsp;</tt><a name="(part._mon-aft)"></a>Syntax and Metafunctions</h4><p><table cellspacing="0" cellpadding="0" class="boxed"><tr><td><p><span style="font-weight: bold">Goals</span></p></td></tr><tr><td><p> &#8212;<wbr></wbr> Redex versus Racket</p></td></tr><tr><td><p> &#8212;<wbr></wbr> define languages</p></td></tr><tr><td><p> &#8212;<wbr></wbr> develop metafunctions, includes basic testing, submodules</p></td></tr><tr><td><p> &#8212;<wbr></wbr> extend languages</p></td></tr><tr><td><p> &#8212;<wbr></wbr> generalizing with <span class="RktSym">any</span></p></td></tr></table></p><h5 x-source-module="(lib &quot;redex/redex.scrbl&quot;)" x-source-pkg="redex-doc" x-part-tag="&quot;Developing_a_Language&quot;">2.2.1<tt>&nbsp;</tt><a name="(part._.Developing_a_.Language)"></a>Developing a Language</h5><p><div class="SIntrapara">To start a program with Redex, start your file with
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=guide&amp;rel=Module_Syntax.html%23%2528part._hash-lang%2529&amp;version=6.3" class="RktModLink Sq" data-pltdoc="x"><span class="RktMod">#lang</span></a><span class="RktMeta"></span><span class="hspace">&nbsp;</span><span class="RktMeta"></span><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=reference&amp;rel=index.html&amp;version=6.3" class="RktModLink Sq" data-pltdoc="x"><span class="RktSym">racket</span></a><span class="RktMeta"></span></td></tr><tr><td><span class="RktMeta"></span><span class="RktPn">(</span><span class="RktSym">require</span><span class="RktMeta"></span><span class="hspace">&nbsp;</span><span class="RktMeta"></span><span class="RktSym">redex</span><span class="RktPn">)</span><span class="RktMeta"></span></td></tr></table></blockquote></div></p><p><div class="SIntrapara">The <span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._define-language%29%29" class="RktStxLink" data-pltdoc="x">define-language</a></span> from specifies syntax trees via tree grammars:
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._define-language%29%29" class="RktStxLink" data-pltdoc="x">define-language</a></span><span class="hspace">&nbsp;</span><span class="RktSym">Lambda</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._~3a~3a~3d%29%29" class="RktStxLink" data-pltdoc="x">::=</a></span><span class="hspace">&nbsp;</span><span class="RktSym">x</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._~3a~3a~3d%29%29" class="RktStxLink" data-pltdoc="x">::=</a></span><span class="hspace">&nbsp;</span><span class="RktSym">variable-not-otherwise-mentioned</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr></table></blockquote></div><div class="SIntrapara">The trees are somewhat concrete, which makes it easy to work with them, but
it is confusing on those incredibly rare occasions when we want truly
abstract syntax.</div></p><p>We can include literal numbers (all of Racket&rsquo;s numbers, including complex)
or integers (all of Racket&rsquo;s integers) or naturals (all of Racket&rsquo;s natural
numbers)&#8212;<wbr></wbr>and many other things.</p><p><div class="SIntrapara">After you have a syntax, use the grammar to generate instances and check
them (typos do sneak in). Instances are generated with <span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span>:
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym">e1</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><table cellspacing="0" cellpadding="0"><tr><td></td></tr></table></td></tr><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym">e2</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">y</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><table cellspacing="0" cellpadding="0"><tr><td></td></tr></table></td></tr><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym">e3</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><table cellspacing="0" cellpadding="0"><tr><td></td></tr></table></td></tr><tr><td><span class="stt">&gt; </span><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym">e4</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktRdr">,</span><span class="RktSym">e2</span><span class="hspace">&nbsp;</span><span class="RktRdr">,</span><span class="RktSym">e3</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><table cellspacing="0" cellpadding="0"><tr><td></td></tr></table></td></tr><tr><td><span class="stt">&gt; </span><span class="RktSym">e4</span></td></tr><tr><td><p><span class="RktRes">'((lambda (y) y) (lambda (x y) y))</span></p></td></tr></table></blockquote></div><div class="SIntrapara">Mouse over <span class="RktSym">define</span>. It is <span style="font-style: italic">not</span> a Redex form, it comes from
Racket. Take a close look at the last definition. Comma anyone?</div></p><blockquote class="SCodeFlow"><p><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._redex-match~3f%29%29" class="RktStxLink" data-pltdoc="x">redex-match?</a></span><span class="hspace">&nbsp;</span><span class="RktSym">Lambda</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym">e4</span><span class="RktPn">)</span></p></blockquote><p><div class="SIntrapara">Define yourself a predicate that tests membership:
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><p><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym">lambda?</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._redex-match~3f%29%29" class="RktStxLink" data-pltdoc="x">redex-match?</a></span><span class="hspace">&nbsp;</span><span class="RktSym">Lambda</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span><span class="RktPn">)</span></p></blockquote></div><div class="SIntrapara">Now you can formulate language tests:
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda?</span><span class="hspace">&nbsp;</span><span class="RktSym">e1</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">#true</span><span class="RktPn">)</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda?</span><span class="hspace">&nbsp;</span><span class="RktSym">e2</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">#true</span><span class="RktPn">)</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda?</span><span class="hspace">&nbsp;</span><span class="RktSym">e3</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">#true</span><span class="RktPn">)</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda?</span><span class="hspace">&nbsp;</span><span class="RktSym">e4</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">#true</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym">eb1</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym">eb2</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">3</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda?</span><span class="hspace">&nbsp;</span><span class="RktSym">eb1</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">#false</span><span class="RktPn">)</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda?</span><span class="hspace">&nbsp;</span><span class="RktSym">eb2</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">#false</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28def._%28%28lib._redex%2Freduction-semantics..rkt%29._test-results%29%29" class="RktValLink" data-pltdoc="x">test-results</a></span><span class="RktPn">)</span></td></tr></table></blockquote></div><div class="SIntrapara">Make sure your language contains the terms that you want and does
<span style="font-style: italic">not</span> contain those you want to exclude. Why should <span class="RktSym">eb1</span> and
<span class="RktSym">eb2</span> not be in <span class="RktSym">Lambda</span>&rsquo;s set of expressions?</div></p><h5 x-source-module="(lib &quot;redex/redex.scrbl&quot;)" x-source-pkg="redex-doc" x-part-tag="&quot;Developing_Metafunctions&quot;">2.2.2<tt>&nbsp;</tt><a name="(part._.Developing_.Metafunctions)"></a>Developing Metafunctions</h5><p>To make basic statements about (parts of) your language, define
metafunctions. Roughly, a metafunction is a function on the terms of a
specific language.</p><p><div class="SIntrapara">We don&rsquo;t want parameter sequences with repeated variables. Can we say this
with a metafunction.
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._define-metafunction%29%29" class="RktStxLink" data-pltdoc="x">define-metafunction</a></span><span class="hspace">&nbsp;</span><span class="RktSym">Lambda</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktSym">unique-vars</span><span class="hspace">&nbsp;</span><span class="RktSym">:</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">-&gt;</span></span><span class="hspace">&nbsp;</span><span class="RktSym">boolean</span><span class="RktPn">)</span></td></tr></table></blockquote></div><div class="SIntrapara">The second line is a Redex contract, not a type. It says
 <span class="RktSym">unique-vars</span> consumes a sequence of <span class="RktSym">x</span>s and produces a
 <span class="RktSym">boolean</span>.</div></p><p><div class="SIntrapara">How do we way we don&rsquo;t want repeated variables? With patterns.
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._define-metafunction%29%29" class="RktStxLink" data-pltdoc="x">define-metafunction</a></span><span class="hspace">&nbsp;</span><span class="RktSym">Lambda</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktSym">unique-vars</span><span class="hspace">&nbsp;</span><span class="RktSym">:</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">-&gt;</span></span><span class="hspace">&nbsp;</span><span class="RktSym">boolean</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">unique-vars</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">#true</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">unique-vars</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">x_1</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">x_2</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">#false</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">unique-vars</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">x_1</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">unique-vars</span><span class="hspace">&nbsp;</span><span class="RktSym">x_1</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">]</span><span class="RktPn">)</span></td></tr></table></blockquote></div><div class="SIntrapara">Patterns are powerful. More later.</div></p><p>But, don&rsquo;t just define metafunctions, develop them properly: state what
they are about, work through examples, write down the latter as tests,
<span style="font-style: italic">then</span> define the function.</p><p><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktCmt">;</span><span class="RktCmt">&nbsp;</span><span class="RktCmt">are the identifiers in the given sequence unique?</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym">module+</span><span class="hspace">&nbsp;</span><span class="RktSym">test</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">unique-vars</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">#true</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">unique-vars</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">#false</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._define-metafunction%29%29" class="RktStxLink" data-pltdoc="x">define-metafunction</a></span><span class="hspace">&nbsp;</span><span class="RktSym">Lambda</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktSym">unique-vars</span><span class="hspace">&nbsp;</span><span class="RktSym">:</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">-&gt;</span></span><span class="hspace">&nbsp;</span><span class="RktSym">boolean</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">unique-vars</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">#true</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">unique-vars</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">x_1</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">x_2</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">#false</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">unique-vars</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">x_1</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">unique-vars</span><span class="hspace">&nbsp;</span><span class="RktSym">x_1</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">]</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym">module+</span><span class="hspace">&nbsp;</span><span class="RktSym">test</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28def._%28%28lib._redex%2Freduction-semantics..rkt%29._test-results%29%29" class="RktValLink" data-pltdoc="x">test-results</a></span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr></table></blockquote></div><div class="SIntrapara">Submodules delegate the tests to where they belong and they allow us to
  document functions by example.</div></p><p>Sadly, <span class="RktSym">unique-vars</span> doesn&rsquo;t work for our language
definition. They create circular definitions.</p><p><div class="SIntrapara">Fortunately, language definitions can employ more than Kleene patterns:
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._define-language%29%29" class="RktStxLink" data-pltdoc="x">define-language</a></span><span class="hspace">&nbsp;</span><span class="RktSym">Lambda</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._~3a~3a~3d%29%29" class="RktStxLink" data-pltdoc="x">::=</a></span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktSym">x</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x_!_</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._~3a~3a~3d%29%29" class="RktStxLink" data-pltdoc="x">::=</a></span><span class="hspace">&nbsp;</span><span class="RktSym">variable-not-otherwise-mentioned</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr></table></blockquote></div><div class="SIntrapara"><span class="RktSym">x_!_</span><span class="stt"> </span><span class="RktSym">...</span> means <span class="RktSym">x</span> must differ from all other elements of
this sequence</div></p><p><div class="SIntrapara">Here are two more metafunctions that use patterns in interesting ways:
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktCmt">;</span><span class="RktCmt">&nbsp;</span><span class="RktCmt">(subtract (x ...) x_1 ...) removes x_1 ... from (x ...)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym">module+</span><span class="hspace">&nbsp;</span><span class="RktSym">test</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">subtract</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="hspace">&nbsp;</span><span class="RktSym">z</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">z</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">y</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._define-metafunction%29%29" class="RktStxLink" data-pltdoc="x">define-metafunction</a></span><span class="hspace">&nbsp;</span><span class="RktSym">Lambda</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktSym">subtract</span><span class="hspace">&nbsp;</span><span class="RktSym">:</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">-&gt;</span></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">subtract</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">subtract</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">x_1</span><span class="hspace">&nbsp;</span><span class="RktSym">x_2</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">subtract</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">subtract1</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">x_1</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">x_2</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">]</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktCmt">;</span><span class="RktCmt">&nbsp;</span><span class="RktCmt">(subtract1 (x ...) x_1) removes x_1</span><span class="hspace">&nbsp;&nbsp;</span><span class="RktCmt">from (x ...)</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym">module+</span><span class="hspace">&nbsp;</span><span class="RktSym">test</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">subtract1</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="hspace">&nbsp;</span><span class="RktSym">z</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">y</span><span class="hspace">&nbsp;</span><span class="RktSym">z</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._define-metafunction%29%29" class="RktStxLink" data-pltdoc="x">define-metafunction</a></span><span class="hspace">&nbsp;</span><span class="RktSym">Lambda</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktSym">subtract1</span><span class="hspace">&nbsp;</span><span class="RktSym">:</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">-&gt;</span></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">subtract1</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x_1</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">x_2</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x_1</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="hspace">&nbsp;</span><span class="RktSym">x_2new</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">where</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x_2new</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">subtract1</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x_2</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">where</span><span class="hspace">&nbsp;</span><span class="RktVal">#false</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">in</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x_1</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">subtract1</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">x_1</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">]</span><span class="RktPn">)</span></td></tr></table></blockquote></div></p><h5 x-source-module="(lib &quot;redex/redex.scrbl&quot;)" x-source-pkg="redex-doc" x-part-tag="&quot;Developing_a_Language_2&quot;">2.2.3<tt>&nbsp;</tt><a name="(part._.Developing_a_.Language_2)"></a>Developing a Language 2</h5><p><div class="SIntrapara">One of the first things a language designer ought to specify is
<a name="(tech._scope)"></a><span style="font-style: italic">scope</span>. People often do so with a free-variables function that
specifies which language constructs bind and which ones don&rsquo;t:
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktCmt">;</span><span class="RktCmt">&nbsp;</span><span class="RktCmt">(fv e) computes the sequence of free variables of e</span></td></tr><tr><td><span class="RktCmt">;</span><span class="RktCmt">&nbsp;</span><span class="RktCmt">a variable occurrence of </span><span class="RktSym">x</span><span class="RktCmt"> is free in </span><span class="RktSym">e</span><span class="RktCmt"> </span></td></tr><tr><td><span class="RktCmt">;</span><span class="RktCmt">&nbsp;</span><span class="RktCmt">if no </span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="stt"> </span><span class="RktPn">(</span><span class="RktSym">...</span><span class="stt"> </span><span class="RktSym">x</span><span class="stt"> </span><span class="RktSym">...</span><span class="RktPn">)</span><span class="stt"> </span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktCmt"> </span><span style="font-style: italic">dominates</span><span class="RktCmt"> its occurrence </span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym">module+</span><span class="hspace">&nbsp;</span><span class="RktSym">test</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">fv</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">fv</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">fv</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">y</span><span class="hspace">&nbsp;</span><span class="RktSym">z</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">y</span><span class="hspace">&nbsp;</span><span class="RktSym">z</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._define-metafunction%29%29" class="RktStxLink" data-pltdoc="x">define-metafunction</a></span><span class="hspace">&nbsp;</span><span class="RktSym">Lambda</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktSym">fv</span><span class="hspace">&nbsp;</span><span class="RktSym">:</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">-&gt;</span></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">fv</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">fv</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">subtract</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x_e</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">where</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x_e</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">fv</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">fv</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e_f</span><span class="hspace">&nbsp;</span><span class="RktSym">e_a</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x_f</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="hspace">&nbsp;</span><span class="RktSym">x_a</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">where</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x_f</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">fv</span><span class="hspace">&nbsp;</span><span class="RktSym">e_f</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">where</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">x_a</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">fv</span><span class="hspace">&nbsp;</span><span class="RktSym">e_a</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">]</span><span class="RktPn">)</span></td></tr></table></blockquote></div></p><p><div class="SIntrapara"><blockquote class="refpara"><blockquote class="refcolumn"><blockquote class="refcontent"><p>You may know it as the de Bruijn index representation.</p></blockquote></blockquote></blockquote></div><div class="SIntrapara">The best approach is to specify an &#945; equivalence relation, that is, the
relation that virtually eliminates variables from phrases and replaces them
with arrows to their declarations. In the world of lambda calculus-based
languages, this transformation is often a part of the compiler, the
so-called static-distance phase.</div></p><p><div class="SIntrapara">The function is a good example of accumulator-functions in Redex:
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktCmt">;</span><span class="RktCmt">&nbsp;</span><span class="RktCmt">(sd e) computes the static distance version of e</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._define-extended-language%29%29" class="RktStxLink" data-pltdoc="x">define-extended-language</a></span><span class="hspace">&nbsp;</span><span class="RktSym">SD</span><span class="hspace">&nbsp;</span><span class="RktSym">Lambda</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._~3a~3a~3d%29%29" class="RktStxLink" data-pltdoc="x">::=</a></span><span class="hspace">&nbsp;</span><span class="RktSym">....</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">K</span><span class="hspace">&nbsp;</span><span class="RktSym">n</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">n</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._~3a~3a~3d%29%29" class="RktStxLink" data-pltdoc="x">::=</a></span><span class="hspace">&nbsp;</span><span class="RktSym">natural</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym">sd1</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">K</span><span class="hspace">&nbsp;</span><span class="RktVal">1</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym">sd2</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktVal">1</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym">SD?</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._redex-match~3f%29%29" class="RktStxLink" data-pltdoc="x">redex-match?</a></span><span class="hspace">&nbsp;</span><span class="RktSym">SD</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym">module+</span><span class="hspace">&nbsp;</span><span class="RktSym">test</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">SD?</span><span class="hspace">&nbsp;</span><span class="RktSym">sd1</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">#true</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr></table></blockquote></div><div class="SIntrapara">We have to add a means to the language to say &ldquo;arrow back to the variable
  declaration.&rdquo; We do <span style="font-style: italic">not</span> edit the language definition but
  <span style="font-style: italic">extend</span> the language definition instead.</div></p><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._define-metafunction%29%29" class="RktStxLink" data-pltdoc="x">define-metafunction</a></span><span class="hspace">&nbsp;</span><span class="RktSym">SD</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktSym">sd</span><span class="hspace">&nbsp;</span><span class="RktSym">:</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">-&gt;</span></span><span class="hspace">&nbsp;</span><span class="RktSym">e</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">sd</span><span class="hspace">&nbsp;</span><span class="RktSym">e_1</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">sd/a</span><span class="hspace">&nbsp;</span><span class="RktSym">e_1</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">]</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym">module+</span><span class="hspace">&nbsp;</span><span class="RktSym">test</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">sd/a</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">sd/a</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">y</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">z</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">K</span><span class="hspace">&nbsp;</span><span class="RktVal">2</span><span class="hspace">&nbsp;</span><span class="RktVal">0</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">sd/a</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">y</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">K</span><span class="hspace">&nbsp;</span><span class="RktVal">0</span><span class="hspace">&nbsp;</span><span class="RktVal">0</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">K</span><span class="hspace">&nbsp;</span><span class="RktVal">0</span><span class="hspace">&nbsp;</span><span class="RktVal">0</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">sd/a</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">y</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">K</span><span class="hspace">&nbsp;</span><span class="RktVal">0</span><span class="hspace">&nbsp;</span><span class="RktVal">0</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">K</span><span class="hspace">&nbsp;</span><span class="RktVal">0</span><span class="hspace">&nbsp;</span><span class="RktVal">0</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">sd/a</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">z</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">y</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">z</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">K</span><span class="hspace">&nbsp;</span><span class="RktVal">0</span><span class="hspace">&nbsp;</span><span class="RktVal">1</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">K</span><span class="hspace">&nbsp;</span><span class="RktVal">1</span><span class="hspace">&nbsp;</span><span class="RktVal">0</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._define-metafunction%29%29" class="RktStxLink" data-pltdoc="x">define-metafunction</a></span><span class="hspace">&nbsp;</span><span class="RktSym">SD</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktSym">sd/a</span><span class="hspace">&nbsp;</span><span class="RktSym">:</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">-&gt;</span></span><span class="hspace">&nbsp;</span><span class="RktSym">e</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">sd/a</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">x_1</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x_0</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">x_2</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x_3</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktCmt">;</span><span class="RktCmt">&nbsp;</span><span class="RktCmt">bound variable </span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">K</span><span class="hspace">&nbsp;</span><span class="RktSym">n_rib</span><span class="hspace">&nbsp;</span><span class="RktSym">n_pos</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">where</span><span class="hspace">&nbsp;</span><span class="RktSym">n_rib</span><span class="hspace">&nbsp;</span><span class="RktRdr">,</span><span class="RktPn">(</span><span class="RktSym">length</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">x_1</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">where</span><span class="hspace">&nbsp;</span><span class="RktSym">n_pos</span><span class="hspace">&nbsp;</span><span class="RktRdr">,</span><span class="RktPn">(</span><span class="RktSym">length</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x_0</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">where</span><span class="hspace">&nbsp;</span><span class="RktVal">#false</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">in</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x_1</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">sd/a</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">e_1</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e_rest</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">sd/a</span><span class="hspace">&nbsp;</span><span class="RktSym">e_1</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">e_rest</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">sd/a</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e_fun</span><span class="hspace">&nbsp;</span><span class="RktSym">e_arg</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e_rib</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">sd/a</span><span class="hspace">&nbsp;</span><span class="RktSym">e_fun</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e_rib</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">sd/a</span><span class="hspace">&nbsp;</span><span class="RktSym">e_arg</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e_rib</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">sd/a</span><span class="hspace">&nbsp;</span><span class="RktSym">e_1</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktCmt">;</span><span class="RktCmt">&nbsp;</span><span class="RktCmt">a free variable is left alone </span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktSym">e_1</span><span class="RktPn">]</span><span class="RktPn">)</span></td></tr></table></blockquote><p><div class="SIntrapara">Now &#945; equivalence is straightforward:
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktCmt">;</span><span class="RktCmt">&nbsp;</span><span class="RktCmt">(=&#945; e_1 e_2) determines whether e_1 and e_2 are &#945; equivalent</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._define-extended-language%29%29" class="RktStxLink" data-pltdoc="x">define-extended-language</a></span><span class="hspace">&nbsp;</span><span class="RktSym">Lambda/n</span><span class="hspace">&nbsp;</span><span class="RktSym">Lambda</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._~3a~3a~3d%29%29" class="RktStxLink" data-pltdoc="x">::=</a></span><span class="hspace">&nbsp;</span><span class="RktSym">....</span><span class="hspace">&nbsp;</span><span class="RktSym">n</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">n</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._~3a~3a~3d%29%29" class="RktStxLink" data-pltdoc="x">::=</a></span><span class="hspace">&nbsp;</span><span class="RktSym">natural</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym">in-Lambda/n?</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._redex-match~3f%29%29" class="RktStxLink" data-pltdoc="x">redex-match?</a></span><span class="hspace">&nbsp;</span><span class="RktSym">Lambda/n</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym">module+</span><span class="hspace">&nbsp;</span><span class="RktSym">test</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">=&#945;</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">y</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">#true</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">=&#945;</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktVal">1</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">y</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">y</span><span class="hspace">&nbsp;</span><span class="RktVal">1</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">#true</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">=&#945;</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">y</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">z</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">#false</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._define-metafunction%29%29" class="RktStxLink" data-pltdoc="x">define-metafunction</a></span><span class="hspace">&nbsp;</span><span class="RktSym">SD</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktSym">=&#945;</span><span class="hspace">&nbsp;</span><span class="RktSym">:</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">-&gt;</span></span><span class="hspace">&nbsp;</span><span class="RktSym">boolean</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">=&#945;</span><span class="hspace">&nbsp;</span><span class="RktSym">e_1</span><span class="hspace">&nbsp;</span><span class="RktSym">e_2</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktRdr">,</span><span class="RktPn">(</span><span class="RktSym">equal?</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">sd</span><span class="hspace">&nbsp;</span><span class="RktSym">e_1</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">sd</span><span class="hspace">&nbsp;</span><span class="RktSym">e_2</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">]</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">=&#945;/racket</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">=&#945;</span><span class="hspace">&nbsp;</span><span class="RktRdr">,</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktRdr">,</span><span class="RktSym">y</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr></table></blockquote></div></p><h5 x-source-module="(lib &quot;redex/redex.scrbl&quot;)" x-source-pkg="redex-doc" x-part-tag="&quot;Extending_a_Language__any&quot;">2.2.4<tt>&nbsp;</tt><a name="(part._.Extending_a_.Language__any)"></a>Extending a Language: <span class="RktSym">any</span></h5><p><div class="SIntrapara">Suppose we wish to extend <span class="RktSym">Lambda</span> with <span class="RktSym">if</span> and Booleans,
like this:
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._define-extended-language%29%29" class="RktStxLink" data-pltdoc="x">define-extended-language</a></span><span class="hspace">&nbsp;</span><span class="RktSym">SD</span><span class="hspace">&nbsp;</span><span class="RktSym">Lambda</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._~3a~3a~3d%29%29" class="RktStxLink" data-pltdoc="x">::=</a></span><span class="hspace">&nbsp;</span><span class="RktSym">....</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktSym">true</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktSym">false</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">if</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr></table></blockquote></div><div class="SIntrapara">Guess what? <span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="stt"> </span><span class="RktPn">(</span><span class="RktSym">fv</span><span class="stt"> </span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="stt"> </span><span class="RktPn">(</span><span class="RktSym">x</span><span class="stt"> </span><span class="RktSym">y</span><span class="RktPn">)</span><span class="stt"> </span><span class="RktPn">(</span><span class="RktSym">if</span><span class="stt"> </span><span class="RktSym">x</span><span class="stt"> </span><span class="RktSym">y</span><span class="stt"> </span><span class="RktSym">false</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span> doesn&rsquo;t
 work because <span class="RktSym">false</span> and <span class="RktSym">if</span> are not covered.</div></p><p>We want metafunctions that are as generic as possible for computing such
notions as free variable sequences, static distance, and alpha
equivalences.</p><p><div class="SIntrapara">Redex contracts come with <span class="RktSym">any</span> and Redex patterns really are over
Racket&rsquo;s S-expressions. This definition now works for extensions that don&rsquo;t
add binders:
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym">module+</span><span class="hspace">&nbsp;</span><span class="RktSym">test</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">SD?</span><span class="hspace">&nbsp;</span><span class="RktSym">sd1</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">#true</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._define-metafunction%29%29" class="RktStxLink" data-pltdoc="x">define-metafunction</a></span><span class="hspace">&nbsp;</span><span class="RktSym">SD</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktSym">sd</span><span class="hspace">&nbsp;</span><span class="RktSym">:</span><span class="hspace">&nbsp;</span><span class="RktSym">any</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">-&gt;</span></span><span class="hspace">&nbsp;</span><span class="RktSym">any</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">sd</span><span class="hspace">&nbsp;</span><span class="RktSym">any_1</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">sd/a</span><span class="hspace">&nbsp;</span><span class="RktSym">any_1</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">]</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym">module+</span><span class="hspace">&nbsp;</span><span class="RktSym">test</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">sd/a</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">sd/a</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">y</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">z</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">K</span><span class="hspace">&nbsp;</span><span class="RktVal">2</span><span class="hspace">&nbsp;</span><span class="RktVal">0</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">sd/a</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">y</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">K</span><span class="hspace">&nbsp;</span><span class="RktVal">0</span><span class="hspace">&nbsp;</span><span class="RktVal">0</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">K</span><span class="hspace">&nbsp;</span><span class="RktVal">0</span><span class="hspace">&nbsp;</span><span class="RktVal">0</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">sd/a</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">y</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">K</span><span class="hspace">&nbsp;</span><span class="RktVal">0</span><span class="hspace">&nbsp;</span><span class="RktVal">0</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">K</span><span class="hspace">&nbsp;</span><span class="RktVal">0</span><span class="hspace">&nbsp;</span><span class="RktVal">0</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">sd/a</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">z</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">y</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">z</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">K</span><span class="hspace">&nbsp;</span><span class="RktVal">0</span><span class="hspace">&nbsp;</span><span class="RktVal">1</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">K</span><span class="hspace">&nbsp;</span><span class="RktVal">1</span><span class="hspace">&nbsp;</span><span class="RktVal">0</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._define-metafunction%29%29" class="RktStxLink" data-pltdoc="x">define-metafunction</a></span><span class="hspace">&nbsp;</span><span class="RktSym">SD</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktSym">sd/a</span><span class="hspace">&nbsp;</span><span class="RktSym">:</span><span class="hspace">&nbsp;</span><span class="RktSym">any</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">-&gt;</span></span><span class="hspace">&nbsp;</span><span class="RktSym">any</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">sd/a</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">x_1</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x_0</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">x_2</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x_3</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktCmt">;</span><span class="RktCmt">&nbsp;</span><span class="RktCmt">bound variable </span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">K</span><span class="hspace">&nbsp;</span><span class="RktSym">n_rib</span><span class="hspace">&nbsp;</span><span class="RktSym">n_pos</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">where</span><span class="hspace">&nbsp;</span><span class="RktSym">n_rib</span><span class="hspace">&nbsp;</span><span class="RktRdr">,</span><span class="RktPn">(</span><span class="RktSym">length</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">x_1</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">where</span><span class="hspace">&nbsp;</span><span class="RktSym">n_pos</span><span class="hspace">&nbsp;</span><span class="RktRdr">,</span><span class="RktPn">(</span><span class="RktSym">length</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x_0</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">where</span><span class="hspace">&nbsp;</span><span class="RktVal">#false</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">in</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x_1</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">sd/a</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">any_1</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">any_rest</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">sd/a</span><span class="hspace">&nbsp;</span><span class="RktSym">any_1</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">any_rest</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">sd/a</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">any_fun</span><span class="hspace">&nbsp;</span><span class="RktSym">any_arg</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">any_rib</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">sd/a</span><span class="hspace">&nbsp;</span><span class="RktSym">any_fun</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">any_rib</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">sd/a</span><span class="hspace">&nbsp;</span><span class="RktSym">any_arg</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">any_rib</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">sd/a</span><span class="hspace">&nbsp;</span><span class="RktSym">any_1</span><span class="hspace">&nbsp;</span><span class="RktSym">any</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktCmt">;</span><span class="RktCmt">&nbsp;</span><span class="RktCmt">free variable, constant, etc </span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktSym">any_1</span><span class="RktPn">]</span><span class="RktPn">)</span></td></tr></table></blockquote></div></p><h5 x-source-module="(lib &quot;redex/redex.scrbl&quot;)" x-source-pkg="redex-doc" x-part-tag="&quot;Substitution&quot;">2.2.5<tt>&nbsp;</tt><a name="(part._.Substitution)"></a>Substitution</h5><p>The last thing we need is substitution, because it <span style="font-style: italic">is</span> the syntactic
equivalent of function application. We define it with <span style="font-style: italic">any</span> having
future extensions in mind.</p><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktCmt">;</span><span class="RktCmt">&nbsp;</span><span class="RktCmt">(subst ([e x] ...) e_*) substitutes e ... for x ... in e_* (hygienically)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym">module+</span><span class="hspace">&nbsp;</span><span class="RktSym">test</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">subst</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">[</span><span class="RktVal">1</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">]</span><span class="RktPn">[</span><span class="RktVal">2</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="RktPn">]</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">1</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">subst</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">[</span><span class="RktVal">1</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">]</span><span class="RktPn">[</span><span class="RktVal">2</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="RktPn">]</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">2</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">subst</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">[</span><span class="RktVal">1</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">]</span><span class="RktPn">[</span><span class="RktVal">2</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="RktPn">]</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">z</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktSym">z</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">subst</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">[</span><span class="RktVal">1</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">]</span><span class="RktPn">[</span><span class="RktVal">2</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="RktPn">]</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">z</span><span class="hspace">&nbsp;</span><span class="RktSym">w</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">z</span><span class="hspace">&nbsp;</span><span class="RktSym">w</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktVal">1</span><span class="hspace">&nbsp;</span><span class="RktVal">2</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">subst</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">[</span><span class="RktVal">1</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">]</span><span class="RktPn">[</span><span class="RktVal">2</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="RktPn">]</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">z</span><span class="hspace">&nbsp;</span><span class="RktSym">w</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">z</span><span class="hspace">&nbsp;</span><span class="RktSym">w</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktVal">2</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">#:equiv</span><span class="hspace">&nbsp;</span><span class="RktSym">=&#945;/racket</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">subst</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktVal">2</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktVal">1</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktVal">1</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">2</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">#:equiv</span><span class="hspace">&nbsp;</span><span class="RktSym">=&#945;/racket</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._define-metafunction%29%29" class="RktStxLink" data-pltdoc="x">define-metafunction</a></span><span class="hspace">&nbsp;</span><span class="RktSym">Lambda</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktSym">subst</span><span class="hspace">&nbsp;</span><span class="RktSym">:</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">any</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">any</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">-&gt;</span></span><span class="hspace">&nbsp;</span><span class="RktSym">any</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">subst</span><span class="hspace">&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">any_1</span><span class="hspace">&nbsp;</span><span class="RktSym">x_1</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">any_x</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">any_2</span><span class="hspace">&nbsp;</span><span class="RktSym">x_2</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">]</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">any_x</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">subst</span><span class="hspace">&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">any_1</span><span class="hspace">&nbsp;</span><span class="RktSym">x_1</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">]</span><span class="hspace">&nbsp;&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">subst</span><span class="hspace">&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">any_1</span><span class="hspace">&nbsp;</span><span class="RktSym">x_1</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">]</span><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">any_body</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x_new</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">subst</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">any_1</span><span class="hspace">&nbsp;</span><span class="RktSym">x_1</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">subst-raw</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">x_new</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">any_body</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">where</span><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x_new</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;&nbsp;</span><span class="RktRdr">,</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28def._%28%28lib._redex%2Freduction-semantics..rkt%29._variables-not-in%29%29" class="RktValLink" data-pltdoc="x">variables-not-in</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktSym">any_body</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">subst</span><span class="hspace">&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">any_1</span><span class="hspace">&nbsp;</span><span class="RktSym">x_1</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">]</span><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">any</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">subst</span><span class="hspace">&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">any_1</span><span class="hspace">&nbsp;</span><span class="RktSym">x_1</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">]</span><span class="hspace">&nbsp;&nbsp;</span><span class="RktSym">any</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">subst</span><span class="hspace">&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">any_1</span><span class="hspace">&nbsp;</span><span class="RktSym">x_1</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">]</span><span class="hspace">&nbsp;&nbsp;</span><span class="RktSym">any_*</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">any_*</span><span class="RktPn">]</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._define-metafunction%29%29" class="RktStxLink" data-pltdoc="x">define-metafunction</a></span><span class="hspace">&nbsp;</span><span class="RktSym">Lambda</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktSym">subst-raw</span><span class="hspace">&nbsp;</span><span class="RktSym">:</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">any</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">-&gt;</span></span><span class="hspace">&nbsp;</span><span class="RktSym">any</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">subst-raw</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">x_n1</span><span class="hspace">&nbsp;</span><span class="RktSym">x_o1</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x_new</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x_n2</span><span class="hspace">&nbsp;</span><span class="RktSym">x_o2</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">x_new</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">subst-raw</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">x_n1</span><span class="hspace">&nbsp;</span><span class="RktSym">x_o1</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">subst-raw</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">x_n1</span><span class="hspace">&nbsp;</span><span class="RktSym">x_o1</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">any</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">subst-raw</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">x_n1</span><span class="hspace">&nbsp;</span><span class="RktSym">x_o1</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;&nbsp;</span><span class="RktSym">any</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">subst-raw</span><span class="hspace">&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">any_1</span><span class="hspace">&nbsp;</span><span class="RktSym">x_1</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">]</span><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">any</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">subst-raw</span><span class="hspace">&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">any_1</span><span class="hspace">&nbsp;</span><span class="RktSym">x_1</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">]</span><span class="hspace">&nbsp;&nbsp;</span><span class="RktSym">any</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">subst-raw</span><span class="hspace">&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">any_1</span><span class="hspace">&nbsp;</span><span class="RktSym">x_1</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">]</span><span class="hspace">&nbsp;&nbsp;</span><span class="RktSym">any_*</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">any_*</span><span class="RktPn">]</span><span class="RktPn">)</span></td></tr></table></blockquote><p>}</p><h4 x-source-module="(lib &quot;redex/redex.scrbl&quot;)" x-source-pkg="redex-doc" x-part-tag="&quot;lab-mon-aft&quot;">2.3<tt>&nbsp;</tt><a name="(part._lab-mon-aft)"></a><span style="font-weight: bold">Lab</span> Designing Metafunctions</h4><p><table cellspacing="0" cellpadding="0" class="boxed"><tr><td><p><span style="font-weight: bold">Goals</span></p></td></tr><tr><td><p> &#8212;<wbr></wbr> developing meta-functions</p></td></tr><tr><td><p> &#8212;<wbr></wbr> discovering Redex patterns</p></td></tr></table></p><p><div class="SIntrapara">The following exercises refer to several definitions found in, and exported
from, <a href="common.rkt">common.rkt</a>. You may either copy these
definitions into your file or add the following <span class="RktSym">require</span> statement
to the top of your file:
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><p><span class="RktPn">(</span><span class="RktSym">require</span><span class="hspace">&nbsp;</span><span class="RktVal">"common.rkt"</span><span class="RktPn">)</span></p></blockquote></div></p><h5 x-source-module="(lib &quot;redex/redex.scrbl&quot;)" x-source-pkg="redex-doc" x-part-tag="&quot;lma&quot;"><a name="(part._lma)"></a>Exercises</h5><blockquote class="SubFlow"><p><a name="(counter._(exercise._ex~3abv))"></a><span style="font-weight: bold">Exercise</span>&nbsp;1. Design <span class="RktSym">bv</span>. The metafunction determines the
bound variables in a <span class="RktSym">Lambda</span> expression. A variable <span class="RktSym">x</span> is
<span style="font-style: italic">bound in <span class="RktSym">e_Lambda</span></span> if <span class="RktSym">x</span> occurs in a
<span class="RktSym">lambda</span>-parameter list in e_<span class="RktSym">Lambda</span>. <img style="vertical-align: 0px; margin: -3px -3px -3px -3px;" src="pict_5.png" alt="image" width="9" height="16"/></p></blockquote><blockquote class="SubFlow"><p><a name="(counter._(exercise._ex~3alookup))"></a><span style="font-weight: bold">Exercise</span>&nbsp;2. Design <span class="RktSym">lookup</span>. The metafunction consumes a
variable and an <a href="#%28tech._environment%29" class="techoutside" data-pltdoc="x"><span class="techinside">environment</span></a>. It determines the leftmost expression
associated with the variable; otherwise it produces <span class="RktVal">#false</span>.</p><p><div class="SIntrapara">Here is the definition of <a name="(tech._environment)"></a><span style="font-style: italic">environment</span>:
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._define-extended-language%29%29" class="RktStxLink" data-pltdoc="x">define-extended-language</a></span><span class="hspace">&nbsp;</span><span class="RktSym">Env</span><span class="hspace">&nbsp;</span><span class="RktSym">Lambda</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._~3a~3a~3d%29%29" class="RktStxLink" data-pltdoc="x">::=</a></span><span class="hspace">&nbsp;</span><span class="RktSym">....</span><span class="hspace">&nbsp;</span><span class="RktSym">natural</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">env</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._~3a~3a~3d%29%29" class="RktStxLink" data-pltdoc="x">::=</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr></table></blockquote></div><div class="SIntrapara">The language extension also adds numbers of the sub-language of
 expressions.</div></p><p>Before you get started, make sure you can create examples of
<a href="#%28tech._environment%29" class="techoutside" data-pltdoc="x"><span class="techinside">environment</span></a>s and confirm their well-formedness. <img style="vertical-align: 0px; margin: -3px -3px -3px -3px;" src="pict_6.png" alt="image" width="9" height="16"/></p></blockquote><blockquote class="SubFlow"><p><a name="(counter._(exercise._ex~3alet))"></a><span style="font-weight: bold">Exercise</span>&nbsp;3. Develop the metafunction <span class="RktSym">let</span>, which extends
 the language with a notational shorthand, also known as syntactic sugar.</p><p><div class="SIntrapara">Once you have this metafunction, you can write expressions such as
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">let</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">a</span><span class="hspace">&nbsp;</span><span class="RktSym">b</span><span class="hspace">&nbsp;</span><span class="RktSym">c</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">a</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">y</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr></table></blockquote></div><div class="SIntrapara">Like Racket&rsquo;s <span class="RktSym">let</span>, the function elaborates surface syntax into
 core syntax:
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">a</span><span class="hspace">&nbsp;</span><span class="RktSym">b</span><span class="hspace">&nbsp;</span><span class="RktSym">c</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">a</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr></table></blockquote></div></p><p><div class="SIntrapara">Since this elaboration happens as the term is constructed, all other
 metafunctions work as expected on this extended syntax. For example,
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span></td></tr><tr><td><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">fv</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">let</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">a</span><span class="hspace">&nbsp;</span><span class="RktSym">b</span><span class="hspace">&nbsp;</span><span class="RktSym">c</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">a</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">y</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr></table></blockquote></div><div class="SIntrapara">or
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span></td></tr><tr><td><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">bv</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">let</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">a</span><span class="hspace">&nbsp;</span><span class="RktSym">b</span><span class="hspace">&nbsp;</span><span class="RktSym">c</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">a</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">y</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr></table></blockquote></div><div class="SIntrapara">produces the expected results. What are those? <img style="vertical-align: 0px; margin: -3px -3px -3px -3px;" src="pict_7.png" alt="image" width="9" height="16"/></div></p></blockquote><h4 x-source-module="(lib &quot;redex/redex.scrbl&quot;)" x-source-pkg="redex-doc" x-part-tag="&quot;tue-mor&quot;">2.4<tt>&nbsp;</tt><a name="(part._tue-mor)"></a>Reductions and Semantics</h4><p><table cellspacing="0" cellpadding="0" class="boxed"><tr><td><p><span style="font-weight: bold">Goals</span></p></td></tr><tr><td><p> &#8212;<wbr></wbr> extend languages with concepts needed for reduction relations</p></td></tr><tr><td><p> &#8212;<wbr></wbr> developing reduction relations</p></td></tr><tr><td><p> &#8212;<wbr></wbr> defining a semantics</p></td></tr><tr><td><p> &#8212;<wbr></wbr> testing against a language</p></td></tr></table></p><p><span style="font-weight: bold">Note</span> These notes deal with the &#955;&#946; calculus, specifically its
reduction system.</p><blockquote><table cellspacing="0" cellpadding="0" style="border-collapse: collapse;"><tr><td style="border-bottom: 1px solid black;"><p>notation</p></td><td style="border-bottom: 1px solid black;"><p><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p></td><td style="border-bottom: 1px solid black;"><p>meaning</p></td></tr><tr><td><p><span class="RktSym">x</span><span class="RktMeta"></span></p></td><td><p><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p></td><td><p>basic notion of reduction, without properties</p></td></tr><tr><td><p><span class="RktSym"><span class="nobreak">--&gt;</span>x</span><span class="RktMeta"></span></p></td><td><p><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p></td><td><p>one-step reduction, generated from <span class="RktSym">x</span><span class="RktMeta"></span>, compatible with syntactic constructions</p></td></tr><tr><td><p><span class="RktSym"><span class="nobreak">--&gt;</span>&gt;x</span><span class="RktMeta"></span></p></td><td><p><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p></td><td><p>reduction, generated from <span class="RktSym"><span class="nobreak">--&gt;</span>x</span><span class="RktMeta"></span>, transitive here also reflexive</p></td></tr><tr><td><p><span class="RktSym">=x</span><span class="RktMeta"></span></p></td><td><p><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p></td><td><p>&ldquo;calculus&rdquo;, generated from <span class="RktSym"><span class="nobreak">--&gt;</span>x</span><span class="RktMeta"></span>, symmetric, transitive, reflexive</p></td></tr></table></blockquote><h5 x-source-module="(lib &quot;redex/redex.scrbl&quot;)" x-source-pkg="redex-doc" x-part-tag="&quot;Contexts__Values&quot;">2.4.1<tt>&nbsp;</tt><a name="(part._.Contexts__.Values)"></a>Contexts, Values</h5><p>The logical way of generating an equivalence (or reduction) relation over
terms uses through inductive inference rules that make the relation
compatible with all syntactic constructions.</p><p><div class="SIntrapara">An alternative and equivalent method is to introduce the notion of a
context and to use it to generate the reduction relation (or equivalence)
from the notion of reduction:
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym">require</span><span class="hspace">&nbsp;</span><span class="RktVal">"common.rkt"</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._define-extended-language%29%29" class="RktStxLink" data-pltdoc="x">define-extended-language</a></span><span class="hspace">&nbsp;</span><span class="RktSym">Lambda-calculus</span><span class="hspace">&nbsp;</span><span class="RktSym">Lambda</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._~3a~3a~3d%29%29" class="RktStxLink" data-pltdoc="x">::=</a></span><span class="hspace">&nbsp;</span><span class="RktSym">....</span><span class="hspace">&nbsp;</span><span class="RktSym">n</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">n</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._~3a~3a~3d%29%29" class="RktStxLink" data-pltdoc="x">::=</a></span><span class="hspace">&nbsp;</span><span class="RktSym">natural</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">v</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._~3a~3a~3d%29%29" class="RktStxLink" data-pltdoc="x">::=</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktCmt">;</span><span class="RktCmt">&nbsp;</span><span class="RktCmt">a context is an expression with one hole in lieu of a sub-expression </span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">C</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._~3a~3a~3d%29%29" class="RktStxLink" data-pltdoc="x">::=</a></span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._hole%29%29" class="RktStxLink" data-pltdoc="x">hole</a></span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="hspace">&nbsp;</span><span class="RktSym">C</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x_!_</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">C</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym">Context?</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._redex-match~3f%29%29" class="RktStxLink" data-pltdoc="x">redex-match?</a></span><span class="hspace">&nbsp;</span><span class="RktSym">Lambda-calculus</span><span class="hspace">&nbsp;</span><span class="RktSym">C</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym">module+</span><span class="hspace">&nbsp;</span><span class="RktSym">test</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym">C1</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._hole%29%29" class="RktStxLink" data-pltdoc="x">hole</a></span><span class="hspace">&nbsp;</span><span class="RktVal">1</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym">C2</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._hole%29%29" class="RktStxLink" data-pltdoc="x">hole</a></span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">0</span><span class="hspace">&nbsp;</span><span class="RktVal">1</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">Context?</span><span class="hspace">&nbsp;</span><span class="RktSym">C1</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">#true</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">Context?</span><span class="hspace">&nbsp;</span><span class="RktSym">C2</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">#true</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr></table></blockquote></div><div class="SIntrapara">Filling the hole of context with an expression yields an expression:
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym">module+</span><span class="hspace">&nbsp;</span><span class="RktSym">test</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym">e1</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._in-hole%29%29" class="RktStxLink" data-pltdoc="x">in-hole</a></span><span class="hspace">&nbsp;</span><span class="RktRdr">,</span><span class="RktSym">C1</span><span class="hspace">&nbsp;</span><span class="RktVal">1</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym">e2</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._in-hole%29%29" class="RktStxLink" data-pltdoc="x">in-hole</a></span><span class="hspace">&nbsp;</span><span class="RktRdr">,</span><span class="RktSym">C2</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">in-Lambda/n?</span><span class="hspace">&nbsp;</span><span class="RktSym">e1</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">#true</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">in-Lambda/n?</span><span class="hspace">&nbsp;</span><span class="RktSym">e2</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">#true</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr></table></blockquote></div><div class="SIntrapara">What does filling the hole of a context with a context yield?</div></p><h5 x-source-module="(lib &quot;redex/redex.scrbl&quot;)" x-source-pkg="redex-doc" x-part-tag="&quot;Long_Tutorial_Reduction_Relations&quot;">2.4.2<tt>&nbsp;</tt><a name="(part._.Long_.Tutorial_.Reduction_.Relations)"></a>Reduction Relations</h5><p>Developing a reduction relation is like developing a function. Work through
examples first. A reduction relation does not have to be a function, meaning
it may reduce one and the same term to distinct terms.</p><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktCmt">;</span><span class="RktCmt">&nbsp;</span><span class="RktCmt">the &#955;&#946; calculus, reductions only </span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym">module+</span><span class="hspace">&nbsp;</span><span class="RktSym">test</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktCmt">;</span><span class="RktCmt">&nbsp;</span><span class="RktCmt">does the one-step reduction reduce both &#946; redexes? </span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test--~3e%29%29" class="RktStxLink" data-pltdoc="x">test--&gt;</a></span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">--&gt;</span>&#946;</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">#:equiv</span><span class="hspace">&nbsp;</span><span class="RktSym">=&#945;/racket</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">y</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">z</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">z</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">y</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">z</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktCmt">;</span><span class="RktCmt">&nbsp;</span><span class="RktCmt">does the full reduction relation reduce all redexes? </span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test--~3e~3e%29%29" class="RktStxLink" data-pltdoc="x">test--&gt;&gt;</a></span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">--&gt;</span>&#946;</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktVal">1</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="hspace">&nbsp;</span><span class="RktVal">2</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">a</span><span class="hspace">&nbsp;</span><span class="RktSym">b</span><span class="hspace">&nbsp;</span><span class="RktSym">c</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">a</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktVal">3</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktVal">1</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">--&gt;</span>&#946;</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._reduction-relation%29%29" class="RktStxLink" data-pltdoc="x">reduction-relation</a></span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktSym">Lambda-calculus</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._--~3e%29%29" class="RktStxLink" data-pltdoc="x"><span class="nobreak">--&gt;</span></a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._in-hole%29%29" class="RktStxLink" data-pltdoc="x">in-hole</a></span><span class="hspace">&nbsp;</span><span class="RktSym">C</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x_1</span><span class="hspace">&nbsp;</span><span class="RktSym">..._n</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">e_1</span><span class="hspace">&nbsp;</span><span class="RktSym">..._n</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._in-hole%29%29" class="RktStxLink" data-pltdoc="x">in-hole</a></span><span class="hspace">&nbsp;</span><span class="RktSym">C</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">subst</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">[</span><span class="RktSym">e_1</span><span class="hspace">&nbsp;</span><span class="RktSym">x_1</span><span class="RktPn">]</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr></table></blockquote><p><div class="SIntrapara">With <span class="RktSym">traces</span> we can visualize reduction graphs:
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym">traces</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">--&gt;</span>&#946;</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">f</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">f</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktVal">1</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="hspace">&nbsp;</span><span class="RktVal">2</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">w</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">42</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">a</span><span class="hspace">&nbsp;</span><span class="RktSym">b</span><span class="hspace">&nbsp;</span><span class="RktSym">c</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">a</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktVal">3</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr></table></blockquote></div></p><blockquote class="SCentered"><p><img src="traces.png" alt="" width="675" height="537"/></p></blockquote><p><div class="SIntrapara">Defining the call-by-value calculus requires just a small change to the
reduction rule:
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">--&gt;</span>&#946;v</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._reduction-relation%29%29" class="RktStxLink" data-pltdoc="x">reduction-relation</a></span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktSym">Lambda-calculus</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._--~3e%29%29" class="RktStxLink" data-pltdoc="x"><span class="nobreak">--&gt;</span></a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._in-hole%29%29" class="RktStxLink" data-pltdoc="x">in-hole</a></span><span class="hspace">&nbsp;</span><span class="RktSym">C</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x_1</span><span class="hspace">&nbsp;</span><span class="RktSym">..._n</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">v_1</span><span class="hspace">&nbsp;</span><span class="RktSym">..._n</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._in-hole%29%29" class="RktStxLink" data-pltdoc="x">in-hole</a></span><span class="hspace">&nbsp;</span><span class="RktSym">C</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">subst</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">[</span><span class="RktSym">v_1</span><span class="hspace">&nbsp;</span><span class="RktSym">x_1</span><span class="RktPn">]</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr></table></blockquote></div><div class="SIntrapara">Let&rsquo;s compare traces for the same term.  You do get the same result but
significantly fewer intermediate terms. Why?</div></p><h5 x-source-module="(lib &quot;redex/redex.scrbl&quot;)" x-source-pkg="redex-doc" x-part-tag="&quot;Semantics&quot;">2.4.3<tt>&nbsp;</tt><a name="(part._.Semantics)"></a>Semantics</h5><p><div class="SIntrapara">First we need a standard reduction relation. The key is to define the path to
the leftmost-outermost redex, which can again be done via contexts. Here are
the relevant definitions for the by-value reduction relation:
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._define-extended-language%29%29" class="RktStxLink" data-pltdoc="x">define-extended-language</a></span><span class="hspace">&nbsp;</span><span class="RktSym">Standard</span><span class="hspace">&nbsp;</span><span class="RktSym">Lambda-calculus</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">v</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._~3a~3a~3d%29%29" class="RktStxLink" data-pltdoc="x">::=</a></span><span class="hspace">&nbsp;</span><span class="RktSym">n</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">E</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._~3a~3a~3d%29%29" class="RktStxLink" data-pltdoc="x">::=</a></span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._hole%29%29" class="RktStxLink" data-pltdoc="x">hole</a></span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">v</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="hspace">&nbsp;</span><span class="RktSym">E</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym">module+</span><span class="hspace">&nbsp;</span><span class="RktSym">test</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym">t0</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">5</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym">t0-one-step</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">5</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktCmt">;</span><span class="RktCmt">&nbsp;</span><span class="RktCmt">yields only one term, leftmost-outermost</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test--~3e%29%29" class="RktStxLink" data-pltdoc="x">test--&gt;</a></span><span class="hspace">&nbsp;</span><span class="RktSym">s-&gt;&#946;v</span><span class="hspace">&nbsp;</span><span class="RktSym">t0</span><span class="hspace">&nbsp;</span><span class="RktSym">t0-one-step</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktCmt">;</span><span class="RktCmt">&nbsp;</span><span class="RktCmt">but the transitive closure drives it to 5</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test--~3e~3e%29%29" class="RktStxLink" data-pltdoc="x">test--&gt;&gt;</a></span><span class="hspace">&nbsp;</span><span class="RktSym">s-&gt;&#946;v</span><span class="hspace">&nbsp;</span><span class="RktSym">t0</span><span class="hspace">&nbsp;</span><span class="RktVal">5</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym">s-&gt;&#946;v</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._reduction-relation%29%29" class="RktStxLink" data-pltdoc="x">reduction-relation</a></span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktSym">Standard</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._--~3e%29%29" class="RktStxLink" data-pltdoc="x"><span class="nobreak">--&gt;</span></a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._in-hole%29%29" class="RktStxLink" data-pltdoc="x">in-hole</a></span><span class="hspace">&nbsp;</span><span class="RktSym">E</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x_1</span><span class="hspace">&nbsp;</span><span class="RktSym">..._n</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">v_1</span><span class="hspace">&nbsp;</span><span class="RktSym">..._n</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._in-hole%29%29" class="RktStxLink" data-pltdoc="x">in-hole</a></span><span class="hspace">&nbsp;</span><span class="RktSym">E</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">subst</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">v_1</span><span class="hspace">&nbsp;</span><span class="RktSym">x_1</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr></table></blockquote></div><div class="SIntrapara">Note the tests-first development of the relation.</div></p><p><div class="SIntrapara">Now we can define the semantics function:
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym">module+</span><span class="hspace">&nbsp;</span><span class="RktSym">test</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">eval-value</span><span class="hspace">&nbsp;</span><span class="RktRdr">,</span><span class="RktSym">t0</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">5</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">eval-value</span><span class="hspace">&nbsp;</span><span class="RktRdr">,</span><span class="RktSym">t0-one-step</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">5</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym">t1</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda?</span><span class="hspace">&nbsp;</span><span class="RktSym">t1</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">#true</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._redex-match~3f%29%29" class="RktStxLink" data-pltdoc="x">redex-match?</a></span><span class="hspace">&nbsp;</span><span class="RktSym">Standard</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym">t1</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">#true</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">eval-value</span><span class="hspace">&nbsp;</span><span class="RktRdr">,</span><span class="RktSym">t1</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">'</span><span class="RktVal">closure</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._define-metafunction%29%29" class="RktStxLink" data-pltdoc="x">define-metafunction</a></span><span class="hspace">&nbsp;</span><span class="RktSym">Standard</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktSym">eval-value</span><span class="hspace">&nbsp;</span><span class="RktSym">:</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">-&gt;</span></span><span class="hspace">&nbsp;</span><span class="RktSym">v</span><span class="hspace">&nbsp;</span><span class="RktSym">or</span><span class="hspace">&nbsp;</span><span class="RktSym">closure</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">eval-value</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">any_1</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">where</span><span class="hspace">&nbsp;</span><span class="RktSym">any_1</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">run-value</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">]</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._define-metafunction%29%29" class="RktStxLink" data-pltdoc="x">define-metafunction</a></span><span class="hspace">&nbsp;</span><span class="RktSym">Standard</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktSym">run-value</span><span class="hspace">&nbsp;</span><span class="RktSym">:</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">-&gt;</span></span><span class="hspace">&nbsp;</span><span class="RktSym">v</span><span class="hspace">&nbsp;</span><span class="RktSym">or</span><span class="hspace">&nbsp;</span><span class="RktSym">closure</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">run-value</span><span class="hspace">&nbsp;</span><span class="RktSym">n</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">n</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">run-value</span><span class="hspace">&nbsp;</span><span class="RktSym">v</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">closure</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">run-value</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">run-value</span><span class="hspace">&nbsp;</span><span class="RktSym">e_again</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktCmt">;</span><span class="RktCmt">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">v</span><span class="RktPn">)</span><span class="RktCmt"> means that we expect s-&gt;&#946;v to be a function </span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">where</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e_again</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktRdr">,</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28def._%28%28lib._redex%2Freduction-semantics..rkt%29._apply-reduction-relation%29%29" class="RktValLink" data-pltdoc="x">apply-reduction-relation</a></span><span class="hspace">&nbsp;</span><span class="RktSym">s-&gt;&#946;v</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">]</span><span class="RktPn">)</span></td></tr></table></blockquote></div><div class="SIntrapara">The key is the stepper-loop, which applies the Racket function
 <span class="RktSym"><a href="The_Redex_Reference.html#%28def._%28%28lib._redex%2Freduction-semantics..rkt%29._apply-reduction-relation%29%29" class="RktValLink" data-pltdoc="x">apply-reduction-relation</a></span> repeatedly until it yields a value.</div></p><h5 x-source-module="(lib &quot;redex/redex.scrbl&quot;)" x-source-pkg="redex-doc" x-part-tag="&quot;What_are_Models&quot;">2.4.4<tt>&nbsp;</tt><a name="(part._.What_are_.Models)"></a>What are Models</h5><p>Good models of programming languages are like Newtonian models of how you
drive a car. As long as your speed is within a reasonable interval, the model
accurately predicts how your car behaves. Similarly, as long as your terms
are within a reasonable subset (the model&rsquo;s language), the evaluator of the
model and the evaluator of the language ought to agree.</p><p><div class="SIntrapara">For Racket you set up an evaluator for the language like this:
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym">define-namespace-anchor</span><span class="hspace">&nbsp;</span><span class="RktSym">A</span><span class="RktPn">)</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym">N</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">namespace-anchor-&gt;namespace</span><span class="hspace">&nbsp;</span><span class="RktSym">A</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="RktCmt">;</span><span class="RktCmt">&nbsp;</span><span class="RktCmt">Lambda.e -&gt; Number or </span><span class="RktCmt">'</span><span class="RktCmt">closure or exn</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">racket-evaluator</span><span class="hspace">&nbsp;</span><span class="RktSym">t0</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym">result</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">with-handlers</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">exn:fail?</span><span class="hspace">&nbsp;</span><span class="RktSym">values</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">eval</span><span class="hspace">&nbsp;</span><span class="RktSym">t0</span><span class="hspace">&nbsp;</span><span class="RktSym">N</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">cond</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">number?</span><span class="hspace">&nbsp;</span><span class="RktSym">result</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">result</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">procedure?</span><span class="hspace">&nbsp;</span><span class="RktSym">result</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktSym">closure</span><span class="RktPn">)</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktSym">else</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">make-exn</span><span class="hspace">&nbsp;</span><span class="RktVal">"hello world"</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">current-continuation-marks</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">]</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr></table></blockquote></div><div class="SIntrapara">The details don&rsquo;t matter.</div></p><p><div class="SIntrapara">So the theorem is this:
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._define-metafunction%29%29" class="RktStxLink" data-pltdoc="x">define-metafunction</a></span><span class="hspace">&nbsp;</span><span class="RktSym">Standard</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktSym">theorem:racket=eval-value</span><span class="hspace">&nbsp;</span><span class="RktSym">:</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">-&gt;</span></span><span class="hspace">&nbsp;</span><span class="RktSym">boolean</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">theorem:racket=eval-value</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktRdr">,</span><span class="RktPn">(</span><span class="RktSym">letrec</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">[</span><span class="RktSym">rr</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">racket-evaluator</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktSym">vr</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">run-value</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">]</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">cond</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">and</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">exn?</span><span class="hspace">&nbsp;</span><span class="RktSym">rr</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">eq?</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktSym">stuck</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">vr</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktVal">#true</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">exn?</span><span class="hspace">&nbsp;</span><span class="RktSym">rr</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">#false</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">eq?</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktSym">stuck</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">vr</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">#false</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktSym">else</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">equal?</span><span class="hspace">&nbsp;</span><span class="RktSym">vr</span><span class="hspace">&nbsp;</span><span class="RktSym">rr</span><span class="RktPn">)</span><span class="RktPn">]</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">]</span><span class="RktPn">)</span></td></tr></table></blockquote></div><div class="SIntrapara">We formulate it as a meta-function and test it on some terms:
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym">module+</span><span class="hspace">&nbsp;</span><span class="RktSym">test</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">racket=eval-value</span><span class="hspace">&nbsp;</span><span class="RktRdr">,</span><span class="RktSym">t0</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">#true</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">racket=eval-value</span><span class="hspace">&nbsp;</span><span class="RktRdr">,</span><span class="RktSym">t0-one-step</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">#true</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">racket=eval-value</span><span class="hspace">&nbsp;</span><span class="RktRdr">,</span><span class="RktSym">t1</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">#true</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr></table></blockquote></div></p><p><div class="SIntrapara">The real test comes with random testing:
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><p><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._redex-check%29%29" class="RktStxLink" data-pltdoc="x">redex-check</a></span><span class="hspace">&nbsp;</span><span class="RktSym">Standard</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">theorem:racket=eval-value</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></p></blockquote></div><div class="SIntrapara">And now it&rsquo;s time to discover.</div></p><h4 x-source-module="(lib &quot;redex/redex.scrbl&quot;)" x-source-pkg="redex-doc" x-part-tag="&quot;lab-tue-mor&quot;">2.5<tt>&nbsp;</tt><a name="(part._lab-tue-mor)"></a><span style="font-weight: bold">Lab</span> Designing Reductions</h4><p><table cellspacing="0" cellpadding="0" class="boxed"><tr><td><p><span style="font-weight: bold">Goals</span></p></td></tr><tr><td><p> &#8212;<wbr></wbr> developing reductions</p></td></tr><tr><td><p> &#8212;<wbr></wbr> semantics</p></td></tr></table></p><p><div class="SIntrapara">The following exercises refer to several definitions found in, and exported
from, <a href="common.rkt">common.rkt</a>. You may either copy these
definitions into your file or add the following <span class="RktSym">require</span> statement
to the top of your file:
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><p><span class="RktPn">(</span><span class="RktSym">require</span><span class="hspace">&nbsp;</span><span class="RktVal">"common.rkt"</span><span class="RktPn">)</span></p></blockquote></div></p><p>Also require <a href="close.rkt">close.rkt</a> for the <span class="RktSym">fv</span> function.</p><p><div class="SIntrapara">You also want to copy the following definitions into your drracket:
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._define-extended-language%29%29" class="RktStxLink" data-pltdoc="x">define-extended-language</a></span><span class="hspace">&nbsp;</span><span class="RktSym">Lambda-&#951;</span><span class="hspace">&nbsp;</span><span class="RktSym">Lambda</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._~3a~3a~3d%29%29" class="RktStxLink" data-pltdoc="x">::=</a></span><span class="hspace">&nbsp;</span><span class="RktSym">....</span><span class="hspace">&nbsp;</span><span class="RktSym">n</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">n</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._~3a~3a~3d%29%29" class="RktStxLink" data-pltdoc="x">::=</a></span><span class="hspace">&nbsp;</span><span class="RktSym">natural</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">C</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._~3a~3a~3d%29%29" class="RktStxLink" data-pltdoc="x">::=</a></span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._hole%29%29" class="RktStxLink" data-pltdoc="x">hole</a></span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="hspace">&nbsp;</span><span class="RktSym">C</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x_!_</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">C</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">v</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._~3a~3a~3d%29%29" class="RktStxLink" data-pltdoc="x">::=</a></span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktSym">n</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">--&gt;</span>&#946;</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._reduction-relation%29%29" class="RktStxLink" data-pltdoc="x">reduction-relation</a></span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktSym">Lambda-&#951;</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._--~3e%29%29" class="RktStxLink" data-pltdoc="x"><span class="nobreak">--&gt;</span></a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._in-hole%29%29" class="RktStxLink" data-pltdoc="x">in-hole</a></span><span class="hspace">&nbsp;</span><span class="RktSym">C</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x_1</span><span class="hspace">&nbsp;</span><span class="RktSym">..._n</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">e_1</span><span class="hspace">&nbsp;</span><span class="RktSym">..._n</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._in-hole%29%29" class="RktStxLink" data-pltdoc="x">in-hole</a></span><span class="hspace">&nbsp;</span><span class="RktSym">C</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">subst</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">[</span><span class="RktSym">e_1</span><span class="hspace">&nbsp;</span><span class="RktSym">x_1</span><span class="RktPn">]</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktSym">&#946;</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym">lambda?</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._redex-match~3f%29%29" class="RktStxLink" data-pltdoc="x">redex-match?</a></span><span class="hspace">&nbsp;</span><span class="RktSym">Lambda-calculus</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr></table></blockquote></div><div class="SIntrapara">Consider equipping the one-step reduction relation with tests.</div></p><h5 x-source-module="(lib &quot;redex/redex.scrbl&quot;)" x-source-pkg="redex-doc" x-part-tag="&quot;ltm&quot;"><a name="(part._ltm)"></a>Exercises</h5><blockquote class="SubFlow"><p><a name="(counter._(exercise._ex~3aeta))"></a><span style="font-weight: bold">Exercise</span>&nbsp;4. Develop a &#946;&#951; reduction relation for <span class="RktSym">Lambda-&#951;</span>.</p><p>Find a term that contains both a &#946;- and an &#951;-redex. Formulate a Redex test
that validates this claim. Also use <span class="RktSym">trace</span> to graphically validate
the claim.</p><p>Develop the &#946; and &#946;&#951; standard reduction relations. <span style="font-weight: bold">Hint</span> Look up
<span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._extend-reduction-relation%29%29" class="RktStxLink" data-pltdoc="x">extend-reduction-relation</a></span> to save some work.</p><p>Use the standard reduction relations to formulate a semantics for both
variants. The above test case, reformulated for the standard reduction,
<span style="font-style: italic">must</span> fail. Why? <span style="font-weight: bold">Note</span> The semantics for &#946;&#951; requires some
experimentation. Justify your non-standard definition of the <span class="RktSym">run</span>
function.</p><p>The &#946;&#951; semantics is equivalent to the &#946; variant. Formulate this theorem as
a metafunction. Use <span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._redex-check%29%29" class="RktStxLink" data-pltdoc="x">redex-check</a></span> to test your theorem.</p><p><span style="font-weight: bold">Note</span> Why does it make no sense to add &#951; to this system? <img style="vertical-align: 0px; margin: -3px -3px -3px -3px;" src="pict_8.png" alt="image" width="9" height="16"/></p></blockquote><blockquote class="SubFlow"><p><a name="(counter._(exercise._ex~3aadd-value))"></a><span style="font-weight: bold">Exercise</span>&nbsp;5. Extend the by-value language with an addition
operator.</p><p>Equip both the &#946;v reduction system and the &#946;v standard reduction with rules
that assign addition the usual semantics.  Finally define a semantics
functions for this language.</p><p><span style="font-weight: bold">Hint</span> Your rules need to escape to Racket and use its addition
operator. <img style="vertical-align: 0px; margin: -3px -3px -3px -3px;" src="pict_9.png" alt="image" width="9" height="16"/></p></blockquote><h4 x-source-module="(lib &quot;redex/redex.scrbl&quot;)" x-source-pkg="redex-doc" x-part-tag="&quot;tue-aft&quot;">2.6<tt>&nbsp;</tt><a name="(part._tue-aft)"></a>Types and Property Testing</h4><p><table cellspacing="0" cellpadding="0" class="boxed"><tr><td><p><span style="font-weight: bold">Goals</span></p></td></tr><tr><td><p> &#8212;<wbr></wbr> typed languages</p></td></tr><tr><td><p> &#8212;<wbr></wbr> developing type judgments</p></td></tr><tr><td><p> &#8212;<wbr></wbr> subject reduction</p></td></tr></table></p><h5 x-source-module="(lib &quot;redex/redex.scrbl&quot;)" x-source-pkg="redex-doc" x-part-tag="&quot;Types&quot;">2.6.1<tt>&nbsp;</tt><a name="(part._.Types)"></a>Types</h5><p><div class="SIntrapara">Here is a typed variant of the Lambda language:
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._define-language%29%29" class="RktStxLink" data-pltdoc="x">define-language</a></span><span class="hspace">&nbsp;</span><span class="RktSym">TLambda</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._~3a~3a~3d%29%29" class="RktStxLink" data-pltdoc="x">::=</a></span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktSym">n</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktSym">+</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktSym">x</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">x_!_</span><span class="hspace">&nbsp;</span><span class="RktSym">t</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">t</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._~3a~3a~3d%29%29" class="RktStxLink" data-pltdoc="x">::=</a></span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktSym">int</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">t</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">-&gt;</span></span><span class="hspace">&nbsp;</span><span class="RktSym">t</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._~3a~3a~3d%29%29" class="RktStxLink" data-pltdoc="x">::=</a></span><span class="hspace">&nbsp;</span><span class="RktSym">variable-not-otherwise-mentioned</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym">lambda?</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._redex-match~3f%29%29" class="RktStxLink" data-pltdoc="x">redex-match?</a></span><span class="hspace">&nbsp;</span><span class="RktSym">TLambda</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym">e1</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">int</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">f</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">int</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">-&gt;</span></span><span class="hspace">&nbsp;</span><span class="RktSym">int</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">+</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">f</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">f</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">f</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym">e2</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">int</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">f</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">int</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">-&gt;</span></span><span class="hspace">&nbsp;</span><span class="RktSym">int</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">-&gt;</span></span><span class="hspace">&nbsp;</span><span class="RktSym">int</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">f</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym">e3</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">int</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">int</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">-&gt;</span></span><span class="hspace">&nbsp;</span><span class="RktSym">int</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym">module+</span><span class="hspace">&nbsp;</span><span class="RktSym">test</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda?</span><span class="hspace">&nbsp;</span><span class="RktSym">e1</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">#true</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda?</span><span class="hspace">&nbsp;</span><span class="RktSym">e2</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">#true</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">in-TLambda?</span><span class="hspace">&nbsp;</span><span class="RktSym">e3</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">#false</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr></table></blockquote></div></p><h5 x-source-module="(lib &quot;redex/redex.scrbl&quot;)" x-source-pkg="redex-doc" x-part-tag="&quot;Developing_Type_Judgments&quot;">2.6.2<tt>&nbsp;</tt><a name="(part._.Developing_.Type_.Judgments)"></a>Developing Type Judgments</h5><p>Like metafunctions and reduction relations, type judgments are developed by
working out examples, formulating tests, and then articulating the judgment
rules:</p><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktCmt">;</span><span class="RktCmt">&nbsp;</span><span class="RktCmt">(&#8866; &#915; e t) </span><span class="RktCmt">&ndash;</span><span class="RktCmt"> the usual type judgment for an LC language</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._define-extended-language%29%29" class="RktStxLink" data-pltdoc="x">define-extended-language</a></span><span class="hspace">&nbsp;</span><span class="RktSym">TLambda-tc</span><span class="hspace">&nbsp;</span><span class="RktSym">TLambda</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">&#915;</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._~3a~3a~3d%29%29" class="RktStxLink" data-pltdoc="x">::=</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">t</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym">module+</span><span class="hspace">&nbsp;</span><span class="RktSym">test</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._judgment-holds%29%29" class="RktStxLink" data-pltdoc="x">judgment-holds</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">&#8866;</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktRdr">,</span><span class="RktSym">e1</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">int</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">int</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">-&gt;</span></span><span class="hspace">&nbsp;</span><span class="RktSym">int</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">-&gt;</span></span><span class="hspace">&nbsp;</span><span class="RktSym">int</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">#true</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._judgment-holds%29%29" class="RktStxLink" data-pltdoc="x">judgment-holds</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">&#8866;</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktRdr">,</span><span class="RktSym">e2</span><span class="hspace">&nbsp;</span><span class="RktSym">t</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">#false</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">displayln</span><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._judgment-holds%29%29" class="RktStxLink" data-pltdoc="x">judgment-holds</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">&#8866;</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktRdr">,</span><span class="RktSym">e1</span><span class="hspace">&nbsp;</span><span class="RktSym">t</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">t</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">displayln</span><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._judgment-holds%29%29" class="RktStxLink" data-pltdoc="x">judgment-holds</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">&#8866;</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktRdr">,</span><span class="RktSym">e2</span><span class="hspace">&nbsp;</span><span class="RktSym">t</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">t</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._define-judgment-form%29%29" class="RktStxLink" data-pltdoc="x">define-judgment-form</a></span><span class="hspace">&nbsp;</span><span class="RktSym">TLambda-tc</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">#:mode</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">&#8866;</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._.I%29%29" class="RktStxLink" data-pltdoc="x">I</a></span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._.I%29%29" class="RktStxLink" data-pltdoc="x">I</a></span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._.O%29%29" class="RktStxLink" data-pltdoc="x">O</a></span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">#:contract</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">&#8866;</span><span class="hspace">&nbsp;</span><span class="RktSym">&#915;</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym">t</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktSym"><span class="nobreak">-----------------------</span></span><span class="hspace">&nbsp;</span><span class="RktVal">"number"</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">&#8866;</span><span class="hspace">&nbsp;</span><span class="RktSym">&#915;</span><span class="hspace">&nbsp;</span><span class="RktSym">n</span><span class="hspace">&nbsp;</span><span class="RktSym">int</span><span class="RktPn">)</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktSym"><span class="nobreak">-----------------------</span></span><span class="hspace">&nbsp;</span><span class="RktVal">"+"</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">&#8866;</span><span class="hspace">&nbsp;</span><span class="RktSym">&#915;</span><span class="hspace">&nbsp;</span><span class="RktSym">+</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">int</span><span class="hspace">&nbsp;</span><span class="RktSym">int</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">-&gt;</span></span><span class="hspace">&nbsp;</span><span class="RktSym">int</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktSym"><span class="nobreak">-----------------------</span></span><span class="hspace">&nbsp;</span><span class="RktVal">"variable"</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">&#8866;</span><span class="hspace">&nbsp;</span><span class="RktSym">&#915;</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lookup</span><span class="hspace">&nbsp;</span><span class="RktSym">&#915;</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">&#8866;</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">extend</span><span class="hspace">&nbsp;</span><span class="RktSym">&#915;</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x_1</span><span class="hspace">&nbsp;</span><span class="RktSym">t_1</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym">t</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktSym"><span class="nobreak">-------------------------------------------------</span></span><span class="hspace">&nbsp;</span><span class="RktVal">"lambda"</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">&#8866;</span><span class="hspace">&nbsp;</span><span class="RktSym">&#915;</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">x_1</span><span class="hspace">&nbsp;</span><span class="RktSym">t_1</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">t_1</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">-&gt;</span></span><span class="hspace">&nbsp;</span><span class="RktSym">t</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">&#8866;</span><span class="hspace">&nbsp;</span><span class="RktSym">&#915;</span><span class="hspace">&nbsp;</span><span class="RktSym">e_1</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">t_2</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">-&gt;</span></span><span class="hspace">&nbsp;</span><span class="RktSym">t</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">&#8866;</span><span class="hspace">&nbsp;</span><span class="RktSym">&#915;</span><span class="hspace">&nbsp;</span><span class="RktSym">e_2</span><span class="hspace">&nbsp;</span><span class="RktSym">t_2</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktSym"><span class="nobreak">-------------------------------------------------</span></span><span class="hspace">&nbsp;</span><span class="RktVal">"application"</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">&#8866;</span><span class="hspace">&nbsp;</span><span class="RktSym">&#915;</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e_1</span><span class="hspace">&nbsp;</span><span class="RktSym">e_2</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">t</span><span class="RktPn">)</span><span class="RktPn">]</span><span class="RktPn">)</span></td></tr></table></blockquote><p><div class="SIntrapara">Here are the necessary auxiliary functions:
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktCmt">;</span><span class="RktCmt">&nbsp;</span><span class="RktCmt">(extend &#915; (x t) ...) add (x t) to &#915; so that x is found before other x-s</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym">module+</span><span class="hspace">&nbsp;</span><span class="RktSym">test</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">extend</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">int</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">int</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._define-metafunction%29%29" class="RktStxLink" data-pltdoc="x">define-metafunction</a></span><span class="hspace">&nbsp;</span><span class="RktSym">TLambda-tc</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktSym">extend</span><span class="hspace">&nbsp;</span><span class="RktSym">:</span><span class="hspace">&nbsp;</span><span class="RktSym">&#915;</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">t</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">-&gt;</span></span><span class="hspace">&nbsp;</span><span class="RktSym">&#915;</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">extend</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">x_&#915;</span><span class="hspace">&nbsp;</span><span class="RktSym">t_&#915;</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">t</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">t</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">(</span><span class="RktSym">x_&#915;</span><span class="hspace">&nbsp;</span><span class="RktSym">t_&#915;</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">]</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktCmt">;</span><span class="RktCmt">&nbsp;</span><span class="RktCmt">(lookup &#915; x) retrieves x</span><span class="RktCmt">'</span><span class="RktCmt">s type from &#915;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym">module+</span><span class="hspace">&nbsp;</span><span class="RktSym">test</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lookup</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">int</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">int</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">-&gt;</span></span><span class="hspace">&nbsp;</span><span class="RktSym">int</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">y</span><span class="hspace">&nbsp;</span><span class="RktSym">int</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktSym">int</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lookup</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">int</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">int</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">-&gt;</span></span><span class="hspace">&nbsp;</span><span class="RktSym">int</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">y</span><span class="hspace">&nbsp;</span><span class="RktSym">int</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktSym">int</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._define-metafunction%29%29" class="RktStxLink" data-pltdoc="x">define-metafunction</a></span><span class="hspace">&nbsp;</span><span class="RktSym">TLambda-tc</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktSym">lookup</span><span class="hspace">&nbsp;</span><span class="RktSym">:</span><span class="hspace">&nbsp;</span><span class="RktSym">&#915;</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">-&gt;</span></span><span class="hspace">&nbsp;</span><span class="RktSym">t</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">lookup</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">x_1</span><span class="hspace">&nbsp;</span><span class="RktSym">t_1</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">t</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x_2</span><span class="hspace">&nbsp;</span><span class="RktSym">t_2</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktSym">t</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">side-condition</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">not</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">member</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x_1</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">lookup</span><span class="hspace">&nbsp;</span><span class="RktSym">any_1</span><span class="hspace">&nbsp;</span><span class="RktSym">any_2</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktRdr">,</span><span class="RktPn">(</span><span class="RktSym">error</span><span class="hspace">&nbsp;</span><span class="RktVal">'</span><span class="RktVal">lookup</span><span class="hspace">&nbsp;</span><span class="RktVal">"not found: ~e"</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">]</span><span class="RktPn">)</span></td></tr></table></blockquote></div></p><h5 x-source-module="(lib &quot;redex/redex.scrbl&quot;)" x-source-pkg="redex-doc" x-part-tag="&quot;Subjection_Reduction&quot;">2.6.3<tt>&nbsp;</tt><a name="(part._.Subjection_.Reduction)"></a>Subjection Reduction</h5><p><div class="SIntrapara">Let&rsquo;s say we define a truly broken (standard) reduction relation for
<span class="RktSym">TLambda</span>:
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">-&gt;</span></span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._reduction-relation%29%29" class="RktStxLink" data-pltdoc="x">reduction-relation</a></span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktSym">TLambda</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">#:domain</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._--~3e%29%29" class="RktStxLink" data-pltdoc="x"><span class="nobreak">--&gt;</span></a></span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">int</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr></table></blockquote></div></p><p><div class="SIntrapara">With <span class="RktSym">trace</span>, we can quickly see that paths in almost any term&rsquo;s
reduction graph do not preserve types:
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym">traces</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">-&gt;</span></span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">int</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">-&gt;</span></span><span class="hspace">&nbsp;</span><span class="RktSym">int</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">int</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">1</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">#:pred</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._judgment-holds%29%29" class="RktStxLink" data-pltdoc="x">judgment-holds</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">&#8866;</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktRdr">,</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym">int</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr></table></blockquote></div><div class="SIntrapara">The <span class="RktPn">#:pred</span> keyword argument supplies a Racket function that judges
whether the intermediate expression type checks, using our type judgment
from above.</div></p><blockquote class="SCentered"><p><img src="subject-reduction.png" alt="" width="471" height="339"/></p></blockquote><p><div class="SIntrapara">For simple &ldquo;type systems,&rdquo; <span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._redex-check%29%29" class="RktStxLink" data-pltdoc="x">redex-check</a></span> can be used to test a
true subject reduction statement:
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._redex-check%29%29" class="RktStxLink" data-pltdoc="x">redex-check</a></span><span class="hspace">&nbsp;</span><span class="RktSym">TLambda</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktSym">e</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">implies</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._judgment-holds%29%29" class="RktStxLink" data-pltdoc="x">judgment-holds</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">&#8866;</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym">int</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._judgment-holds%29%29" class="RktStxLink" data-pltdoc="x">judgment-holds</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">&#8866;</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">eval-value</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">int</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">#:attempts</span><span class="hspace">&nbsp;</span><span class="RktVal">3</span><span class="RktPn">)</span></td></tr></table></blockquote></div></p><h4 x-source-module="(lib &quot;redex/redex.scrbl&quot;)" x-source-pkg="redex-doc" x-part-tag="&quot;lab-tue-aft&quot;">2.7<tt>&nbsp;</tt><a name="(part._lab-tue-aft)"></a><span style="font-weight: bold">Lab</span> Type Checking</h4><p><table cellspacing="0" cellpadding="0" class="boxed"><tr><td><p><span style="font-weight: bold">Goals</span></p></td></tr><tr><td><p> &#8212;<wbr></wbr> subject reduction testing with <span class="RktSym">trace</span></p></td></tr><tr><td><p> &#8212;<wbr></wbr> typing judgments</p></td></tr></table></p><p><div class="SIntrapara">The following exercises refer to several definitions found in, and exported
from, <a href="common.rkt">common.rkt</a>. You may either copy these
definitions into your file or add the following <span class="RktSym">require</span> statement
to the top of your file:
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><p><span class="RktPn">(</span><span class="RktSym">require</span><span class="hspace">&nbsp;</span><span class="RktVal">"common.rkt"</span><span class="RktPn">)</span></p></blockquote></div></p><p>In addition to <span class="stt">"common.rkt"</span>, you also want to <span class="RktSym">require</span>
<a href="tc-common.rkt">tc-common.rkt</a> for this lab. Furthermore, if you
copy code from <a href="#%28part._tue-aft%29" data-pltdoc="x">Types and Property Testing</a>, make sure to copy the tests and to adapt
the tests as you develop the machines.</p><h5 x-source-module="(lib &quot;redex/redex.scrbl&quot;)" x-source-pkg="redex-doc" x-part-tag="&quot;lta&quot;"><a name="(part._lta)"></a>Exercises</h5><blockquote class="SubFlow"><p><a name="(counter._(exercise._ex~3atyping-trace))"></a><span style="font-weight: bold">Exercise</span>&nbsp;6. Develop a reduction system for which the
<span class="RktSym">trace</span> expression from the lecture preserves types</p><p><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym">module+</span><span class="hspace">&nbsp;</span><span class="RktSym">test</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">traces</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">-&gt;</span></span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">int</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">-&gt;</span></span><span class="hspace">&nbsp;</span><span class="RktSym">int</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">int</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">1</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">#:pred</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._judgment-holds%29%29" class="RktStxLink" data-pltdoc="x">judgment-holds</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">&#8866;</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktRdr">,</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym">int</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr></table></blockquote></div><div class="SIntrapara"><img style="vertical-align: 0px; margin: -3px -3px -3px -3px;" src="pict_10.png" alt="image" width="9" height="16"/></div></p></blockquote><blockquote class="SubFlow"><p><div class="SIntrapara"><a name="(counter._(exercise._ex~3atyping))"></a><span style="font-weight: bold">Exercise</span>&nbsp;7. Extend <span class="RktSym">TLambda</span> with syntax for the
following:
</div><div class="SIntrapara"><ul><li><p>additional numeric operators, say, multiplication, subtraction, and
division;</p></li><li><p><span class="RktSym">let</span> expressions;</p></li><li><p>Boolean constants plus strict and and or operators as well as a
branching construct;</p></li><li><p>lists, specifically constructors and selectors (de-constructors);</p></li><li><p>explicitly recursive function definitions.</p></li></ul></div><div class="SIntrapara">Completing the above list is an ambitious undertaking, but do try to
complete at least two or three of these tasks. <img style="vertical-align: 0px; margin: -3px -3px -3px -3px;" src="pict_11.png" alt="image" width="9" height="16"/></div></p></blockquote><h4 x-source-module="(lib &quot;redex/redex.scrbl&quot;)" x-source-pkg="redex-doc" x-part-tag="&quot;wed-mor&quot;">2.8<tt>&nbsp;</tt><a name="(part._wed-mor)"></a>Imperative Extensions</h4><p><table cellspacing="0" cellpadding="0" class="boxed"><tr><td><p><span style="font-weight: bold">Goals</span></p></td></tr><tr><td><p> &#8212;<wbr></wbr> revise the language for assignment statements</p></td></tr><tr><td><p> &#8212;<wbr></wbr> a standard reduction system for expression-store tuples</p></td></tr><tr><td><p> &#8212;<wbr></wbr> revise the language for raising exceptions</p></td></tr><tr><td><p> &#8212;<wbr></wbr> a general reduction system for exceptions</p></td></tr></table></p><h5 x-source-module="(lib &quot;redex/redex.scrbl&quot;)" x-source-pkg="redex-doc" x-part-tag="&quot;Variable_Assignment&quot;">2.8.1<tt>&nbsp;</tt><a name="(part._.Variable_.Assignment)"></a>Variable Assignment</h5><p><div class="SIntrapara">Let&rsquo;s add variable assignments to our language:
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._define-extended-language%29%29" class="RktStxLink" data-pltdoc="x">define-extended-language</a></span><span class="hspace">&nbsp;</span><span class="RktSym">Assignments</span><span class="hspace">&nbsp;</span><span class="RktSym">Lambda</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._~3a~3a~3d%29%29" class="RktStxLink" data-pltdoc="x">::=</a></span><span class="hspace">&nbsp;</span><span class="RktSym">....</span><span class="hspace">&nbsp;</span><span class="RktSym">n</span><span class="hspace">&nbsp;</span><span class="RktSym">+</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">void</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">set!</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">n</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._~3a~3a~3d%29%29" class="RktStxLink" data-pltdoc="x">::=</a></span><span class="hspace">&nbsp;</span><span class="RktSym">natural</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr></table></blockquote></div><div class="SIntrapara">This makes it like Racket, Scheme and Lisp, but unlike ML where you can
mutate only data structure (one-slot records in SML and slots in arbitrary
records in OCaml.</div></p><p><div class="SIntrapara">For writing programs in this world, you also want blocks and local
declarations. We add a task-specific <span class="RktSym">let</span> expression:
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktCmt">;</span><span class="RktCmt">&nbsp;</span><span class="RktCmt">(let ((x_1 x_2) ...) e_1 e_2) binds the current value of x_2 to x_1,</span></td></tr><tr><td><span class="RktCmt">;</span><span class="RktCmt">&nbsp;</span><span class="RktCmt">evaluates e_1, throws away its value, and finally evaluates e_2 </span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._define-metafunction%29%29" class="RktStxLink" data-pltdoc="x">define-metafunction</a></span><span class="hspace">&nbsp;</span><span class="RktSym">Assignments</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktSym">let</span><span class="hspace">&nbsp;</span><span class="RktSym">:</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">-&gt;</span></span><span class="hspace">&nbsp;</span><span class="RktSym">e</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">let</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">[</span><span class="RktSym">x_lhs</span><span class="hspace">&nbsp;</span><span class="RktSym">e_rhs</span><span class="RktPn">]</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">e_1</span><span class="hspace">&nbsp;</span><span class="RktSym">e_2</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x_lhs</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x_dummy</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">e_2</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">e_1</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktSym">e_rhs</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">where</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x_dummy</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktRdr">,</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28def._%28%28lib._redex%2Freduction-semantics..rkt%29._variables-not-in%29%29" class="RktValLink" data-pltdoc="x">variables-not-in</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e_1</span><span class="hspace">&nbsp;</span><span class="RktSym">e_2</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">'</span><span class="RktVal">(</span><span class="RktVal">dummy</span><span class="RktVal">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">]</span><span class="RktPn">)</span></td></tr></table></blockquote></div></p><p><div class="SIntrapara">Here are some sample programs:
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym">e1</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">y</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">let</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">[</span><span class="RktSym">tmp</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">]</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">set!</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">+</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="hspace">&nbsp;</span><span class="RktVal">1</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktSym">tmp</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym">p-1</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktRdr">,</span><span class="RktSym">e1</span><span class="hspace">&nbsp;</span><span class="RktVal">1</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">2</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym">e2</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">let</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">[</span><span class="RktSym">tmp</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">]</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">set!</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktSym">tmp</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">let</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">[</span><span class="RktSym">tmp-z</span><span class="hspace">&nbsp;</span><span class="RktSym">z</span><span class="RktPn">]</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">set!</span><span class="hspace">&nbsp;</span><span class="RktSym">z</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">+</span><span class="hspace">&nbsp;</span><span class="RktSym">z</span><span class="hspace">&nbsp;</span><span class="RktVal">1</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">let</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">[</span><span class="RktSym">tmp-y</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="RktPn">]</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">set!</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="hspace">&nbsp;</span><span class="RktSym">tmp-z</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktSym">tmp-y</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym">p-2</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">y</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">z</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktRdr">,</span><span class="RktSym">e2</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">1</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">2</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr></table></blockquote></div><div class="SIntrapara">How do they behave?</div></p><p><div class="SIntrapara">For a <span style="font-style: italic">standard reduction relation</span>, we need both evaluation contexts
<span style="font-style: italic">and</span> a table that keeps track of the current value of variables:
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._define-extended-language%29%29" class="RktStxLink" data-pltdoc="x">define-extended-language</a></span><span class="hspace">&nbsp;</span><span class="RktSym">Assignments-s</span><span class="hspace">&nbsp;</span><span class="RktSym">Assignments</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">E</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._~3a~3a~3d%29%29" class="RktStxLink" data-pltdoc="x">::=</a></span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._hole%29%29" class="RktStxLink" data-pltdoc="x">hole</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">v</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="hspace">&nbsp;</span><span class="RktSym">E</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">set!</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">E</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">&#963;</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._~3a~3a~3d%29%29" class="RktStxLink" data-pltdoc="x">::=</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">v</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">v</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._~3a~3a~3d%29%29" class="RktStxLink" data-pltdoc="x">::=</a></span><span class="hspace">&nbsp;</span><span class="RktSym">n</span><span class="hspace">&nbsp;</span><span class="RktSym">+</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">void</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktCmt">;</span><span class="RktCmt">&nbsp;</span><span class="RktCmt">(extend &#963; x v) adds (x v) to &#963;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._define-metafunction%29%29" class="RktStxLink" data-pltdoc="x">define-metafunction</a></span><span class="hspace">&nbsp;</span><span class="RktSym">Assignments-s</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktSym">extend</span><span class="hspace">&nbsp;</span><span class="RktSym">:</span><span class="hspace">&nbsp;</span><span class="RktSym">&#963;</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">any</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">-&gt;</span></span><span class="hspace">&nbsp;</span><span class="RktSym">&#963;</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">extend</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">any</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x_1</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">any_1</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">x_1</span><span class="hspace">&nbsp;</span><span class="RktSym">any_1</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">any</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">]</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktCmt">;</span><span class="RktCmt">&nbsp;</span><span class="RktCmt">&#8212;<wbr></wbr></span><span class="RktCmt">&#8212;<wbr></wbr></span><span class="RktCmt">&#8212;<wbr></wbr></span><span class="RktCmt">&#8212;<wbr></wbr></span><span class="RktCmt">&#8212;<wbr></wbr></span><span class="RktCmt">&#8212;<wbr></wbr></span><span class="RktCmt">&#8212;<wbr></wbr></span><span class="RktCmt">&#8212;<wbr></wbr></span><span class="RktCmt">&#8212;<wbr></wbr></span><span class="RktCmt">&#8212;<wbr></wbr></span><span class="RktCmt">&#8212;<wbr></wbr></span><span class="RktCmt">&#8212;<wbr></wbr></span><span class="RktCmt">&#8212;<wbr></wbr></span><span class="RktCmt">&#8212;<wbr></wbr></span><span class="RktCmt">&#8212;<wbr></wbr></span><span class="RktCmt">&#8212;<wbr></wbr></span><span class="RktCmt">&#8212;<wbr></wbr></span><span class="RktCmt">&#8212;<wbr></wbr></span><span class="RktCmt">&#8212;<wbr></wbr></span><span class="RktCmt">&#8212;<wbr></wbr></span><span class="RktCmt">&#8212;<wbr></wbr></span><span class="RktCmt">&#8212;<wbr></wbr></span><span class="RktCmt">&#8212;<wbr></wbr></span><span class="RktCmt">&#8212;<wbr></wbr></span><span class="RktCmt">&#8212;<wbr></wbr></span><span class="RktCmt">&ndash;</span></td></tr><tr><td><span class="RktCmt">;</span><span class="RktCmt">&nbsp;</span><span class="RktCmt">(lookup &#915; x) retrieves x</span><span class="RktCmt">'</span><span class="RktCmt">s type from &#915;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._define-metafunction%29%29" class="RktStxLink" data-pltdoc="x">define-metafunction</a></span><span class="hspace">&nbsp;</span><span class="RktSym">Assignments-s</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktSym">lookup</span><span class="hspace">&nbsp;</span><span class="RktSym">:</span><span class="hspace">&nbsp;</span><span class="RktSym">any</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">-&gt;</span></span><span class="hspace">&nbsp;</span><span class="RktSym">any</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">lookup</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">x_1</span><span class="hspace">&nbsp;</span><span class="RktSym">any_1</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">any_t</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x_2</span><span class="hspace">&nbsp;</span><span class="RktSym">any_2</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktSym">any_t</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">side-condition</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">not</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">member</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x_1</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">lookup</span><span class="hspace">&nbsp;</span><span class="RktSym">any_1</span><span class="hspace">&nbsp;</span><span class="RktSym">any_2</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktRdr">,</span><span class="RktPn">(</span><span class="RktSym">error</span><span class="hspace">&nbsp;</span><span class="RktVal">'</span><span class="RktVal">lookup</span><span class="hspace">&nbsp;</span><span class="RktVal">"not found: ~e in: ~e"</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktSym">any_2</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">]</span><span class="RktPn">)</span></td></tr></table></blockquote></div><div class="SIntrapara">Extending this table and looking up values in it, is a routine matter by
 now.</div></p><p><div class="SIntrapara">Here is the standard reduction relation:
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym">s-&gt;&#946;s</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._reduction-relation%29%29" class="RktStxLink" data-pltdoc="x">reduction-relation</a></span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktSym">Assignments-s</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">#:domain</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym">&#963;</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._--~3e%29%29" class="RktStxLink" data-pltdoc="x"><span class="nobreak">--&gt;</span></a></span><span class="hspace">&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._in-hole%29%29" class="RktStxLink" data-pltdoc="x">in-hole</a></span><span class="hspace">&nbsp;</span><span class="RktSym">E</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">&#963;</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._in-hole%29%29" class="RktStxLink" data-pltdoc="x">in-hole</a></span><span class="hspace">&nbsp;</span><span class="RktSym">E</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lookup</span><span class="hspace">&nbsp;</span><span class="RktSym">&#963;</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">&#963;</span><span class="RktPn">]</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._--~3e%29%29" class="RktStxLink" data-pltdoc="x"><span class="nobreak">--&gt;</span></a></span><span class="hspace">&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._in-hole%29%29" class="RktStxLink" data-pltdoc="x">in-hole</a></span><span class="hspace">&nbsp;</span><span class="RktSym">E</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">set!</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">v</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">&#963;</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._in-hole%29%29" class="RktStxLink" data-pltdoc="x">in-hole</a></span><span class="hspace">&nbsp;</span><span class="RktSym">E</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">void</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">extend</span><span class="hspace">&nbsp;</span><span class="RktSym">&#963;</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">v</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">]</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._--~3e%29%29" class="RktStxLink" data-pltdoc="x"><span class="nobreak">--&gt;</span></a></span><span class="hspace">&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._in-hole%29%29" class="RktStxLink" data-pltdoc="x">in-hole</a></span><span class="hspace">&nbsp;</span><span class="RktSym">E</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">+</span><span class="hspace">&nbsp;</span><span class="RktSym">n_1</span><span class="hspace">&nbsp;</span><span class="RktSym">n_2</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">&#963;</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._in-hole%29%29" class="RktStxLink" data-pltdoc="x">in-hole</a></span><span class="hspace">&nbsp;</span><span class="RktSym">E</span><span class="hspace">&nbsp;</span><span class="RktRdr">,</span><span class="RktPn">(</span><span class="RktSym">+</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktSym">n_1</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktSym">n_2</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">&#963;</span><span class="RktPn">]</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._--~3e%29%29" class="RktStxLink" data-pltdoc="x"><span class="nobreak">--&gt;</span></a></span><span class="hspace">&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._in-hole%29%29" class="RktStxLink" data-pltdoc="x">in-hole</a></span><span class="hspace">&nbsp;</span><span class="RktSym">E</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">..._n</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">v</span><span class="hspace">&nbsp;</span><span class="RktSym">..._n</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">&#963;</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._in-hole%29%29" class="RktStxLink" data-pltdoc="x">in-hole</a></span><span class="hspace">&nbsp;</span><span class="RktSym">E</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">extend</span><span class="hspace">&nbsp;</span><span class="RktSym">&#963;</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x_new</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">v</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">where</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x_new</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktRdr">,</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28def._%28%28lib._redex%2Freduction-semantics..rkt%29._variables-not-in%29%29" class="RktValLink" data-pltdoc="x">variables-not-in</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktSym">&#963;</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr></table></blockquote></div><div class="SIntrapara">The question is what the corresponding calculus looks like. See
 <a href="#%28part._lab-wed-mor%29" data-pltdoc="x"><span style="font-weight: bold">Lab</span> Contexts and Stores</a>.</div></p><p><span style="font-weight: bold">This use of the standard reduction relation is common because most
researchers <span style="font-style: italic">do not need</span> the calculus. Instead they define such a
relation and consider it a semantics.</span></p><p><div class="SIntrapara">The semantics is a function, however, that maps programs to the final
answers and possibly extracts pieces from the store.
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym">module+</span><span class="hspace">&nbsp;</span><span class="RktSym">test</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">eval-assignments</span><span class="hspace">&nbsp;</span><span class="RktRdr">,</span><span class="RktSym">p-1</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">1</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">eval-assignments</span><span class="hspace">&nbsp;</span><span class="RktRdr">,</span><span class="RktSym">p-2</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">2</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">eval-assignments</span><span class="hspace">&nbsp;</span><span class="RktRdr">,</span><span class="RktSym">p-c</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktSym">closure</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._define-metafunction%29%29" class="RktStxLink" data-pltdoc="x">define-metafunction</a></span><span class="hspace">&nbsp;</span><span class="RktSym">Assignments-s</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktSym">eval-assignments</span><span class="hspace">&nbsp;</span><span class="RktSym">:</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">-&gt;</span></span><span class="hspace">&nbsp;</span><span class="RktSym">v</span><span class="hspace">&nbsp;</span><span class="RktSym">or</span><span class="hspace">&nbsp;</span><span class="RktSym">closure</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">eval-assignments</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">run-assignments</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">]</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._define-metafunction%29%29" class="RktStxLink" data-pltdoc="x">define-metafunction</a></span><span class="hspace">&nbsp;</span><span class="RktSym">Assignments-s</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktSym">run-assignments</span><span class="hspace">&nbsp;</span><span class="RktSym">:</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym">&#963;</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">-&gt;</span></span><span class="hspace">&nbsp;</span><span class="RktSym">v</span><span class="hspace">&nbsp;</span><span class="RktSym">or</span><span class="hspace">&nbsp;</span><span class="RktSym">closure</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">run-assignments</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">n</span><span class="hspace">&nbsp;</span><span class="RktSym">&#963;</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">n</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">run-assignments</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">v</span><span class="hspace">&nbsp;</span><span class="RktSym">&#963;</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">closure</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">run-assignments</span><span class="hspace">&nbsp;</span><span class="RktSym">any_1</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">run-assignments</span><span class="hspace">&nbsp;</span><span class="RktSym">any_again</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">where</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">any_again</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktRdr">,</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28def._%28%28lib._redex%2Freduction-semantics..rkt%29._apply-reduction-relation%29%29" class="RktValLink" data-pltdoc="x">apply-reduction-relation</a></span><span class="hspace">&nbsp;</span><span class="RktSym">s-&gt;&#946;s</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktSym">any_1</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">run-assignments</span><span class="hspace">&nbsp;</span><span class="RktSym">any</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">stuck</span><span class="RktPn">]</span><span class="RktPn">)</span></td></tr></table></blockquote></div></p><h5 x-source-module="(lib &quot;redex/redex.scrbl&quot;)" x-source-pkg="redex-doc" x-part-tag="&quot;Raising_Exceptions&quot;">2.8.2<tt>&nbsp;</tt><a name="(part._.Raising_.Exceptions)"></a>Raising Exceptions</h5><p>When non-local control operators come such as ML&rsquo;s exceptions come into
play, reductions become (evaluation-) context-sensitive.</p><p><div class="SIntrapara">Here is a language with a simple construct for raising exceptions:
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._define-extended-language%29%29" class="RktStxLink" data-pltdoc="x">define-extended-language</a></span><span class="hspace">&nbsp;</span><span class="RktSym">Exceptions</span><span class="hspace">&nbsp;</span><span class="RktSym">Lambda</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._~3a~3a~3d%29%29" class="RktStxLink" data-pltdoc="x">::=</a></span><span class="hspace">&nbsp;</span><span class="RktSym">....</span><span class="hspace">&nbsp;</span><span class="RktSym">n</span><span class="hspace">&nbsp;</span><span class="RktSym">+</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">raise</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">n</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._~3a~3a~3d%29%29" class="RktStxLink" data-pltdoc="x">::=</a></span><span class="hspace">&nbsp;</span><span class="RktSym">integer</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr></table></blockquote></div><div class="SIntrapara"><span style="font-weight: bold">History</span> This form of exception was actually introduced into Lisp as
 the <span class="stt">catch</span> and <span class="stt">throw</span> combination (contrary to some statements in
 Turing-award announcements).</div></p><p><div class="SIntrapara">Try to figure out what these expressions ought to compute:
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym">c1</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">+</span><span class="hspace">&nbsp;</span><span class="RktVal">1</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">raise</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">+</span><span class="hspace">&nbsp;</span><span class="RktVal">1</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktVal">0</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym">c2</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">y</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">+</span><span class="hspace">&nbsp;</span><span class="RktVal">1</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">raise</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">+</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">raise</span><span class="hspace">&nbsp;</span><span class="RktVal"><span class="nobreak">-1</span></span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktVal">0</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr></table></blockquote></div></p><p><div class="SIntrapara">A calculus of exceptions needs both arbitrary term contexts and evaluation
contexts:
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._define-extended-language%29%29" class="RktStxLink" data-pltdoc="x">define-extended-language</a></span><span class="hspace">&nbsp;</span><span class="RktSym">Exceptions-s</span><span class="hspace">&nbsp;</span><span class="RktSym">Exceptions</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">C</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._~3a~3a~3d%29%29" class="RktStxLink" data-pltdoc="x">::=</a></span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._hole%29%29" class="RktStxLink" data-pltdoc="x">hole</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="hspace">&nbsp;</span><span class="RktSym">C</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">C</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">raise</span><span class="hspace">&nbsp;</span><span class="RktSym">C</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">E</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._~3a~3a~3d%29%29" class="RktStxLink" data-pltdoc="x">::=</a></span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._hole%29%29" class="RktStxLink" data-pltdoc="x">hole</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">v</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="hspace">&nbsp;</span><span class="RktSym">E</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">raise</span><span class="hspace">&nbsp;</span><span class="RktSym">E</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">v</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._~3a~3a~3d%29%29" class="RktStxLink" data-pltdoc="x">::=</a></span><span class="hspace">&nbsp;</span><span class="RktSym">n</span><span class="hspace">&nbsp;</span><span class="RktSym">+</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr></table></blockquote></div></p><p><div class="SIntrapara">The key insight is that an exception-raising construct erases any
surrounding evaluation context, regardless of where it shows up:
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym">module+</span><span class="hspace">&nbsp;</span><span class="RktSym">test</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test--~3e~3e%29%29" class="RktStxLink" data-pltdoc="x">test--&gt;&gt;</a></span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">-&gt;</span>&#946;c</span><span class="hspace">&nbsp;</span><span class="RktSym">c1</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">raise</span><span class="hspace">&nbsp;</span><span class="RktVal">1</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test--~3e~3e%29%29" class="RktStxLink" data-pltdoc="x">test--&gt;&gt;</a></span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">-&gt;</span>&#946;c</span><span class="hspace">&nbsp;</span><span class="RktSym">c2</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">y</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">raise</span><span class="hspace">&nbsp;</span><span class="RktVal"><span class="nobreak">-1</span></span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">-&gt;</span>&#946;c</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._reduction-relation%29%29" class="RktStxLink" data-pltdoc="x">reduction-relation</a></span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktSym">Exceptions-s</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._--~3e%29%29" class="RktStxLink" data-pltdoc="x"><span class="nobreak">--&gt;</span></a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._in-hole%29%29" class="RktStxLink" data-pltdoc="x">in-hole</a></span><span class="hspace">&nbsp;</span><span class="RktSym">C</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._in-hole%29%29" class="RktStxLink" data-pltdoc="x">in-hole</a></span><span class="hspace">&nbsp;</span><span class="RktSym">E</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">raise</span><span class="hspace">&nbsp;</span><span class="RktSym">v</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._in-hole%29%29" class="RktStxLink" data-pltdoc="x">in-hole</a></span><span class="hspace">&nbsp;</span><span class="RktSym">C</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">raise</span><span class="hspace">&nbsp;</span><span class="RktSym">v</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">where</span><span class="hspace">&nbsp;</span><span class="RktVal">#false</span><span class="hspace">&nbsp;</span><span class="RktRdr">,</span><span class="RktPn">(</span><span class="RktSym">equal?</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktSym">E</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._hole%29%29" class="RktStxLink" data-pltdoc="x">hole</a></span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktSym">&#950;</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._--~3e%29%29" class="RktStxLink" data-pltdoc="x"><span class="nobreak">--&gt;</span></a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._in-hole%29%29" class="RktStxLink" data-pltdoc="x">in-hole</a></span><span class="hspace">&nbsp;</span><span class="RktSym">C</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">+</span><span class="hspace">&nbsp;</span><span class="RktSym">n_1</span><span class="hspace">&nbsp;</span><span class="RktSym">n_2</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._in-hole%29%29" class="RktStxLink" data-pltdoc="x">in-hole</a></span><span class="hspace">&nbsp;</span><span class="RktSym">C</span><span class="hspace">&nbsp;</span><span class="RktRdr">,</span><span class="RktPn">(</span><span class="RktSym">+</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktSym">n_1</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktSym">n_2</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktSym">+</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._--~3e%29%29" class="RktStxLink" data-pltdoc="x"><span class="nobreak">--&gt;</span></a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._in-hole%29%29" class="RktStxLink" data-pltdoc="x">in-hole</a></span><span class="hspace">&nbsp;</span><span class="RktSym">C</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x_1</span><span class="hspace">&nbsp;</span><span class="RktSym">..._n</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">v_1</span><span class="hspace">&nbsp;</span><span class="RktSym">..._n</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._in-hole%29%29" class="RktStxLink" data-pltdoc="x">in-hole</a></span><span class="hspace">&nbsp;</span><span class="RktSym">C</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">subst</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">[</span><span class="RktSym">v_1</span><span class="hspace">&nbsp;</span><span class="RktSym">x_1</span><span class="RktPn">]</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktSym">&#946;_v</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr></table></blockquote></div><div class="SIntrapara">The question is what a standard reduction relation for such a calculus
 looks like. See <a href="#%28part._lab-wed-mor%29" data-pltdoc="x"><span style="font-weight: bold">Lab</span> Contexts and Stores</a>.</div></p><h4 x-source-module="(lib &quot;redex/redex.scrbl&quot;)" x-source-pkg="redex-doc" x-part-tag="&quot;lab-wed-mor&quot;">2.9<tt>&nbsp;</tt><a name="(part._lab-wed-mor)"></a><span style="font-weight: bold">Lab</span> Contexts and Stores</h4><p><table cellspacing="0" cellpadding="0" class="boxed"><tr><td><p><span style="font-weight: bold">Goals</span></p></td></tr><tr><td><p> &#8212;<wbr></wbr> develop a general reduction system for Lambda with assignments</p></td></tr><tr><td><p> &#8212;<wbr></wbr> develop a standard reduction system for Lambda with exceptions</p></td></tr></table></p><p><div class="SIntrapara">The following exercises refer to several definitions found in, and exported
from, <a href="common.rkt">common.rkt</a>. You may either copy these
definitions into your file or add the following <span class="RktSym">require</span> statement
to the top of your file:
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><p><span class="RktPn">(</span><span class="RktSym">require</span><span class="hspace">&nbsp;</span><span class="RktVal">"common.rkt"</span><span class="RktPn">)</span></p></blockquote></div></p><p>Also require <a href="extend-lookup.rkt">extend-lookup.rkt</a>. Feel free to
copy code from <a href="#%28part._wed-mor%29" data-pltdoc="x">Imperative Extensions</a> but make sure to add tests.</p><h5 x-source-module="(lib &quot;redex/redex.scrbl&quot;)" x-source-pkg="redex-doc" x-part-tag="&quot;lwm&quot;"><a name="(part._lwm)"></a>Exercises</h5><p>The exercises this morning are puzzles. Try your hands on them, but when
you feel stuck, don&rsquo;t hesitate to request help.</p><blockquote class="SubFlow"><p><div class="SIntrapara"><a name="(counter._(exercise._ex~3acalculus-assignments))"></a><span style="font-weight: bold">Exercise</span>&nbsp;8. Develop a reduction relation for
assignment statements. Add a <span class="RktSym">letrec</span> syntax to the language like
this:
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._define-extended-language%29%29" class="RktStxLink" data-pltdoc="x">define-extended-language</a></span><span class="hspace">&nbsp;</span><span class="RktSym">ImperativeCalculus</span><span class="hspace">&nbsp;</span><span class="RktSym">Assignments</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._~3a~3a~3d%29%29" class="RktStxLink" data-pltdoc="x">::=</a></span><span class="hspace">&nbsp;</span><span class="RktSym">....</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">letrec</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">v</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr></table></blockquote></div><div class="SIntrapara">A <span class="RktSym">letrec</span> mutually recursively binds the variables <span class="RktSym">x</span><span class="stt"> </span><span class="RktSym">...</span>
 to the values <span class="RktSym">v</span><span class="stt"> </span><span class="RktSym">...</span> and in <span class="RktSym">e</span>. The addition of
 <span class="RktSym">letrec</span> internalizes the store into the language. Adapt the
 existing relations.</div></p><p>Develop terms that one-step reduce in several different directions via
reductions that model assignment and/or variable derefences. Use
<span class="RktSym">trace</span> graphs to demonstrate the idea.</p><p><span style="font-weight: bold">Note</span> This calculus has naturally separated mini-heaps, but your
system must extrude the scope of these heaps on occasion (when values are
returned) and merge them. <img style="vertical-align: 0px; margin: -3px -3px -3px -3px;" src="pict_12.png" alt="image" width="9" height="16"/></p></blockquote><blockquote class="SubFlow"><p><a name="(counter._(exercise._ex~3aexn-semantics))"></a><span style="font-weight: bold">Exercise</span>&nbsp;9. Develop a standard reduction system and a
semantics for exceptions.</p><p><span style="font-weight: bold">Note</span> You need to use evaluation contexts for two distinct purposes. <img style="vertical-align: 0px; margin: -3px -3px -3px -3px;" src="pict_13.png" alt="image" width="9" height="16"/></p></blockquote><blockquote class="SubFlow"><p><a name="(counter._(exercise._ex~3acallcc))"></a><span style="font-weight: bold">Exercise</span>&nbsp;10. Develop a semantics of for a control operator such as
<span class="RktSym">callcc</span>.</p><p><span style="font-weight: bold">Request</span> Check with one of us before you embark on this project. We
want to make sure that (1) the operator isn&rsquo;t too difficult and (2) not to
easy to implement. We are also available for hints. <img style="vertical-align: 0px; margin: -3px -3px -3px -3px;" src="pict_14.png" alt="image" width="9" height="16"/></p></blockquote><h4 x-source-module="(lib &quot;redex/redex.scrbl&quot;)" x-source-pkg="redex-doc" x-part-tag="&quot;wed-aft&quot;">2.10<tt>&nbsp;</tt><a name="(part._wed-aft)"></a>Abstract Machines</h4><p><table cellspacing="0" cellpadding="0" class="boxed"><tr><td><p><span style="font-weight: bold">Goals</span></p></td></tr><tr><td><p> &#8212;<wbr></wbr> why these three machines: CC machine, CK machine, CEK machine</p></td></tr><tr><td><p> &#8212;<wbr></wbr> theorems connecting the machines, theorems for debugging</p></td></tr><tr><td><p> &#8212;<wbr></wbr> equivalence theorems</p></td></tr></table></p><h5 x-source-module="(lib &quot;redex/redex.scrbl&quot;)" x-source-pkg="redex-doc" x-part-tag="&quot;CC_Machine&quot;">2.10.1<tt>&nbsp;</tt><a name="(part._.C.C_.Machine)"></a>CC Machine</h5><p><span style="font-weight: bold">Observation</span> &#946; and &#946;_v redexes often take place repeatedly in the
same evaluation context. On occasion they just add more layers (inside the
hole) to the evaluation context. Let&rsquo;s separate the in-focus expression
from the evaluation context. Historically the two have been called
<span style="font-style: italic">control string</span> (C) and <span style="font-style: italic">control context</span> (C).</p><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._define-extended-language%29%29" class="RktStxLink" data-pltdoc="x">define-extended-language</a></span><span class="hspace">&nbsp;</span><span class="RktSym">Lambda/v</span><span class="hspace">&nbsp;</span><span class="RktSym">Lambda</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._~3a~3a~3d%29%29" class="RktStxLink" data-pltdoc="x">::=</a></span><span class="hspace">&nbsp;</span><span class="RktSym">....</span><span class="hspace">&nbsp;</span><span class="RktSym">n</span><span class="hspace">&nbsp;</span><span class="RktSym">+</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">n</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._~3a~3a~3d%29%29" class="RktStxLink" data-pltdoc="x">::=</a></span><span class="hspace">&nbsp;</span><span class="RktSym">integer</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">v</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._~3a~3a~3d%29%29" class="RktStxLink" data-pltdoc="x">::=</a></span><span class="hspace">&nbsp;</span><span class="RktSym">n</span><span class="hspace">&nbsp;</span><span class="RktSym">+</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym">vv?</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._redex-match~3f%29%29" class="RktStxLink" data-pltdoc="x">redex-match?</a></span><span class="hspace">&nbsp;</span><span class="RktSym">Lambda/v</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym">e0</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">0</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym">e1</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">y</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">1</span><span class="hspace">&nbsp;</span><span class="RktVal">2</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym">module+</span><span class="hspace">&nbsp;</span><span class="RktSym">test</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">vv?</span><span class="hspace">&nbsp;</span><span class="RktSym">e1</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">#true</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">vv?</span><span class="hspace">&nbsp;</span><span class="RktSym">e0</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">#true</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktCmt">;</span><span class="RktCmt">&nbsp;</span><span class="RktCmt">&#8212;<wbr></wbr></span><span class="RktCmt">&#8212;<wbr></wbr></span><span class="RktCmt">&#8212;<wbr></wbr></span><span class="RktCmt">&#8212;<wbr></wbr></span><span class="RktCmt">&#8212;<wbr></wbr></span><span class="RktCmt">&#8212;<wbr></wbr></span><span class="RktCmt">&#8212;<wbr></wbr></span><span class="RktCmt">&#8212;<wbr></wbr></span><span class="RktCmt">&#8212;<wbr></wbr></span><span class="RktCmt">&#8212;<wbr></wbr></span><span class="RktCmt">&#8212;<wbr></wbr></span><span class="RktCmt">&#8212;<wbr></wbr></span><span class="RktCmt">&#8212;<wbr></wbr></span><span class="RktCmt">&#8212;<wbr></wbr></span><span class="RktCmt">&#8212;<wbr></wbr></span><span class="RktCmt">&#8212;<wbr></wbr></span><span class="RktCmt">&#8212;<wbr></wbr></span><span class="RktCmt">&#8212;<wbr></wbr></span><span class="RktCmt">&#8212;<wbr></wbr></span><span class="RktCmt">&#8212;<wbr></wbr></span><span class="RktCmt">&#8212;<wbr></wbr></span><span class="RktCmt">&#8212;<wbr></wbr></span><span class="RktCmt">&#8212;<wbr></wbr></span><span class="RktCmt">&#8212;<wbr></wbr></span><span class="RktCmt">&#8212;<wbr></wbr></span><span class="RktCmt">&ndash;</span></td></tr><tr><td><span class="RktCmt">;</span><span class="RktCmt">&nbsp;</span><span class="RktCmt">the CC machine: keep contexts and expression-in-focus apart</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._define-extended-language%29%29" class="RktStxLink" data-pltdoc="x">define-extended-language</a></span><span class="hspace">&nbsp;</span><span class="RktSym">CC</span><span class="hspace">&nbsp;</span><span class="RktSym">Lambda/v</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">E</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._~3a~3a~3d%29%29" class="RktStxLink" data-pltdoc="x">::=</a></span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._hole%29%29" class="RktStxLink" data-pltdoc="x">hole</a></span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktCmt">;</span><span class="RktCmt">&nbsp;</span><span style="font-weight: bold">Note</span><span class="RktCmt"> right to left evaluation of application </span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="hspace">&nbsp;</span><span class="RktSym">E</span><span class="hspace">&nbsp;</span><span class="RktSym">v</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym">module+</span><span class="hspace">&nbsp;</span><span class="RktSym">test</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test--~3e~3e%29%29" class="RktStxLink" data-pltdoc="x">test--&gt;&gt;</a></span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">--&gt;</span>cc</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">[</span><span class="RktRdr">,</span><span class="RktSym">e0</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._hole%29%29" class="RktStxLink" data-pltdoc="x">hole</a></span><span class="RktPn">]</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">[</span><span class="RktVal">0</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._hole%29%29" class="RktStxLink" data-pltdoc="x">hole</a></span><span class="RktPn">]</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test--~3e~3e%29%29" class="RktStxLink" data-pltdoc="x">test--&gt;&gt;</a></span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">--&gt;</span>cc</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">[</span><span class="RktRdr">,</span><span class="RktSym">e1</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._hole%29%29" class="RktStxLink" data-pltdoc="x">hole</a></span><span class="RktPn">]</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">[</span><span class="RktVal">1</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._hole%29%29" class="RktStxLink" data-pltdoc="x">hole</a></span><span class="RktPn">]</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">--&gt;</span>cc</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._reduction-relation%29%29" class="RktStxLink" data-pltdoc="x">reduction-relation</a></span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktSym">CC</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">#:domain</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym">E</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._--~3e%29%29" class="RktStxLink" data-pltdoc="x"><span class="nobreak">--&gt;</span></a></span><span class="hspace">&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">..._n</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._in-hole%29%29" class="RktStxLink" data-pltdoc="x">in-hole</a></span><span class="hspace">&nbsp;</span><span class="RktSym">E</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._hole%29%29" class="RktStxLink" data-pltdoc="x">hole</a></span><span class="hspace">&nbsp;</span><span class="RktSym">v</span><span class="hspace">&nbsp;</span><span class="RktSym">..._n</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">subst</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">[</span><span class="RktSym">v</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">]</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">E</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktSym">CC-&#946;_v</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._--~3e%29%29" class="RktStxLink" data-pltdoc="x"><span class="nobreak">--&gt;</span></a></span><span class="hspace">&nbsp;</span><span class="RktPn">[</span><span class="RktSym">+</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._in-hole%29%29" class="RktStxLink" data-pltdoc="x">in-hole</a></span><span class="hspace">&nbsp;</span><span class="RktSym">E</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._hole%29%29" class="RktStxLink" data-pltdoc="x">hole</a></span><span class="hspace">&nbsp;</span><span class="RktSym">n_1</span><span class="hspace">&nbsp;</span><span class="RktSym">n_2</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktRdr">,</span><span class="RktPn">(</span><span class="RktSym">+</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktSym">n_1</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktSym">n_2</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">E</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktSym">CC-+</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._--~3e%29%29" class="RktStxLink" data-pltdoc="x"><span class="nobreak">--&gt;</span></a></span><span class="hspace">&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">e_1</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">E</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktSym">e_last</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._in-hole%29%29" class="RktStxLink" data-pltdoc="x">in-hole</a></span><span class="hspace">&nbsp;</span><span class="RktSym">E</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e_1others</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._hole%29%29" class="RktStxLink" data-pltdoc="x">hole</a></span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">where</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e_1others</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="hspace">&nbsp;</span><span class="RktSym">e_last</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e_1</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktSym">CC-push</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._--~3e%29%29" class="RktStxLink" data-pltdoc="x"><span class="nobreak">--&gt;</span></a></span><span class="hspace">&nbsp;</span><span class="RktPn">[</span><span class="RktSym">v</span><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._in-hole%29%29" class="RktStxLink" data-pltdoc="x">in-hole</a></span><span class="hspace">&nbsp;</span><span class="RktSym">E</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._hole%29%29" class="RktStxLink" data-pltdoc="x">hole</a></span><span class="hspace">&nbsp;</span><span class="RktSym">v_1</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktSym">e_last</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._in-hole%29%29" class="RktStxLink" data-pltdoc="x">in-hole</a></span><span class="hspace">&nbsp;</span><span class="RktSym">E</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e_prefix</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._hole%29%29" class="RktStxLink" data-pltdoc="x">hole</a></span><span class="hspace">&nbsp;</span><span class="RktSym">v</span><span class="hspace">&nbsp;</span><span class="RktSym">v_1</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">where</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e_prefix</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="hspace">&nbsp;</span><span class="RktSym">e_last</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktSym">CC-switch</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym">module+</span><span class="hspace">&nbsp;</span><span class="RktSym">test</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">eval-cc</span><span class="hspace">&nbsp;</span><span class="RktRdr">,</span><span class="RktSym">e0</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">0</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">eval-cc</span><span class="hspace">&nbsp;</span><span class="RktRdr">,</span><span class="RktSym">e1</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">1</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._define-metafunction%29%29" class="RktStxLink" data-pltdoc="x">define-metafunction</a></span><span class="hspace">&nbsp;</span><span class="RktSym">Lambda/v</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktSym">eval-cc</span><span class="hspace">&nbsp;</span><span class="RktSym">:</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">-&gt;</span></span><span class="hspace">&nbsp;</span><span class="RktSym">v</span><span class="hspace">&nbsp;</span><span class="RktSym">or</span><span class="hspace">&nbsp;</span><span class="RktSym">closure</span><span class="hspace">&nbsp;</span><span class="RktSym">or</span><span class="hspace">&nbsp;</span><span class="RktSym">stuck</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">eval-cc</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">run-cc</span><span class="hspace">&nbsp;</span><span class="RktPn">[</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._hole%29%29" class="RktStxLink" data-pltdoc="x">hole</a></span><span class="RktPn">]</span><span class="RktPn">)</span><span class="RktPn">]</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._define-metafunction%29%29" class="RktStxLink" data-pltdoc="x">define-metafunction</a></span><span class="hspace">&nbsp;</span><span class="RktSym">CC</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktSym">run-cc</span><span class="hspace">&nbsp;</span><span class="RktSym">:</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym">E</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">-&gt;</span></span><span class="hspace">&nbsp;</span><span class="RktSym">v</span><span class="hspace">&nbsp;</span><span class="RktSym">or</span><span class="hspace">&nbsp;</span><span class="RktSym">closure</span><span class="hspace">&nbsp;</span><span class="RktSym">or</span><span class="hspace">&nbsp;</span><span class="RktSym">stuck</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">run-cc</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">n</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._hole%29%29" class="RktStxLink" data-pltdoc="x">hole</a></span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">n</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">run-cc</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">v</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._hole%29%29" class="RktStxLink" data-pltdoc="x">hole</a></span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">closure</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">run-cc</span><span class="hspace">&nbsp;</span><span class="RktSym">any_1</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">run-cc</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e_again</span><span class="hspace">&nbsp;</span><span class="RktSym">E_again</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">where</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">e_again</span><span class="hspace">&nbsp;</span><span class="RktSym">E_again</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktRdr">,</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28def._%28%28lib._redex%2Freduction-semantics..rkt%29._apply-reduction-relation%29%29" class="RktValLink" data-pltdoc="x">apply-reduction-relation</a></span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">--&gt;</span>cc</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktSym">any_1</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">run-cc</span><span class="hspace">&nbsp;</span><span class="RktSym">any</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">stuck</span><span class="RktPn">]</span><span class="RktPn">)</span></td></tr></table></blockquote><h5 x-source-module="(lib &quot;redex/redex.scrbl&quot;)" x-source-pkg="redex-doc" x-part-tag="&quot;The_CK_Machine&quot;">2.10.2<tt>&nbsp;</tt><a name="(part._.The_.C.K_.Machine)"></a>The CK Machine</h5><p><span style="font-weight: bold">Observation</span> The evaluation context of the CC machine behaves exactly
like a control stack. Let&rsquo;s represent it as such.</p><p><span style="font-weight: bold">General Idea</span> The general idea is to show how valuable it is to
reconsider data representations in PL, and how easy it is to do so in
Redex.</p><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._define-extended-language%29%29" class="RktStxLink" data-pltdoc="x">define-extended-language</a></span><span class="hspace">&nbsp;</span><span class="RktSym">CK</span><span class="hspace">&nbsp;</span><span class="RktSym">Lambda/v</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktCmt">;</span><span class="RktCmt">&nbsp;</span><span style="font-weight: bold">Note</span><span class="RktCmt"> encode context as stack (left is top)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">k</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._~3a~3a~3d%29%29" class="RktStxLink" data-pltdoc="x">::=</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">app</span><span class="hspace">&nbsp;</span><span class="RktPn">[</span><span class="RktSym">v</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">]</span><span class="hspace">&nbsp;</span><span class="RktPn">[</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">]</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym">module+</span><span class="hspace">&nbsp;</span><span class="RktSym">test</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test--~3e~3e%29%29" class="RktStxLink" data-pltdoc="x">test--&gt;&gt;</a></span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">--&gt;</span>ck</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">[</span><span class="RktRdr">,</span><span class="RktSym">e0</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span><span class="RktPn">]</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">[</span><span class="RktVal">0</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span><span class="RktPn">]</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test--~3e~3e%29%29" class="RktStxLink" data-pltdoc="x">test--&gt;&gt;</a></span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">--&gt;</span>ck</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">[</span><span class="RktRdr">,</span><span class="RktSym">e1</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span><span class="RktPn">]</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">[</span><span class="RktVal">1</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span><span class="RktPn">]</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">--&gt;</span>ck</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._reduction-relation%29%29" class="RktStxLink" data-pltdoc="x">reduction-relation</a></span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktSym">CK</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">#:domain</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym">k</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._--~3e%29%29" class="RktStxLink" data-pltdoc="x"><span class="nobreak">--&gt;</span></a></span><span class="hspace">&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">..._n</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">app</span><span class="hspace">&nbsp;</span><span class="RktPn">[</span><span class="RktSym">v</span><span class="hspace">&nbsp;</span><span class="RktSym">..._n</span><span class="RktPn">]</span><span class="hspace">&nbsp;</span><span class="RktPn">[</span><span class="RktPn">]</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">app</span><span class="hspace">&nbsp;</span><span class="RktSym">any_v</span><span class="hspace">&nbsp;</span><span class="RktSym">any_e</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">subst</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">[</span><span class="RktSym">v</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="RktPn">]</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">app</span><span class="hspace">&nbsp;</span><span class="RktSym">any_v</span><span class="hspace">&nbsp;</span><span class="RktSym">any_e</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktSym">CK-&#946;_v</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._--~3e%29%29" class="RktStxLink" data-pltdoc="x"><span class="nobreak">--&gt;</span></a></span><span class="hspace">&nbsp;</span><span class="RktPn">[</span><span class="RktSym">+</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">app</span><span class="hspace">&nbsp;</span><span class="RktPn">[</span><span class="RktSym">n_1</span><span class="hspace">&nbsp;</span><span class="RktSym">n_2</span><span class="RktPn">]</span><span class="hspace">&nbsp;</span><span class="RktPn">[</span><span class="RktPn">]</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">app</span><span class="hspace">&nbsp;</span><span class="RktSym">any_v</span><span class="hspace">&nbsp;</span><span class="RktSym">any_e</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktRdr">,</span><span class="RktPn">(</span><span class="RktSym">+</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktSym">n_1</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktSym">n_2</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">app</span><span class="hspace">&nbsp;</span><span class="RktSym">any_v</span><span class="hspace">&nbsp;</span><span class="RktSym">any_e</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktSym">CK-+</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._--~3e%29%29" class="RktStxLink" data-pltdoc="x"><span class="nobreak">--&gt;</span></a></span><span class="hspace">&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">e_1</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">any_k</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktSym">e_last</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">app</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e_1others</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">any_k</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">where</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e_1others</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="hspace">&nbsp;</span><span class="RktSym">e_last</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e_1</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktSym">CK-push</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._--~3e%29%29" class="RktStxLink" data-pltdoc="x"><span class="nobreak">--&gt;</span></a></span><span class="hspace">&nbsp;</span><span class="RktPn">[</span><span class="RktSym">v</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">app</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">v_1</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">any_k</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktSym">e_last</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">app</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">v</span><span class="hspace">&nbsp;</span><span class="RktSym">v_1</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e_prefix</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">any_k</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">where</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e_prefix</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="hspace">&nbsp;</span><span class="RktSym">e_last</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktSym">CK-switch</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym">module+</span><span class="hspace">&nbsp;</span><span class="RktSym">test</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">eval-ck</span><span class="hspace">&nbsp;</span><span class="RktRdr">,</span><span class="RktSym">e0</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">0</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">eval-ck</span><span class="hspace">&nbsp;</span><span class="RktRdr">,</span><span class="RktSym">e1</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">1</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._define-metafunction%29%29" class="RktStxLink" data-pltdoc="x">define-metafunction</a></span><span class="hspace">&nbsp;</span><span class="RktSym">Lambda/v</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktSym">eval-ck</span><span class="hspace">&nbsp;</span><span class="RktSym">:</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">-&gt;</span></span><span class="hspace">&nbsp;</span><span class="RktSym">v</span><span class="hspace">&nbsp;</span><span class="RktSym">or</span><span class="hspace">&nbsp;</span><span class="RktSym">closure</span><span class="hspace">&nbsp;</span><span class="RktSym">or</span><span class="hspace">&nbsp;</span><span class="RktSym">stuck</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">eval-ck</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">run-ck</span><span class="hspace">&nbsp;</span><span class="RktPn">[</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span><span class="RktPn">]</span><span class="RktPn">)</span><span class="RktPn">]</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._define-metafunction%29%29" class="RktStxLink" data-pltdoc="x">define-metafunction</a></span><span class="hspace">&nbsp;</span><span class="RktSym">CK</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktSym">run-ck</span><span class="hspace">&nbsp;</span><span class="RktSym">:</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym">k</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">-&gt;</span></span><span class="hspace">&nbsp;</span><span class="RktSym">v</span><span class="hspace">&nbsp;</span><span class="RktSym">or</span><span class="hspace">&nbsp;</span><span class="RktSym">closure</span><span class="hspace">&nbsp;</span><span class="RktSym">or</span><span class="hspace">&nbsp;</span><span class="RktSym">stuck</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">run-ck</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">n</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">n</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">run-ck</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">v</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">closure</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">run-ck</span><span class="hspace">&nbsp;</span><span class="RktSym">any_1</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">run-ck</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e_again</span><span class="hspace">&nbsp;</span><span class="RktSym">k_again</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">where</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">e_again</span><span class="hspace">&nbsp;</span><span class="RktSym">k_again</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktRdr">,</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28def._%28%28lib._redex%2Freduction-semantics..rkt%29._apply-reduction-relation%29%29" class="RktValLink" data-pltdoc="x">apply-reduction-relation</a></span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">--&gt;</span>ck</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktSym">any_1</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">run-ck</span><span class="hspace">&nbsp;</span><span class="RktSym">any</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">stuck</span><span class="RktPn">]</span><span class="RktPn">)</span></td></tr></table></blockquote><h5 x-source-module="(lib &quot;redex/redex.scrbl&quot;)" x-source-pkg="redex-doc" x-part-tag="&quot;The_CC-CK_Theorem&quot;">2.10.3<tt>&nbsp;</tt><a name="(part._.The_.C.C-.C.K_.Theorem)"></a>The CC-CK Theorem</h5><p>The two machines define the same evaluation function. Let&rsquo;s formulate this
as a theorem and <span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._redex-check%29%29" class="RktStxLink" data-pltdoc="x">redex-check</a></span> it.</p><p><span style="font-weight: bold">Note</span> When I prepared these notes, I found two mistakes in my
machines.</p><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym">module+</span><span class="hspace">&nbsp;</span><span class="RktSym">test</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktCmt">;</span><span class="RktCmt">&nbsp;</span><span class="RktCmt">theorem:eval-ck=eval-cc</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">theorem:eval-ck=eval-cc</span><span class="hspace">&nbsp;</span><span class="RktRdr">,</span><span class="RktSym">e0</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">#true</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">theorem:eval-ck=eval-cc</span><span class="hspace">&nbsp;</span><span class="RktRdr">,</span><span class="RktSym">e1</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">#true</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktCmt">;</span><span class="RktCmt">&nbsp;</span><span class="RktCmt">NEXT: CEK vs CK </span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._redex-check%29%29" class="RktStxLink" data-pltdoc="x">redex-check</a></span><span class="hspace">&nbsp;</span><span class="RktSym">Lambda</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">theorem:eval-ck=eval-cc</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">#:attempts</span><span class="hspace">&nbsp;</span><span class="RktVal">24</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">#:prepare</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">close-all-fv</span><span class="hspace">&nbsp;</span><span class="RktSym">vv?</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._define-metafunction%29%29" class="RktStxLink" data-pltdoc="x">define-metafunction</a></span><span class="hspace">&nbsp;</span><span class="RktSym">Lambda/v</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktSym">theorem:eval-ck=eval-cc</span><span class="hspace">&nbsp;</span><span class="RktSym">:</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">-&gt;</span></span><span class="hspace">&nbsp;</span><span class="RktSym">boolean</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">theorem:eval-ck=eval-cc</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktRdr">,</span><span class="RktPn">(</span><span class="RktSym">equal?</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">eval-cc</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">eval-ck</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">]</span><span class="RktPn">)</span></td></tr></table></blockquote><h5 x-source-module="(lib &quot;redex/redex.scrbl&quot;)" x-source-pkg="redex-doc" x-part-tag="&quot;The_CEK_machine&quot;">2.10.4<tt>&nbsp;</tt><a name="(part._.The_.C.E.K_machine)"></a>The CEK machine</h5><p><span style="font-weight: bold">Observation</span> Substitution is an eager operation. It traverses the
term kind of like machine does anyway when it searches for a redex. Why not
combine the two by delaying substitution until needed? That&rsquo;s called an
<a href="#%28tech._environment%29" class="techoutside" data-pltdoc="x"><span class="techinside">environment</span></a> (E) in the contexts of machines (also see above).</p><p><span style="font-weight: bold">General Idea</span> Universal laziness is <span style="font-style: italic">not</span> a good idea. But
the selective delay of operations&#8212;<wbr></wbr>especially when operations can be
merged&#8212;<wbr></wbr>is a good thing.</p><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._define-extended-language%29%29" class="RktStxLink" data-pltdoc="x">define-extended-language</a></span><span class="hspace">&nbsp;</span><span class="RktSym">CEK</span><span class="hspace">&nbsp;</span><span class="RktSym">Lambda/v</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">&#961;</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._~3a~3a~3d%29%29" class="RktStxLink" data-pltdoc="x">::=</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">c</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">c</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._~3a~3a~3d%29%29" class="RktStxLink" data-pltdoc="x">::=</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">v</span><span class="hspace">&nbsp;</span><span class="RktSym">&#961;</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">k</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._~3a~3a~3d%29%29" class="RktStxLink" data-pltdoc="x">::=</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">app</span><span class="hspace">&nbsp;</span><span class="RktPn">[</span><span class="RktSym">c</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">]</span><span class="hspace">&nbsp;</span><span class="RktSym">&#961;</span><span class="hspace">&nbsp;</span><span class="RktPn">[</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">]</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym">module+</span><span class="hspace">&nbsp;</span><span class="RktSym">test</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test--~3e~3e%29%29" class="RktStxLink" data-pltdoc="x">test--&gt;&gt;</a></span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">--&gt;</span>cek</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">[</span><span class="RktRdr">,</span><span class="RktSym">e0</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span><span class="RktPn">]</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">[</span><span class="RktVal">0</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span><span class="RktPn">]</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test--~3e~3e%29%29" class="RktStxLink" data-pltdoc="x">test--&gt;&gt;</a></span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">--&gt;</span>cek</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">[</span><span class="RktRdr">,</span><span class="RktSym">e1</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span><span class="RktPn">]</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">[</span><span class="RktVal">1</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span><span class="RktPn">]</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym">define</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">--&gt;</span>cek</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._reduction-relation%29%29" class="RktStxLink" data-pltdoc="x">reduction-relation</a></span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktSym">CEK</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">#:domain</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym">&#961;</span><span class="hspace">&nbsp;</span><span class="RktSym">k</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._--~3e%29%29" class="RktStxLink" data-pltdoc="x"><span class="nobreak">--&gt;</span></a></span><span class="hspace">&nbsp;</span><span class="RktPn">[</span><span class="RktSym">x</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">x_1</span><span class="hspace">&nbsp;</span><span class="RktSym">c_1</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">v</span><span class="hspace">&nbsp;</span><span class="RktSym">&#961;</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x_2</span><span class="hspace">&nbsp;</span><span class="RktSym">c_2</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">app</span><span class="hspace">&nbsp;</span><span class="RktSym">any_v</span><span class="hspace">&nbsp;</span><span class="RktSym">any_r</span><span class="hspace">&nbsp;</span><span class="RktSym">any_e</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktSym">v</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktSym">&#961;</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">app</span><span class="hspace">&nbsp;</span><span class="RktSym">any_v</span><span class="hspace">&nbsp;</span><span class="RktSym">any_r</span><span class="hspace">&nbsp;</span><span class="RktSym">any_e</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktSym">CEK-lookup</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._--~3e%29%29" class="RktStxLink" data-pltdoc="x"><span class="nobreak">--&gt;</span></a></span><span class="hspace">&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">lambda</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">..._n</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">any_c</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">app</span><span class="hspace">&nbsp;</span><span class="RktPn">[</span><span class="RktSym">c</span><span class="hspace">&nbsp;</span><span class="RktSym">..._n</span><span class="RktPn">]</span><span class="hspace">&nbsp;</span><span class="RktSym">&#961;</span><span class="hspace">&nbsp;</span><span class="RktPn">[</span><span class="RktPn">]</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">app</span><span class="hspace">&nbsp;</span><span class="RktSym">any_v</span><span class="hspace">&nbsp;</span><span class="RktSym">any_r</span><span class="hspace">&nbsp;</span><span class="RktSym">any_e</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktSym">e</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktPn">[</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">c</span><span class="RktPn">]</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="hspace">&nbsp;</span><span class="RktSym">any_c</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">app</span><span class="hspace">&nbsp;</span><span class="RktSym">any_v</span><span class="hspace">&nbsp;</span><span class="RktSym">any_r</span><span class="hspace">&nbsp;</span><span class="RktSym">any_e</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktSym">CEK-&#946;_v</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._--~3e%29%29" class="RktStxLink" data-pltdoc="x"><span class="nobreak">--&gt;</span></a></span><span class="hspace">&nbsp;</span><span class="RktPn">[</span><span class="RktSym">+</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktSym">&#961;</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">app</span><span class="hspace">&nbsp;</span><span class="RktPn">[</span><span class="RktSym">n_1</span><span class="hspace">&nbsp;</span><span class="RktSym">n_2</span><span class="RktPn">]</span><span class="hspace">&nbsp;</span><span class="RktPn">[</span><span class="RktPn">]</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">app</span><span class="hspace">&nbsp;</span><span class="RktSym">any_v</span><span class="hspace">&nbsp;</span><span class="RktSym">any_r</span><span class="hspace">&nbsp;</span><span class="RktSym">any_e</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktRdr">,</span><span class="RktPn">(</span><span class="RktSym">+</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktSym">n_1</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktSym">n_2</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">app</span><span class="hspace">&nbsp;</span><span class="RktSym">any_v</span><span class="hspace">&nbsp;</span><span class="RktSym">any_r</span><span class="hspace">&nbsp;</span><span class="RktSym">any_e</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktSym">CEK-+</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._--~3e%29%29" class="RktStxLink" data-pltdoc="x"><span class="nobreak">--&gt;</span></a></span><span class="hspace">&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">e_1</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktSym">&#961;</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">any_k</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktSym">e_last</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktSym">&#961;</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">app</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">&#961;</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e_1others</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">any_k</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">where</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e_1others</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="hspace">&nbsp;</span><span class="RktSym">e_last</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e_1</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktSym">CEK-push</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._--~3e%29%29" class="RktStxLink" data-pltdoc="x"><span class="nobreak">--&gt;</span></a></span><span class="hspace">&nbsp;</span><span class="RktPn">[</span><span class="RktSym">v</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktSym">&#961;</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">app</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">c_1</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">&#961;_stack</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">any_k</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktSym">e_last</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktSym">&#961;_stack</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">app</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">v</span><span class="hspace">&nbsp;</span><span class="RktSym">&#961;</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">c_1</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">&#961;_stack</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e_prefix</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">any_k</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">where</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e_prefix</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="hspace">&nbsp;</span><span class="RktSym">e_last</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym">...</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktSym">CEK-switch</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym">module+</span><span class="hspace">&nbsp;</span><span class="RktSym">test</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">eval-cek</span><span class="hspace">&nbsp;</span><span class="RktRdr">,</span><span class="RktSym">e0</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">0</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">eval-cek</span><span class="hspace">&nbsp;</span><span class="RktRdr">,</span><span class="RktSym">e1</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">1</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._define-metafunction%29%29" class="RktStxLink" data-pltdoc="x">define-metafunction</a></span><span class="hspace">&nbsp;</span><span class="RktSym">Lambda/v</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktSym">eval-cek</span><span class="hspace">&nbsp;</span><span class="RktSym">:</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">-&gt;</span></span><span class="hspace">&nbsp;</span><span class="RktSym">v</span><span class="hspace">&nbsp;</span><span class="RktSym">or</span><span class="hspace">&nbsp;</span><span class="RktSym">closure</span><span class="hspace">&nbsp;</span><span class="RktSym">or</span><span class="hspace">&nbsp;</span><span class="RktSym">stuck</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">eval-cek</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">run-cek</span><span class="hspace">&nbsp;</span><span class="RktPn">[</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span><span class="RktPn">]</span><span class="RktPn">)</span><span class="RktPn">]</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._define-metafunction%29%29" class="RktStxLink" data-pltdoc="x">define-metafunction</a></span><span class="hspace">&nbsp;</span><span class="RktSym">CEK</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktSym">run-cek</span><span class="hspace">&nbsp;</span><span class="RktSym">:</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym">&#961;</span><span class="hspace">&nbsp;</span><span class="RktSym">k</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">-&gt;</span></span><span class="hspace">&nbsp;</span><span class="RktSym">v</span><span class="hspace">&nbsp;</span><span class="RktSym">or</span><span class="hspace">&nbsp;</span><span class="RktSym">closure</span><span class="hspace">&nbsp;</span><span class="RktSym">or</span><span class="hspace">&nbsp;</span><span class="RktSym">stuck</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">run-cek</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">n</span><span class="hspace">&nbsp;</span><span class="RktSym">&#961;</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">n</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">run-cek</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">v</span><span class="hspace">&nbsp;</span><span class="RktSym">&#961;</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">closure</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">run-cek</span><span class="hspace">&nbsp;</span><span class="RktSym">any_1</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">run-cek</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e_again</span><span class="hspace">&nbsp;</span><span class="RktSym">&#961;_again</span><span class="hspace">&nbsp;</span><span class="RktSym">k_again</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">where</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktPn">(</span><span class="RktSym">e_again</span><span class="hspace">&nbsp;</span><span class="RktSym">&#961;_again</span><span class="hspace">&nbsp;</span><span class="RktSym">k_again</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktRdr">,</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28def._%28%28lib._redex%2Freduction-semantics..rkt%29._apply-reduction-relation%29%29" class="RktValLink" data-pltdoc="x">apply-reduction-relation</a></span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">--&gt;</span>cek</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktSym">any_1</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">]</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">run-cek</span><span class="hspace">&nbsp;</span><span class="RktSym">any</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym">stuck</span><span class="RktPn">]</span><span class="RktPn">)</span></td></tr></table></blockquote><h5 x-source-module="(lib &quot;redex/redex.scrbl&quot;)" x-source-pkg="redex-doc" x-part-tag="&quot;The_CEK-CK_Theorem&quot;">2.10.5<tt>&nbsp;</tt><a name="(part._.The_.C.E.K-.C.K_.Theorem)"></a>The CEK-CK Theorem</h5><p>Again, the two machines define the <span style="font-style: italic">same semantics</span>. Here is the
theorem.</p><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym">module+</span><span class="hspace">&nbsp;</span><span class="RktSym">test</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktCmt">;</span><span class="RktCmt">&nbsp;</span><span class="RktCmt">theorem:eval-ck=eval-cc</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">theorem:eval-cek=eval-ck</span><span class="hspace">&nbsp;</span><span class="RktRdr">,</span><span class="RktSym">e0</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">#true</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._test-equal%29%29" class="RktStxLink" data-pltdoc="x">test-equal</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">theorem:eval-cek=eval-ck</span><span class="hspace">&nbsp;</span><span class="RktRdr">,</span><span class="RktSym">e1</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktVal">#true</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktCmt">;</span><span class="RktCmt">&nbsp;</span><span class="RktCmt">NEXT: CEK vs CK </span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._redex-check%29%29" class="RktStxLink" data-pltdoc="x">redex-check</a></span><span class="hspace">&nbsp;</span><span class="RktSym">Lambda</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">theorem:eval-cek=eval-ck</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">#:attempts</span><span class="hspace">&nbsp;</span><span class="RktVal">24</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">#:prepare</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">close-all-fv</span><span class="hspace">&nbsp;</span><span class="RktSym">vv?</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._define-metafunction%29%29" class="RktStxLink" data-pltdoc="x">define-metafunction</a></span><span class="hspace">&nbsp;</span><span class="RktSym">Lambda/v</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktSym">theorem:eval-cek=eval-ck</span><span class="hspace">&nbsp;</span><span class="RktSym">:</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym"><span class="nobreak">-&gt;</span></span><span class="hspace">&nbsp;</span><span class="RktSym">boolean</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">[</span><span class="RktPn">(</span><span class="RktSym">theorem:eval-cek=eval-ck</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;</span><span class="RktRdr">,</span><span class="RktPn">(</span><span class="RktSym">equal?</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">eval-cek</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._term%29%29" class="RktStxLink" data-pltdoc="x">term</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">eval-ck</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">]</span><span class="RktPn">)</span></td></tr></table></blockquote><h4 x-source-module="(lib &quot;redex/redex.scrbl&quot;)" x-source-pkg="redex-doc" x-part-tag="&quot;lab-wed-aft&quot;">2.11<tt>&nbsp;</tt><a name="(part._lab-wed-aft)"></a><span style="font-weight: bold">Lab</span> Machine Transitions</h4><p><table cellspacing="0" cellpadding="0" class="boxed"><tr><td><p><span style="font-weight: bold">Goals</span></p></td></tr><tr><td><p> &#8212;<wbr></wbr> develop the CESK machine</p></td></tr></table></p><p><div class="SIntrapara">The following exercises refer to several definitions found in, and exported
from, <a href="common.rkt">common.rkt</a>. You may either copy these
definitions into your file or add the following <span class="RktSym">require</span> statement
to the top of your file:
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><p><span class="RktPn">(</span><span class="RktSym">require</span><span class="hspace">&nbsp;</span><span class="RktVal">"common.rkt"</span><span class="RktPn">)</span></p></blockquote></div></p><p>In addition to <span class="stt">"common.rkt"</span>, you also want to <span class="RktSym">require</span>
<a href="close.rkt">close.rkt</a> for this lab. Furthermore, if you copy code
from <a href="#%28part._wed-aft%29" data-pltdoc="x">Abstract Machines</a>, make sure to copy the tests and to adapt the tests
as you develop the machines.</p><h5 x-source-module="(lib &quot;redex/redex.scrbl&quot;)" x-source-pkg="redex-doc" x-part-tag="&quot;lwa&quot;"><a name="(part._lwa)"></a>Exercises</h5><blockquote class="SubFlow"><p><div class="SIntrapara"><a name="(counter._(exercise._ex~3acesk))"></a><span style="font-weight: bold">Exercise</span>&nbsp;11. Equip the language with assignment statements and
<span class="RktSym">void</span>:
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._define-extended-language%29%29" class="RktStxLink" data-pltdoc="x">define-extended-language</a></span><span class="hspace">&nbsp;</span><span class="RktSym">Assignments</span><span class="hspace">&nbsp;</span><span class="RktSym">Lambda</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">e</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._~3a~3a~3d%29%29" class="RktStxLink" data-pltdoc="x">::=</a></span><span class="hspace">&nbsp;</span><span class="RktSym">....</span><span class="hspace">&nbsp;</span><span class="RktSym">n</span><span class="hspace">&nbsp;</span><span class="RktSym">+</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">void</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">set!</span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">e</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym">n</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="The_Redex_Reference.html#%28form._%28%28lib._redex%2Freduction-semantics..rkt%29._~3a~3a~3d%29%29" class="RktStxLink" data-pltdoc="x">::=</a></span><span class="hspace">&nbsp;</span><span class="RktSym">natural</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr></table></blockquote></div></p><p>Start with the CS reduction system and develop the CESK
machine, re-tracing the above machine derivation. <img style="vertical-align: 0px; margin: -3px -3px -3px -3px;" src="pict_15.png" alt="image" width="9" height="16"/></p></blockquote><h4 x-source-module="(lib &quot;redex/redex.scrbl&quot;)" x-source-pkg="redex-doc" x-part-tag="&quot;thu-mor&quot;">2.12<tt>&nbsp;</tt><a name="(part._thu-mor)"></a>Abstracting Abstract Machines I</h4><p><table cellspacing="0" cellpadding="0" class="boxed"><tr><td><p><span style="font-weight: bold">Goals</span></p></td></tr><tr><td><p> &#8212;<wbr></wbr> another perspective and more machines</p></td></tr><tr><td><p> &#8212;<wbr></wbr> advanced Redex features and extensions</p></td></tr><tr><td><p> &#8212;<wbr></wbr> static analysis via abstracting abstract machines</p></td></tr><tr><td><p> &#8212;<wbr></wbr> soundness theorems (in place of equivalence theorems)</p></td></tr></table></p><p>We&rsquo;ll work through some existing notes on introducing Redex using an
idea called &ldquo;abstracting abstract machines,&rdquo; a process for turning
abstract machines in to static analyzers.</p><p>The beginning of these notes will largely be review, but it won&rsquo;t hurt
to go through the material again.  During the lecture, I&rsquo;ll skim
through those parts that have been covered to make sure we&rsquo;re all on
the same page.</p><p>Please see <a href="https://dvanhorn.github.io/redex-aam-tutorial/"><span class="url">https://dvanhorn.github.io/redex-aam-tutorial/</span></a>.</p><h4 x-source-module="(lib &quot;redex/redex.scrbl&quot;)" x-source-pkg="redex-doc" x-part-tag="&quot;lab-thu-mor&quot;">2.13<tt>&nbsp;</tt><a name="(part._lab-thu-mor)"></a><span style="font-weight: bold">Lab</span> Abstracting Abstract Machines I</h4><p><table cellspacing="0" cellpadding="0" class="boxed"><tr><td><p><span style="font-weight: bold">Goals</span></p></td></tr><tr><td><p> &#8212;<wbr></wbr> develop the world&rsquo;s smallest static analysis</p></td></tr><tr><td><p> &#8212;<wbr></wbr> define approximation on stores</p></td></tr><tr><td><p> &#8212;<wbr></wbr> import semantic ideas into analysis</p></td></tr></table></p><p>Start with
and edit <span class="stt">tutorial.rkt</span> to complete the exercises.</p><h5 x-source-module="(lib &quot;redex/redex.scrbl&quot;)" x-source-pkg="redex-doc" x-part-tag="&quot;lthm&quot;"><a name="(part._lthm)"></a>Exercises</h5><blockquote class="SubFlow"><p><a name="(counter._(exercise._ex~3advh1))"></a><span style="font-weight: bold">Exercise</span>&nbsp;12. Design the approximation relation for stores,
named <span class="stt">&#8849;&#931;</span>.  (Marked with <span class="stt">FIXME</span> in <span class="stt">tutorial.rkt</span>.) <img style="vertical-align: 0px; margin: -3px -3px -3px -3px;" src="pict_16.png" alt="image" width="9" height="16"/></p></blockquote><blockquote class="SubFlow"><p><a name="(counter._(exercise._ex~3advh2))"></a><span style="font-weight: bold">Exercise</span>&nbsp;13. Add <span class="stt">set!</span> and <span class="stt">void</span> to the model starting
with <span class="stt"></span><span class="stt">&ndash;</span><span class="stt">&gt;v&#963;</span> and carry it through to <span class="stt"></span><span class="stt">&ndash;</span><span class="stt">&gt;v&#963;^</span>.  Can you design a
more precise, yet sound, way of approximating store updates? <img style="vertical-align: 0px; margin: -3px -3px -3px -3px;" src="pict_17.png" alt="image" width="9" height="16"/></p></blockquote><blockquote class="SubFlow"><p><a name="(counter._(exercise._ex~3advh3))"></a><span style="font-weight: bold">Exercise</span>&nbsp;14. Implement a garbage collector for <span class="stt"></span><span class="stt">&ndash;</span><span class="stt">&gt;v&#963;</span>
and carry it through to <span class="stt"></span><span class="stt">&ndash;</span><span class="stt">&gt;v&#963;^</span>.  What do you notice about the precision
of the resulting analyzer? <img style="vertical-align: 0px; margin: -3px -3px -3px -3px;" src="pict_18.png" alt="image" width="9" height="16"/></p></blockquote><h4 x-source-module="(lib &quot;redex/redex.scrbl&quot;)" x-source-pkg="redex-doc" x-part-tag="&quot;thu-aft&quot;">2.14<tt>&nbsp;</tt><a name="(part._thu-aft)"></a>Abstracting Abstract Machines II</h4><p><table cellspacing="0" cellpadding="0" class="boxed"><tr><td><p><span style="font-weight: bold">Goals</span></p></td></tr><tr><td><p> &#8212;<wbr></wbr> modular static analysis</p></td></tr><tr><td><p> &#8212;<wbr></wbr> contract verification and symbolic execution</p></td></tr><tr><td><p> &#8212;<wbr></wbr> from Redex to <span class="stt">#lang</span></p></td></tr></table></p><p>In this part, I&rsquo;ll give a high-level overview of some more advanced
topics.</p><p>Please see <a href="https://dvanhorn.github.io/redex-aam-tutorial/"><span class="url">https://dvanhorn.github.io/redex-aam-tutorial/</span></a>.</p><h4 x-source-module="(lib &quot;redex/redex.scrbl&quot;)" x-source-pkg="redex-doc" x-part-tag="&quot;lab-thu-aft&quot;">2.15<tt>&nbsp;</tt><a name="(part._lab-thu-aft)"></a><span style="font-weight: bold">Lab</span> Abstracting Abstract Machines II</h4><p><table cellspacing="0" cellpadding="0" class="boxed"><tr><td><p><span style="font-weight: bold">Goals</span></p></td></tr><tr><td><p> &#8212;<wbr></wbr> go further with AAM</p></td></tr><tr><td><p> &#8212;<wbr></wbr> a glimpse of pragmatic concerns</p></td></tr></table></p><p><div class="SIntrapara">The following exercises refer to several definitions found in, and exported
from, <a href="common.rkt">common.rkt</a>. You may either copy these
definitions into your file or add the following <span class="RktSym">require</span> statement
to the top of your file:
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><p><span class="RktPn">(</span><span class="RktSym">require</span><span class="hspace">&nbsp;</span><span class="RktVal">"common.rkt"</span><span class="RktPn">)</span></p></blockquote></div></p><h5 x-source-module="(lib &quot;redex/redex.scrbl&quot;)" x-source-pkg="redex-doc" x-part-tag="&quot;ltha&quot;"><a name="(part._ltha)"></a>Exercises</h5><blockquote class="SubFlow"><p><a name="(counter._(exercise._ex~3advh4))"></a><span style="font-weight: bold">Exercise</span>&nbsp;15. Add exceptions to the model and carry it through to an
analyzer that handles control effects. <img style="vertical-align: 0px; margin: -3px -3px -3px -3px;" src="pict_19.png" alt="image" width="9" height="16"/></p></blockquote><blockquote class="SubFlow"><p><a name="(counter._(exercise._ex~3advh5))"></a><span style="font-weight: bold">Exercise</span>&nbsp;16. A very common, pragmatic further approximation to
perform is to consider a &ldquo;global&rdquo; store, i.e. analysis is not done
by collecting a set of states, each of which includes a store, but
instead a pair consisting of a set of term, environment, stack tuples
and a single store.  Construct another reduction relation which
performs this approximation. <img style="vertical-align: 0px; margin: -3px -3px -3px -3px;" src="pict_20.png" alt="image" width="9" height="16"/></p></blockquote><blockquote class="SubFlow"><p><a name="(counter._(exercise._ex~3advh6))"></a><span style="font-weight: bold">Exercise</span>&nbsp;17. Pick a language feature you think would be
interesting to model and add it. <img style="vertical-align: 0px; margin: -3px -3px -3px -3px;" src="pict_21.png" alt="image" width="9" height="16"/></p></blockquote><div class="navsetbottom"><span class="navleft"><form class="searchform"><input class="searchbox" style="color: #888;" type="text" value="...search manuals..." title="Enter a search string to search the manuals" onkeypress="return DoSearchKey(event, this, &quot;6.3&quot;, &quot;../&quot;);" onfocus="this.style.color=&quot;black&quot;; this.style.textAlign=&quot;left&quot;; if (this.value == &quot;...search manuals...&quot;) this.value=&quot;&quot;;" onblur="if (this.value.match(/^ *$/)) { this.style.color=&quot;#888&quot;; this.style.textAlign=&quot;center&quot;; this.value=&quot;...search manuals...&quot;; }"/></form>&nbsp;&nbsp;<a href="../index.html" title="up to the documentation top" data-pltdoc="x" onclick="return GotoPLTRoot(&quot;6.3&quot;);">top</a></span><span class="navright">&nbsp;&nbsp;<a href="tutorial.html" title="backward to &quot;1 Amb: A Redex Tutorial&quot;" data-pltdoc="x">&larr; prev</a>&nbsp;&nbsp;<a href="index.html" title="up to &quot;Redex: Practical Semantics Engineering&quot;" data-pltdoc="x">up</a>&nbsp;&nbsp;<a href="fri-mor.html" title="forward to &quot;3 Extended Exercises&quot;" data-pltdoc="x">next &rarr;</a></span>&nbsp;</div></div></div><div id="contextindicator">&nbsp;</div></body></html>