<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=""><div><blockquote type="cite" class=""><div class="">On Nov 1, 2017, at 3:20 AM, Richard Wei <<a href="mailto:rxrwei@gmail.com" class="">rxrwei@gmail.com</a>> wrote:</div><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><blockquote type="cite" class=""><div class=""><div 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;" class=""><blockquote type="cite" class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div class=""><div class=""><br class=""></div><div class="">Since you bring it up, Python exceptions will be annoying - As with other languages, Python can throw from an arbitrary expression. Modeling everything as throws in Swift would be super-annoying and unergonomic for the programmer, because we'd require 'try' everywhere. Thoughts on what to do about that are welcome!</div></div></div></blockquote><div class=""><br class=""></div><div class="">Requiring ‘try’ on every statement is annoying, but not having the ability to catch python exceptions is annoying too. We could probably make python exception handling an opt-in feature. For example:</div><div class=""><br class=""></div><div class=""><font face="Menlo" class="">try Python.do {</font></div><div class=""><font face="Menlo" class=""> let a = np.array([1, 2, 3])</font></div><div class=""><font face="Menlo" class=""> let b = np.array([[2], [4]])</font></div><div class=""><font face="Menlo" class=""> print(a.dot(b)) // matrix mul with incompatible shapes</font></div><div class=""><font face="Menlo" class="">}</font></div><div class=""><font face="Menlo" class="">catch let error as PythonException {</font></div><div class=""><font face="Menlo" class=""> // Handle PythonError.valueError(“objects are not aligned”)</font></div><div class=""><font face="Menlo" class="">}</font></div></div></div></blockquote><div class=""><br class=""></div><div class="">To correct my example: </div><div class=""><br class=""></div><div class=""><div class=""><font face="Menlo" class="">do { </font></div><div class=""><font face="Menlo" class=""> try Python.do {</font></div><div class=""><font face="Menlo" class=""> let a = np.array([1, 2, 3])</font></div><div class=""><font face="Menlo" class=""> let b = np.array([[2], [4]])</font></div><div class=""><font face="Menlo" class=""> print(a.dot(b)) // matrix mul with incompatible shapes</font></div><div class=""><font face="Menlo" class=""> }</font></div><div class=""><font face="Menlo" class="">}</font></div><div class=""><font face="Menlo" class="">catch let error as PythonException {</font></div><div class=""><font face="Menlo" class=""> // Handle PythonError.valueError(“objects are not aligned”)</font></div><div class=""><font face="Menlo" class="">}</font></div></div><div class=""><br class=""></div><div class="">Maybe ‘Python.do {}’ should be called something like ‘Python.safely {}’.</div></div></div></div></blockquote><br class=""></div><div>That’s a super interesting way to model this. I’ll need to ponder on it more, but it is certainly a nice ergonomic solution.</div><div><br class=""></div><div>Question though: how does it work? Say the first np.array call threw a python exception:</div><div><br class=""></div><div><blockquote type="cite" class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space;"><div class=""><div class=""><div class=""><font face="Menlo" class="">try Python.do {</font></div><div class=""><font face="Menlo" class=""> let a = np.array([1, 2, 3])</font></div><div class=""><font face="Menlo" class=""> let b = np.array([[2], [4]])</font></div><div class=""><font face="Menlo" class=""> print(a.dot(b)) // matrix mul with incompatible shapes</font></div><div class=""><font face="Menlo" class=""> }</font></div></div></div></div></blockquote></div><div><br class=""></div><div>We can definitely make the python glue code notice it, catch it and squirrel it away somewhere, but without compiler hacks we couldn’t make it jump out of the closure. This means that np.array would have to return something, and the calls below it would still execute, or am I missing something?</div><div><br class=""></div><div>-Chris</div><div><br class=""></div><br class=""></body></html>