<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="">+1. &nbsp;I have always thought this sugar should be consistent throughout the language.<div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Feb 17, 2017, at 2:20 AM, Adrian Zubarev 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="bloop_markdown" style="font-family: Helvetica, Arial; font-size: 13px; 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-stroke-width: 0px; background-color: rgb(254, 254, 254);"><p style="margin: 15px 0px; -webkit-margin-before: 0px;" class="">I’d like to revive an additive proposal that couldn’t make it into Swift 3. This proposal has a small improvement to the language compared to other big features currently being proposed. It almost feels like a bug fix rather than a new feature, but it still needs a full and quick review process.</p><p style="margin: 15px 0px;" class="">You can read the formatted version here:<span class="Apple-converted-space">&nbsp;</span><a href="https://github.com/apple/swift-evolution/pull/608" style="color: rgb(65, 131, 196); background-color: inherit; text-decoration: none; -webkit-margin-before: 0px;" class="">https://github.com/apple/swift-evolution/pull/608</a></p><h1 id="returnconsistencyforsingle-expressions" style="font-weight: bold; font-size: 28pt;" class=""><code style="font-family: Menlo, Consolas, 'Liberation Mono', Courier, monospace; font-size: 10pt; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(248, 248, 248); color: inherit; border: 1px solid rgb(234, 234, 234); margin: 0px 2px; padding: 0px 5px; word-break: normal; word-wrap: normal; -webkit-margin-before: 0px;" class="">return</code><span class="Apple-converted-space">&nbsp;</span>consistency for single-expressions</h1><ul style="margin: 15px 0px;" class=""><li style="margin: 15px 0px; -webkit-margin-before: 0px;" class="">Proposal:<span class="Apple-converted-space">&nbsp;</span><a href="https://github.com/apple/swift-evolution/blob/master/proposals/nnnn-single-expression-optional-return.md" style="color: rgb(65, 131, 196); background-color: inherit; text-decoration: none; -webkit-margin-before: 0px;" class="">SE-NNNN</a></li><li style="margin: 15px 0px;" class="">Author:<span class="Apple-converted-space">&nbsp;</span><a href="https://github.com/DevAndArtist" style="color: rgb(65, 131, 196); background-color: inherit; text-decoration: none; -webkit-margin-before: 0px;" class="">Adrian Zubarev</a></li><li style="margin: 15px 0px;" class="">Status:<span class="Apple-converted-space">&nbsp;</span><strong style="-webkit-margin-before: 0px;" class=""><a href="x-msg://423/#rationale" style="color: rgb(65, 131, 196); background-color: inherit; text-decoration: none; -webkit-margin-before: 0px;" class="">Awaiting review</a></strong></li><li style="margin: 15px 0px;" class="">Review manager: TBD</li></ul><h2 id="introduction" style="font-weight: bold; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(204, 204, 204); font-size: 24px;" class="">Introduction</h2><p style="margin: 15px 0px;" class="">Any single-expression closure can omit the<span class="Apple-converted-space">&nbsp;</span><code style="font-family: Menlo, Consolas, 'Liberation Mono', Courier, monospace; font-size: 10pt; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(248, 248, 248); color: inherit; border: 1px solid rgb(234, 234, 234); margin: 0px 2px; padding: 0px 5px; word-break: normal; word-wrap: normal; -webkit-margin-before: 0px;" class="">return</code><span class="Apple-converted-space">&nbsp;</span>statement. This proposal aims to make this feature more consistent in some other corners of the language.</p><p style="margin: 15px 0px;" class="">Original swift-evolution thread: *<span class="Apple-converted-space">&nbsp;</span><a href="" style="color: rgb(65, 131, 196); background-color: inherit; text-decoration: none; -webkit-margin-before: 0px;" class="">[Pitch] [Stage–2]<span class="Apple-converted-space">&nbsp;</span><code style="font-family: Menlo, Consolas, 'Liberation Mono', Courier, monospace; font-size: 10pt; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(248, 248, 248); color: inherit; border: 1px solid rgb(234, 234, 234); margin: 0px 2px; padding: 0px 5px; word-break: normal; word-wrap: normal; -webkit-margin-before: 0px;" class="">return</code><span class="Apple-converted-space">&nbsp;</span>consistency for single-expressions</a><span class="Apple-converted-space">&nbsp;</span>*<span class="Apple-converted-space">&nbsp;</span><a href="https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160523/019260.html" style="color: rgb(65, 131, 196); background-color: inherit; text-decoration: none;" class="">[Pitch] (Bofore Swift 3) Make<span class="Apple-converted-space">&nbsp;</span><code style="font-family: Menlo, Consolas, 'Liberation Mono', Courier, monospace; font-size: 10pt; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(248, 248, 248); color: inherit; border: 1px solid rgb(234, 234, 234); margin: 0px 2px; padding: 0px 5px; word-break: normal; word-wrap: normal; -webkit-margin-before: 0px;" class="">return</code><span class="Apple-converted-space">&nbsp;</span>optional in computed properties for a single case</a></p><h2 id="motivation" style="font-weight: bold; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(204, 204, 204); font-size: 24px;" class="">Motivation</h2><p style="margin: 15px 0px;" class="">Closures can omit the<span class="Apple-converted-space">&nbsp;</span><code style="font-family: Menlo, Consolas, 'Liberation Mono', Courier, monospace; font-size: 10pt; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(248, 248, 248); color: inherit; border: 1px solid rgb(234, 234, 234); margin: 0px 2px; padding: 0px 5px; word-break: normal; word-wrap: normal; -webkit-margin-before: 0px;" class="">return</code><span class="Apple-converted-space">&nbsp;</span>and have an inferred return type:</p><pre style="margin: 15px 0px; font-family: Menlo, Consolas, 'Liberation Mono', Courier, monospace; font-size: 10pt; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(248, 248, 248); color: inherit; border: 1px solid rgb(204, 204, 204); overflow: auto; padding: 4px 8px; word-break: normal; word-wrap: normal;" class=""><code class="swift" style="font-family: Menlo, Consolas, 'Liberation Mono', Courier, monospace; font-size: 10pt; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(248, 248, 248); color: inherit; border: 0px; margin: 0px; padding: 0px; word-break: normal; word-wrap: normal; -webkit-margin-before: 0px;">let _ = { 42 } // Type: () -&gt; Int

let _ = [1,2,3].map { $0 * 5 } // T == Int
</code></pre><p style="margin: 15px 0px;" class="">There are also value returning code blocks in the language that feel the same but are inconsistent to the mentioned feature:</p><pre style="margin: 15px 0px; font-family: Menlo, Consolas, 'Liberation Mono', Courier, monospace; font-size: 10pt; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(248, 248, 248); color: inherit; border: 1px solid rgb(204, 204, 204); overflow: auto; padding: 4px 8px; word-break: normal; word-wrap: normal;" class=""><code class="swift" style="font-family: Menlo, Consolas, 'Liberation Mono', Courier, monospace; font-size: 10pt; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(248, 248, 248); color: inherit; border: 0px; margin: 0px; padding: 0px; word-break: normal; word-wrap: normal; -webkit-margin-before: 0px;">// Read-write computed property:
var integer: Int {  
    get { return 2016 }  
    set { /* do some work */ }  
}  

// Read-only computed property:
var string: String { return "hello swift" }  

// Function:
func pi() -&gt; Double {
    return 3.141
}

// Read-Write subscript:
subscript(index: Int) -&gt; Int {
    get { return index % 2 }
    set { /* do some work */ }
}

// Read-only subscript:
subscript(index: Int) -&gt; Int { return index * 2 }
</code></pre><h2 id="proposedsolution" style="font-weight: bold; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(204, 204, 204); font-size: 24px;" class="">Proposed solution</h2><p style="margin: 15px 0px;" class="">Make<span class="Apple-converted-space">&nbsp;</span><code style="font-family: Menlo, Consolas, 'Liberation Mono', Courier, monospace; font-size: 10pt; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(248, 248, 248); color: inherit; border: 1px solid rgb(234, 234, 234); margin: 0px 2px; padding: 0px 5px; word-break: normal; word-wrap: normal; -webkit-margin-before: 0px;" class="">return</code><span class="Apple-converted-space">&nbsp;</span>optional for the following top level code blocks that only contain a single expression:</p><ul style="margin: 15px 0px;" class=""><li style="margin: 15px 0px; -webkit-margin-before: 0px;" class=""><em style="-webkit-margin-before: 0px;" class="">variable-declaration</em></li><li style="margin: 15px 0px;" class=""><em style="-webkit-margin-before: 0px;" class="">getter-setter-block</em></li><li style="margin: 15px 0px;" class=""><em style="-webkit-margin-before: 0px;" class="">getter-clause</em></li><li style="margin: 15px 0px;" class=""><em style="-webkit-margin-before: 0px;" class="">function-body</em></li><li style="margin: 15px 0px;" class=""><em style="-webkit-margin-before: 0px;" class="">subscript-declaration</em></li></ul><p style="margin: 15px 0px;" class="">That will allow us to rewrite the above example to:</p><pre style="margin: 15px 0px; font-family: Menlo, Consolas, 'Liberation Mono', Courier, monospace; font-size: 10pt; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(248, 248, 248); color: inherit; border: 1px solid rgb(204, 204, 204); overflow: auto; padding: 4px 8px; word-break: normal; word-wrap: normal;" class=""><code class="swift" style="font-family: Menlo, Consolas, 'Liberation Mono', Courier, monospace; font-size: 10pt; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(248, 248, 248); color: inherit; border: 0px; margin: 0px; padding: 0px; word-break: normal; word-wrap: normal; -webkit-margin-before: 0px;">// Read-Write computed property:
var integer: Int {  
    get { 2016 }  
    ...
}  

// Read-only computed property:
var string: String { "hello swift" }  

// Function:
func pi() -&gt; Double { 3.141 }

// Read-Write subscript:
subscript(index: Int) -&gt; Int {
    get { index % 2 }
    ...
}

// Read-only subscript:
subscript(index: Int) -&gt; Int { index * 2 }
</code></pre><p style="margin: 15px 0px;" class=""><strong style="-webkit-margin-before: 0px;" class="">Possible real world example:</strong></p><pre style="margin: 15px 0px; font-family: Menlo, Consolas, 'Liberation Mono', Courier, monospace; font-size: 10pt; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(248, 248, 248); color: inherit; border: 1px solid rgb(204, 204, 204); overflow: auto; padding: 4px 8px; word-break: normal; word-wrap: normal;" class=""><code class="swift" style="font-family: Menlo, Consolas, 'Liberation Mono', Courier, monospace; font-size: 10pt; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(248, 248, 248); color: inherit; border: 0px; margin: 0px; padding: 0px; word-break: normal; word-wrap: normal; -webkit-margin-before: 0px;">// Today
public struct Character {
     
    public let source: Module.Source
    private let _pointer: UnsafePointer&lt;Swift.Character&gt;
     
    public var value: Swift.Character {
        return self._pointer.pointee
    }
    ...
}

// Rewritten:
public struct Character {
    ...
    public var value: Swift.Character { self._pointer.pointee }
    ...
}
</code></pre><h2 id="impactonexistingcode" style="font-weight: bold; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(204, 204, 204); font-size: 24px;" class="">Impact on existing code</h2><p style="margin: 15px 0px;" class="">None, this change will only relax some existing rules.</p><h2 id="alternativesconsidered" style="font-weight: bold; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(204, 204, 204); font-size: 24px;" class="">Alternatives considered</h2><p style="margin: 15px 0px;" class="">Leave this as is and live with such inconsistency.</p><div style="margin: 15px 0px;" class=""><br class="webkit-block-placeholder"></div></div><div class="bloop_original_html" style="font-family: Helvetica, Arial; font-size: 13px; 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-stroke-width: 0px; background-color: rgb(254, 254, 254);"><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; margin: 0px;" class=""><br class=""></div><br class=""><div id="bloop_sign_1487319131171746048" class="bloop_sign"><div style="font-family: helvetica, arial; font-size: 13px;" class="">--&nbsp;<br class="">Adrian Zubarev<br class="">Sent with Airmail</div></div></div><div class="bloop_markdown" style="font-family: Helvetica, Arial; font-size: 13px; 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-stroke-width: 0px; background-color: rgb(254, 254, 254);"><div style="margin: 15px 0px; -webkit-margin-before: 0px;" class=""><br class="webkit-block-placeholder"></div></div><span style="font-family: Helvetica, Arial; font-size: 13px; 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-stroke-width: 0px; background-color: rgb(254, 254, 254); float: none; display: inline !important;" class="">_______________________________________________</span><br style="font-family: Helvetica, Arial; font-size: 13px; 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-stroke-width: 0px; background-color: rgb(254, 254, 254);" class=""><span style="font-family: Helvetica, Arial; font-size: 13px; 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-stroke-width: 0px; background-color: rgb(254, 254, 254); float: none; display: inline !important;" class="">swift-evolution mailing list</span><br style="font-family: Helvetica, Arial; font-size: 13px; 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-stroke-width: 0px; background-color: rgb(254, 254, 254);" class=""><a href="mailto:swift-evolution@swift.org" style="color: rgb(65, 131, 196); background-color: rgb(254, 254, 254); text-decoration: none; font-family: Helvetica, Arial; font-size: 13px; 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;" class="">swift-evolution@swift.org</a><br style="font-family: Helvetica, Arial; font-size: 13px; 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-stroke-width: 0px; background-color: rgb(254, 254, 254);" class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" style="color: rgb(65, 131, 196); background-color: rgb(254, 254, 254); text-decoration: none; font-family: Helvetica, Arial; font-size: 13px; 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;" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br style="font-family: Helvetica, Arial; font-size: 13px; 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-stroke-width: 0px; background-color: rgb(254, 254, 254);" class=""></div></blockquote></div><br class=""></div></body></html>