<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On Nov 12, 2017, at 3:33 AM, Tino Heth via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> 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; line-break: after-white-space;" class=""><br class=""><div class=""><br class=""><blockquote type="cite" class=""><div class="">Am 11.11.2017 um 19:03 schrieb Chris Lattner <<a href="mailto:sabre@nondot.org" class="">sabre@nondot.org</a>>:</div><br class="Apple-interchange-newline"><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div class=""><blockquote type="cite" class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;"><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div class="">Swift is quite flexible on what can act as a closure — would it be allowed to use a dynamic callable in that context?</div><div class="">I guess forwarding of</div><div class=""><br class=""></div><div class=""><div class="" style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);"><span class="" style="color: rgb(186, 45, 162);">let</span><span class="Apple-converted-space"> </span>closure: ([(<span class="" style="color: rgb(112, 61, 170);">String</span>,<span class="Apple-converted-space"> </span><span class="" style="color: rgb(112, 61, 170);">Int</span>)]) -><span class="Apple-converted-space"> </span><span class="" style="color: rgb(112, 61, 170);">Int</span> = DynamicCallableType()</div></div><div class=""><br class=""></div><div class="">to the dynamicCall method of DynamicCallableType isn’t that hard, but wouldn’t it be odd if the value of closure changes when you leave out its type?</div></div></div></blockquote><br 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><div class="">I’m not sure I understand what you’re getting at. Can you show how this would work with the example in the motivation section?</div></div></div></blockquote></div><br class=""><div class="">I’m just asking if this should work ;-) — I didn’t see anything regarding it in the proposal.</div><div class="">But to take something from the document:</div><div class=""><br class=""></div><div class=""><pre style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.600000381469727px; margin-top: 0px; margin-bottom: 0px; word-wrap: normal; padding: 16px; overflow: auto; line-height: 1.45; background-color: rgb(246, 248, 250); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; word-break: normal; color: rgb(36, 41, 46);" class=""> <span class="pl-c" style="box-sizing: border-box; color: rgb(106, 115, 125);"><span class="pl-c" style="box-sizing: border-box;">//</span> file = open(filename)</span>
<span class="pl-c" style="box-sizing: border-box; color: rgb(106, 115, 125);"></span> <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">let</span> file <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">=</span> Python.<span class="pl-smi" style="box-sizing: border-box;">open</span>.<span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 92, 197);">call</span>(filename)
</pre></div><div class=""><pre style="box-sizing: border-box; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.600000381469727px; margin-top: 0px; margin-bottom: 0px; word-wrap: normal; padding: 16px; overflow: auto; line-height: 1.45; background-color: rgb(246, 248, 250); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; word-break: normal; color: rgb(36, 41, 46);" class=""><span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">let</span> openFile: (String) -> FileHandle? <span class="pl-k" style="box-sizing: border-box; color: rgb(215, 58, 73);">=</span> Python.<span class="pl-smi" style="box-sizing: border-box;">open // is this be possible, or an error?</span></pre></div></div></div></blockquote><br class=""></div><div>This would be an error. It is perfectly fine to do something like this:</div><div><br class=""></div><div> func foo(a : PyRef) -> PyRef {</div><div> let b = a.foo // produces a PyRef</div><div> let c = b(“string”) // produces a PyRef</div><div> return c</div><div> }</div><div><br class=""></div><div>The idea of this proposal is that in Python “everything is a python object”, but that some of the objects are callable. This approach is modeling a python object with some type (PyRef in the example above). It is totally possible to produce sugar on top of that, or to go farther. For example, with no language extensions, it is possible to do:</div><div><br class=""></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>let closure: (String) -> Int = { arg in Int(pythonThing.call(args: arg))! }</div><div><br class=""></div><div>Or with this proposal, you could do something like:</div><div><br class=""></div><div><div><span class="Apple-tab-span" style="white-space: pre;">        </span>let closure: (String) -> Int = { arg in Int(pythonThing(arg))! }</div><div class=""><br class=""></div></div><div>-Chris</div><div><br class=""></div><br class=""></body></html>