<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi,<div class=""><br class=""></div><div class="">Please find my comment in body:</div><div class=""><br class=""></div><div class="">BR,</div><div class="">Radek Smogura<br class=""><div><blockquote type="cite" class=""><div class="">On 27 Dec 2015, at 22:08, Taras Zakharko &lt;<a href="mailto:taras.zakharko@uzh.ch" class="">taras.zakharko@uzh.ch</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><br class=""></div><div class=""><blockquote type="cite" class=""><div class="">On 27 Dec 2015, at 21:55, Mosab Elagha &lt;<a href="mailto:mosabelagha@gmail.com" class="">mosabelagha@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Agreed, this seems like a great idea. Looks like it would also allow for a lot of customization - for example out of one "template" object.<div class=""><br class=""></div><div class="">Would the object have to already be initialized or could you initialize it from this? IMO it would have to already be initialized or else it might lead to confusion.</div></div></div></blockquote><div class=""><br class=""></div><div class="">The object could be any kind of valid Swift entity that has members (where you would usually use . to access them): object instance, type, struct etc. I can also imagine combining it with assignment, e.g. instead of&nbsp;</div><div class=""><br class=""></div><div class=""><div class="">let obj = MyClass()</div><div class="">do with obj {</div><div class=""><div class="">&nbsp; prop1 = v1</div><div class="">&nbsp; setup2()</div></div><div class="">}</div><div class=""><br class=""></div><div class="">a combined assignment form such as&nbsp;</div><div class=""><br class=""></div></div><div class="">do with let obj = MyClass() {</div><div class=""><div class=""><div class="">&nbsp; prop1 = v1</div><div class="">&nbsp; setup2()</div></div></div><div class="">}</div></div></div></div></blockquote>I think in this case it’s important to define scope of obj - it should be only “do with”, not the the outer one?</div><div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><div class="">But this clashes with optional binding, so it might be not a good idea.&nbsp;</div><div class=""><br class=""></div><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="">Also, would this be limited to instance methods?</div></div></div></blockquote><div class=""><br class=""></div><div class="">Anything you can access with the dot notation.&nbsp;</div></div><div class=""><br class=""></div><div class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_extra"><br clear="all" class=""><div class=""><div class=""><div dir="ltr" class=""><span style="border-collapse:collapse;font-family:arial,sans-serif;font-size:13px" class=""><font color="#C0C0C0" class=""><div class="">-Mosab Elagha</div></font></span></div></div></div>
<br class=""><div class="gmail_quote">On Sun, Dec 27, 2015 at 3:13 PM, Radosław Smogura <span dir="ltr" class="">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt;</span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br class="">
<br class="">
That’s a great idea!<br class="">
<br class="">
Kind regards,<br class="">
Radek<br class="">
<div class=""><div class=""><br class="">
&gt; On 27 Dec 2015, at 21:10, Taras Zakharko via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; wrote:<br class="">
&gt;<br class="">
&gt; Quite often, one needs to perform a number of operations on a single object (e.g. call up a bunch of configuration or action methods). This proposal is to extend the ‘do' statement&nbsp; with an explicit lexical scope feature. For instance, this piece of code<br class="">
&gt;<br class="">
&gt; object.do_something()<br class="">
&gt; object.do_somethind_else()<br class="">
&gt; object.prop1 = value<br class="">
&gt;<br class="">
&gt; becomes<br class="">
&gt;<br class="">
&gt; do with object // or with object do<br class="">
&gt; {<br class="">
&gt;&nbsp; &nbsp;do_something()<br class="">
&gt;&nbsp; &nbsp;do_somethind_else()<br class="">
&gt;&nbsp; &nbsp;prop1 = value<br class="">
&gt; }<br class="">
&gt;<br class="">
&gt; Essentially, this construct would introduce a level of lexical scope — explicitly controlled by the programmer, in addition to the implicit scope dictated by statement blocks, closures and self.<br class="">
&gt;<br class="">
&gt; The advantage of this construct is that it allows one to remove boilerplate code for initialisation/configuration as well as adds clear logical separation to the code. Disadvantage is potential shadowing of identifiers in the scope, but this should to be a big issue because the syntax is explicit rather then implicit, meaning that its the programmers job to make sure that no shadowing occurs (btw, compiler could warn about shadowing). The additions to the language syntax is minimal and the implementation should be straightforward (its essentially the same logic as for self).<br class="">
&gt;<br class="">
&gt; Note that this proposal is close to the discussion about popular the implicit self on this mailing list. A body of any method could be understood as wrapped into an implicit<br class="">
&gt;<br class="">
&gt;&nbsp; &nbsp;do with self {}<br class="">
&gt;<br class="">
&gt; Finally, this construct exists in a very similar form in Pascal (no idea if Wirth was inspired by some other feature or not here) and is also present in a bunch of languages that have dynamic scope. Personally, I use it all the time in R and I am loving it.<br class="">
&gt;<br class="">
&gt; If the community thinks this could be a nice addition to the language, I am ready to draft a proposal. Also, apologies if this has been suggested before — it is impossible to keep up with this list.<br class="">
&gt;<br class="">
&gt; Best,<br class="">
&gt;<br class="">
&gt; Taras<br class="">
&gt; _______________________________________________<br class="">
&gt; swift-evolution mailing list<br class="">
&gt; <a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a><br class="">
&gt; <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="">
<br class="">
_______________________________________________<br class="">
swift-evolution mailing list<br class="">
<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a><br class="">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="">
</div></div></blockquote></div><br class=""></div></div>
</div></blockquote></div><br class=""></div></div></blockquote></div><br class=""></div></body></html>