<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jun 28, 2017, at 5:33 AM, Dimitri Racordon via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;">Using our contextual variables, one could rewrite our motivational example as follows:</div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><span class="" style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">class</span><span class="" style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;">&nbsp;Interpreter:&nbsp;</span><span class="" style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);">Visitor</span><span class="" style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;">&nbsp;{</span></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp; &nbsp;&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">func</span><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp;visit(</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">_</span><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp;node:&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);">BinExpr</span><span class="" style="font-variant-ligatures: no-common-ligatures;">) {</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span class="" style="color: rgb(186, 45, 162);">let</span>&nbsp;lhs, rhs :&nbsp;</span><span class="" style="color: rgb(112, 61, 170);">Int</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-tab-span" style="white-space: pre;"></span><span class="" style="color: rgb(186, 45, 162);">set</span>&nbsp;accumulator =&nbsp;<span class="" style="color: rgb(186, 45, 162);">nil</span>&nbsp;<font color="#ba2da2" class="">in</font>&nbsp;{</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures;">node.lhs.accept(</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">self</span><span class="" style="font-variant-ligatures: no-common-ligatures;">)</span></div><div class="" style="margin: 0px; line-height: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lhs = accumulator!</div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp; &nbsp; &nbsp; &nbsp; }</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;"><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-tab-span" style="white-space: pre;"></span><span class="" style="color: rgb(186, 45, 162);">set</span>&nbsp;accumulator =&nbsp;<span class="" style="color: rgb(186, 45, 162);">nil</span>&nbsp;</span><font color="#ba2da2" class="">in&nbsp;</font>{</div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures;">node.lhs.accept(</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">self</span><span class="" style="font-variant-ligatures: no-common-ligatures;">)</span></div><div class="" style="margin: 0px; line-height: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rhs = accumulator!</div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp; &nbsp; &nbsp; &nbsp; }</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;"><br class=""></span></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">switch</span><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp;node.op {</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">case</span><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(209, 47, 27);">"+"</span><span class="" style="font-variant-ligatures: no-common-ligatures;">:</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; accumulator = lhs + rhs</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">case</span><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(209, 47, 27);">"-"</span><span class="" style="font-variant-ligatures: no-common-ligatures;">:</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; accumulator = lhs - rhs</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">default</span><span class="" style="font-variant-ligatures: no-common-ligatures;">:</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fatalError(</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(209, 47, 27);">"unexpected operator&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures;">\</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(209, 47, 27);">(</span><span class="" style="font-variant-ligatures: no-common-ligatures;">node.op</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(209, 47, 27);">)"</span><span class="" style="font-variant-ligatures: no-common-ligatures;">)</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp; &nbsp; &nbsp; &nbsp; }</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp; &nbsp; }</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;"><br class=""></span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;"><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp; &nbsp;&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">func</span><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp;visit(</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">_</span><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp;node:&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);">Literal</span><span class="" style="font-variant-ligatures: no-common-ligatures;">) {</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp; &nbsp; &nbsp; &nbsp; accumulator = node.val</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp; &nbsp; }</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;"><br class=""></span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;"><div class="" style="margin: 0px; line-height: normal; min-height: 13px;"><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">&nbsp; &nbsp; func</span><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp;visit(</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">_</span><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp;node:&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);">Scope</span><span class="" style="font-variant-ligatures: no-common-ligatures;">) {</span></div><div class="" style="margin: 0px; line-height: normal; min-height: 13px;"><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-tab-span" style="white-space: pre;"></span><span class="" style="color: rgb(186, 45, 162);">set</span>&nbsp;symbols = [:]</span>&nbsp;<font color="#ba2da2" class="">in</font>&nbsp;{</div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">for</span><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp;child&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">in</span><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp;node.children {</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; child.accept(</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">self</span><span class="" style="font-variant-ligatures: no-common-ligatures;">)</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp; &nbsp; &nbsp; &nbsp; }</span></div></div><div class="" style="margin: 0px; line-height: normal; min-height: 13px;">&nbsp; &nbsp; }</div></span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;"><br class=""></span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;"><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp; &nbsp;&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">func</span><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp;visit(</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">_</span><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp;node:&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);">Identifier</span><span class="" style="font-variant-ligatures: no-common-ligatures;">) {</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">guard</span><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">let</span><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp;val = symbols?[node.name]&nbsp;<span class="" style="color: rgb(186, 45, 162);">else</span>&nbsp;{</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures;">fatalError(</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(209, 47, 27);">"undefined symbol</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(209, 47, 27);">:&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures;">\</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(209, 47, 27);">(</span><span class="" style="font-variant-ligatures: no-common-ligatures;">node.name</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(209, 47, 27);">)</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(209, 47, 27);">"</span><span class="" style="font-variant-ligatures: no-common-ligatures;">)</span></div><div class="" style="margin: 0px; line-height: normal;">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span>accumulator = val</div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp; &nbsp; }</span></div></span></div></span></div></div></span></div><div class="" style="margin: 0px; line-height: normal; min-height: 13px;"><span class="" style="font-variant-ligatures: no-common-ligatures;"></span><br class=""></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp; &nbsp;&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">context var</span><span class="" style="font-variant-ligatures: no-common-ligatures;">&nbsp;accumulator:&nbsp;</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);">Int</span><span class="" style="font-variant-ligatures: no-common-ligatures;">?</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);">&nbsp; &nbsp; context</span></span><span class="" style="color: rgb(186, 45, 162);">&nbsp;</span><span class="" style="color: rgb(186, 45, 162);">var</span>&nbsp;symbols: [String: Int]?</div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">}</span></div><div class=""><span class="" style="font-variant-ligatures: no-common-ligatures;"><br class=""></span></div></div></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;">It is no longer unclear what depth of the tree the&nbsp;<font face="Menlo" class="" style="font-size: 11px;">accumulator</font>&nbsp;variable should be associated with. The mechanism is handled automatically, preventing the programmer from incorrectly reading a value that was previously set for another descent. It is no longer needed to manually handle the stack management of the&nbsp;<span class="" style="font-family: Menlo; font-size: 11px;">symbols</span>&nbsp;variable, which was error prone in our previous implementation.</div></div></blockquote><br class=""></div><div>As far as I can see, you can do this with existing features:</div><div><br class=""></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>struct Contextual&lt;Value&gt; {</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>&nbsp; &nbsp;&nbsp;&nbsp;private var values: [Value]</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>&nbsp; &nbsp; &nbsp;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>&nbsp; &nbsp;&nbsp;&nbsp;var value:&nbsp;Value {</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;get { return&nbsp;values.last! }</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;set {&nbsp;values[values.index(before:&nbsp;values.endIndex)] = newValue }</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>&nbsp; &nbsp; &nbsp;}</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>&nbsp; &nbsp; &nbsp;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>&nbsp; &nbsp;&nbsp;&nbsp;mutating func with&lt;R&gt;(_ value: Value, do body: () throws -&gt; R) rethrows -&gt; R {</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;values.append(value)</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;defer {&nbsp;values.removeLast() }</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;return try body()</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>&nbsp; &nbsp;&nbsp;}</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><span class="Apple-tab-span" style="white-space: pre;">        </span></div><div><span class="Apple-tab-span" style="white-space: pre;">        </span>&nbsp;class&nbsp;Interpreter:&nbsp;Visitor&nbsp;{</div><div><span class="Apple-tab-span" style="white-space: pre;">        </span>&nbsp; &nbsp; var&nbsp;accumulator: Contextual&lt;Int?&gt;<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>&nbsp; &nbsp; var&nbsp;symbols: Contextual&lt;[String: Int]&gt;</div><div><span class="Apple-tab-span" style="white-space: pre;">        </span><br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>&nbsp; &nbsp;&nbsp;func&nbsp;visit(_&nbsp;node:&nbsp;BinExpr) {<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;let&nbsp;lhs, rhs :&nbsp;Int<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>&nbsp; &nbsp; &nbsp; &nbsp; accumulator.with(nil)&nbsp;{<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;node.lhs.accept(self)<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lhs = accumulator.value!<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>&nbsp; &nbsp; &nbsp; &nbsp; }<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>&nbsp; &nbsp; &nbsp; &nbsp; accumulator.with(nil)&nbsp;{<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;node.lhs.accept(self)<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rhs = accumulator.value!<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>&nbsp; &nbsp; &nbsp; &nbsp; }<br class=""><br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;switch&nbsp;node.op {<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;case&nbsp;"+":<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; accumulator.value = lhs + rhs<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;case&nbsp;"-":<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; accumulator.value = lhs - rhs<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;default:<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fatalError("unexpected operator&nbsp;\(node.op)")<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>&nbsp; &nbsp; &nbsp; &nbsp; }<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>&nbsp; &nbsp; }<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span><br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>&nbsp; &nbsp;&nbsp;func&nbsp;visit(_&nbsp;node:&nbsp;Literal) {<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>&nbsp; &nbsp; &nbsp; &nbsp; accumulator.value = node.val<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>&nbsp; &nbsp; }<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span><br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>&nbsp; &nbsp; func&nbsp;visit(_&nbsp;node:&nbsp;Scope) {<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>&nbsp; &nbsp; &nbsp; &nbsp; symbols.with([:])&nbsp;{<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;for&nbsp;child&nbsp;in&nbsp;node.children {<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; child.accept(self)<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>&nbsp; &nbsp; &nbsp; &nbsp; }<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>&nbsp; &nbsp; }<br class=""><br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>&nbsp; &nbsp;&nbsp;func&nbsp;visit(_&nbsp;node:&nbsp;Identifier) {<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;guard&nbsp;let&nbsp;val = symbols.value[node.name]&nbsp;else&nbsp;{<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;fatalError("undefined symbol:&nbsp;\(node.name)")<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>&nbsp; &nbsp; &nbsp; &nbsp; }<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;accumulator.value = val<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>&nbsp; &nbsp; }<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>}</div><div><br class=""></div><div>(There is actually a minor problem with this: the closures passed to `with(_:do:)` can't initialize `lhs` and `rhs` because DI can't prove they're run exactly once. I'd like an `@once` annotation on closure parameters to address this, but in the mean time, you can use `var` for those parameters instead of `let`.)<br class=""><br class=""></div><div>Obviously, your `context` keyword is slightly prettier to use. But is that enough? Is this use case *so* common, or the syntax of `with(_:do:)` and `value` *so* cumbersome, that it's worth adding language features to avoid it?</div><div><br class=""></div><div>And if the existing syntax *is* too cumbersome, could the Property Behaviors proposal (with some of the extensions described at the end) allow you to implement this yourself with an acceptable syntax? &lt;<a href="https://github.com/apple/swift-evolution/blob/master/proposals/0030-property-behavior-decls.md" class="">https://github.com/apple/swift-evolution/blob/master/proposals/0030-property-behavior-decls.md</a>&gt;</div><div><br class=""></div><div>Basically, what about this problem *requires* a solution built in to the language? Language-level solutions are difficult to design and have to be maintained forever, so it's going to take a lot to convince us this is a good addition to the language.</div><br class=""><div class="">
<span class="Apple-style-span" style="border-collapse: separate; font-variant-ligatures: normal; font-variant-east-asian: normal; font-variant-position: normal; line-height: normal; border-spacing: 0px;"><div class=""><div style="font-size: 12px; " class="">--&nbsp;</div><div style="font-size: 12px; " class="">Brent Royal-Gordon</div><div style="font-size: 12px; " class="">Architechies</div></div></span>

</div>
<br class=""></body></html>