If we assume that Swift was changed to be like Scala then:<div><br></div><div> protocol Stored {</div><div> let x = 42</div><div> }</div><div><br></div><div>Would be equivalent to:</div><div><br></div><div> protocol Stored {</div><div> var x: Int { get }</div><div> static func initX() -> Int</div><div> }</div><div><br></div><div> extension Stored {</div><div> static func initX() -> Int { return 42 }</div><div> }</div><div><br></div><div>If you then implemented the protocol:</div><div><br></div><div> struct S: Stored {</div><div> var x = 69 // Could be `let` instead of `var`</div><div> }</div><div><br></div><div>Would be equivalent to:</div><div><br></div><div> struct S: Stored {</div><div> var x = S.initX()</div><div> static func initX() -> Int { return 69 }</div><div> }</div><div><br></div><div>Therefore it is possible to unify the two concepts.<br><br>On Saturday, 30 January 2016, <<a href="mailto:davesweeris@mac.com">davesweeris@mac.com</a>> wrote:<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">Not really… There’s a pretty big difference between “no setter” and “const". Plus, since we’re talking about protocols, “var … {get}” doesn’t even mean “no setter”, it means “no setter <i>required</i>”. A regular var property (which is obviously not constant) can satisfy a {get} requirement.<div><br></div><div><div>
- Dave Sweeris (Non-Canonical Dave)
</div>
<br><div><blockquote type="cite"><div>On Jan 29, 2016, at 22:49, Howard Lovatt via swift-evolution <<a href="javascript:_e(%7B%7D,'cvml','swift-evolution@swift.org');" target="_blank">swift-evolution@swift.org</a>> wrote:</div><br><div>Scala uses their equivalent of let ... instead of var ... { get }. In Scala let ... Always means var ... { get }. Not a problem in Scala only having one concept. I think it is a possibility for Swift.<br><br>On Saturday, 30 January 2016, Brent Royal-Gordon via swift-evolution <<a href="javascript:_e(%7B%7D,'cvml','swift-evolution@swift.org');" target="_blank">swift-evolution@swift.org</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">> So what about protocols requiring ‘var … { get }’ syntax for read only properties? Is there some sort of underlying reason for this confusing syntax instead of ‘let …’? Now that Swift allows deferred initialization of lets does this requirement make sense?<br>
<br>
`let` doesn't mean "no setter", it means "constant". For instance, you can't make a `weak let`, because the `weak` implies the variable can be nilled. There's no way to require a constant in a protocol, but if there were one, that's what `let ...` would mean.<br>
<br>
--<br>
Brent Royal-Gordon<br>
Architechies<br>
<br>
_______________________________________________<br>
swift-evolution mailing list<br>
<a>swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote><br><br>-- <br> -- Howard.<br><br>
_______________________________________________<br>swift-evolution mailing list<br><a href="javascript:_e(%7B%7D,'cvml','swift-evolution@swift.org');" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div></blockquote></div><br></div></div></blockquote></div><br><br>-- <br> -- Howard.<br><br>