<div dir="ltr">that makes sense to me ;P</div><div class="gmail_extra"><br><div class="gmail_quote">2017-06-08 12:07 GMT+08:00 Gwendal Roué <span dir="ltr"><<a href="mailto:gwendal.roue@gmail.com" target="_blank">gwendal.roue@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><span class=""><div><blockquote type="cite"><div>Le 8 juin 2017 à 05:15, Susan Cheng via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> a écrit :</div><br class="m_-7963812331717988441Apple-interchange-newline"><div><div dir="ltr">Just a thought<div><br></div><div>if parentheses is important, why the tuples are not?</div><div><div style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica;min-height:14px"><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(186,45,162)">var</span> tuple1: (<span style="color:rgb(112,61,170)">Int</span>, <span style="color:rgb(112,61,170)">Int</span>) = (<span style="color:rgb(39,42,216)">0</span>, <span style="color:rgb(39,42,216)">0</span>)</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(186,45,162)">var</span> tuple2: ((((<span style="color:rgb(112,61,170)">Int</span>, <span style="color:rgb(112,61,170)">Int</span>)))) = (<span style="color:rgb(39,42,216)">0</span>, <span style="color:rgb(39,42,216)">0</span>)</div><div style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica;min-height:14px"><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">type(of: <span style="color:rgb(79,129,135)">tuple1</span>) == type(of: <span style="color:rgb(79,129,135)">tuple2</span>) <span style="color:rgb(0,132,0)">// true</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(186,45,162)">var</span> void: ((((((())))))) = ()</div><div style="margin:0px;font-size:12px;line-height:normal;font-family:Helvetica;min-height:14px"><br></div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">
</p><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">type(of: <span style="color:rgb(79,129,135)">void</span>) == type(of: Void()) <span style="color:rgb(0,132,0)">// true</span></div></div></div></div></blockquote><br></div></span><div>I think is is because Swift doesn't have tuples with a single value: those parenthesis are just parenthesis around an expression:</div><div><br></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">let</span><span style="font-variant-ligatures:no-common-ligatures"> a = </span><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8">1</span><span style="font-variant-ligatures:no-common-ligatures"> + </span><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8">2</span></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">let</span><span style="font-variant-ligatures:no-common-ligatures"> b = (</span><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8">1</span><span style="font-variant-ligatures:no-common-ligatures"> + </span><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8">2</span><span style="font-variant-ligatures:no-common-ligatures">)</span></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">let</span><span style="font-variant-ligatures:no-common-ligatures"> c = (</span><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8">1</span><span style="font-variant-ligatures:no-common-ligatures"> + </span><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8">2</span><span style="font-variant-ligatures:no-common-ligatures">) * </span><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8">3</span></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">let</span><span style="font-variant-ligatures:no-common-ligatures"> d = ((</span><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8">1</span><span style="font-variant-ligatures:no-common-ligatures"> + </span><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8">2</span><span style="font-variant-ligatures:no-common-ligatures">)) * </span><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8">3</span></div><div><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8"><br></span></div></div></div><div>Many languages behave like that, Swift is no exception.</div><div><br></div><div>It also allows some fancy/legacy/foreign programming styles :-)</div><div><br></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><div style="margin:0px;line-height:normal;color:rgb(0,132,0)"><span style="font-variant-ligatures:no-common-ligatures;color:#000000"> </span><span style="font-variant-ligatures:no-common-ligatures">// C-style if</span></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">if</span><span style="font-variant-ligatures:no-common-ligatures"> (</span><span style="font-variant-ligatures:no-common-ligatures;color:#4f8187">a</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#3e1e81">&&</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#4f8187">b</span><span style="font-variant-ligatures:no-common-ligatures">) {</span></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#008400">...</span></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures"> }</span></div><div style="margin:0px;line-height:normal;color:rgb(0,132,0)"><span style="font-variant-ligatures:no-common-ligatures;color:#000000"> </span><span style="font-variant-ligatures:no-common-ligatures">// "return function"</span></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">return</span><span style="font-variant-ligatures:no-common-ligatures">(a && b)</span></div><div><br></div></div></div><div>Languages that have single-valued tuples need a special syntax so that they are distinguished from parenthesised expressions. In Python, this is a trailing comma:</div><div><br></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8">1</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="color:rgb(0,132,0)"># 1</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"> (</span><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8">1</span><span style="font-variant-ligatures:no-common-ligatures">) </span><span style="color:rgb(0,132,0)"># 1</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"> (</span><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8">1</span><span style="font-variant-ligatures:no-common-ligatures">,) </span><span style="color:rgb(0,132,0)"># (1,)</span></div><div><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div><span style="font-variant-ligatures:no-common-ligatures">Swift currently disallows trailing commas inside parenthesis.</span></div><span class="HOEnZb"><font color="#888888"><div><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div><span style="font-variant-ligatures:no-common-ligatures"><div>Gwendal</div><div><br></div></span></div></font></span></div></div></blockquote></div><br></div>