<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 Jan 4, 2016, at 11:31 PM, Howard Lovatt <<a href="mailto:howard.lovatt@gmail.com" class="">howard.lovatt@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class="">I was guessing that the current proposal does not change anything re. default and current member wise initializers and so in addition to suggesting Scala syntax I was also suggesting the transformation shown, or its equivalent. The advantage of having a member wise init that has default arguments and argument labels are considerable:<div class=""><br class=""></div><div class="">1. Allows lets as well as vars </div></div></blockquote><div><br class=""></div><div>The proposal does allow lets as well as vars. It is very unfortunate that defaults for lets cannot be supported immediately. Doing that is a highly desired enhancement. If you read Chris Lattner’s comments in the history of this thread you will have more background on the issues involved.</div><br class=""><blockquote type="cite" class=""><div class=""><div class="">2. Allows partial custom initialization </div></div></blockquote><div><br class=""></div><div>I don’t know for sure what you mean by this but the proposal does allow partial custom initialization in the way I think of that phrase.</div><br class=""><blockquote type="cite" class=""><div class=""><div class="">3. Eliminates need for other mechanisms, i.e. default and existing member wise initialization </div><div class=""><br class=""></div><div class="">These facilities could be added to `memberwise init(...)` as well. In particular, if a member wise init was present then an initialized property could have a label, e.g.:</div></div></blockquote><div><br class=""></div><div>I do not think allowing custom labels for memberwise initialization parameters is a good idea. The caller is initializing a member directly. It is more clear if the name of the parameter matches the name of the parameter.</div><br class=""><blockquote type="cite" class=""><div class=""><div class=""><br class=""></div><div class=""> class C {</div><div class=""> let example name: Type = initial</div><div class=""> memberwise init(...)</div><div class=""> }</div><div class=""><br class=""></div><div class="">Would become the equivalent of:</div><div class=""><br class=""></div><div class=""> <font size="2" class=""><span style="background-color:rgba(255,255,255,0)" class=""> class C {</span></font></div><div class=""><font size="2" class=""><span style="background-color:rgba(255,255,255,0)" class=""> let name: Type</span></font></div><div class=""><font size="2" class=""><span style="background-color:rgba(255,255,255,0)" class=""> init(</span></font><span style="background-color:rgba(255,255,255,0);font-size:small" class="">example name: Type = initial) {</span></div><div class=""><span style="background-color:rgba(255,255,255,0);font-size:small" class=""> <a href="http://self.name/" class="">self.name</a> = name</span></div><div class=""><span style="background-color:rgba(255,255,255,0);font-size:small" class=""> }</span></div><div class=""><font size="2" class=""><span style="background-color:rgba(255,255,255,0)" class=""> }</span></font></div><div class=""><br class=""></div><div class="">The Scala syntax is just a shorter alternative, ideally there be a discussion of the pros and cons of the two syntax that included the possibility of the wider set of objectives as outlined in the numbered points above.</div></div></blockquote><div><br class=""></div><div>It was not a goal of this proposal to provide the most concise syntax for simple cases. The goal of this proposal is to provide a flexible and scalable memberwise initialization facility. Specific goals included supporting more than one memberwise initializer as well as allowing some properties to be memberwise initialized and some (private state, etc) to be initialized by other means.</div><div><br class=""></div><div>An independent proposal focused on making simple cases as concise as possible is something that could also be pursued.</div><br class=""><blockquote type="cite" class=""><div class=""><div class=""><br class="">On Tuesday, 5 January 2016, Matthew Johnson <<a href="mailto:matthew@anandabits.com" class="">matthew@anandabits.com</a>> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Jan 4, 2016, at 5:48 PM, Howard Lovatt <<a href="javascript:_e(%7B%7D,'cvml','howard.lovatt@gmail.com');" target="_blank" class="">howard.lovatt@gmail.com</a>> wrote:</div><br class=""><div class=""><div style="word-wrap:break-word" class="">Yes you can get close, but:<div class=""><br class=""></div><div class="">1. Its weird that you can only do this in an extension.</div></div></div></blockquote><div class=""><br class=""></div><div class="">This is the way the current implicit initializer works. It is not synthesized if you define any initializers in the body of the type. There are good reasons it works this way and the current proposal does not change those rules.</div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap:break-word" class=""><div class="">2. Its not quite the same as the proposal the current member-wise initialiser does not make the init arguments optional (the arguments themselves do not have defaults), i.e. with your example `let defaultOriginRect = Rect(size: Size(width: 5.0, height: 5.0))` fails whereas it would work for the proposal (this could also be true if the existing struct memberwise init and the new `memberwise init(..)` where changed to provide init argument defaults).</div></div></div></blockquote><div class=""><br class=""></div><div class="">The implicit memberwise initializer currently in the language does not provide defaults for parameters. This proposal changes that behavior and provides defaults if the the member is a `var` and has an initial value. </div><div class=""><br class=""></div><div class="">Unfortunately I was not able to find a solution to allow synthesized parameters for `let` members to have default values. This is because the current semantics for `let` members do not allow the member to be initialized to anything other than the initial value if one is provided. I am hoping a solution to this will be identified in the future and have suggested one possible mechanism `@default` in the future enhancements section.</div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap:break-word" class=""><div class="">3. Only ‘really' works for structs, the compiler doesn’t write a member-wise initialiser for classes (just a default initializer).</div></div></div></blockquote><div class=""><br class=""></div><div class="">That is true about the current behavior of the language but is not true with regards to the current proposal.</div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap:break-word" class=""><div class="">4. Still need the compiler to provide both default and member-wise initialisers, whereas this proposal would allow the existing default and member-wise initialisers to be deprecated and just the new member-wise initialiser would remain which would simplify the language and make it clear what was happening (this could also be true if a `memberwise init(..)` where added and existing compiler written inits removed).<br class=""></div></div></div></blockquote><div class=""><br class=""></div><div class="">This proposal does not change anything with regard to the default initializer.</div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap:break-word" class=""><div class=""><div class=""><br class="">
</div>
<br class=""><div class=""><blockquote type="cite" class=""><div class="">On 5 Jan 2016, at 10:16 AM, Matthew Johnson <<a href="javascript:_e(%7B%7D,'cvml','matthew@anandabits.com');" target="_blank" class="">matthew@anandabits.com</a>> wrote:</div><br class=""><div class=""><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class="">struct Rect { var origin: Point = Point(), size: Size = Size() }</div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class="">extension Rect {</div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""> init(center: Point, size: Size) {<br class=""><blockquote type="cite" class=""></blockquote> let originX = center.x - (size.width / 2)<br class=""><blockquote type="cite" class=""></blockquote> let originY = center.y - (size.height / 2)<br class=""><blockquote type="cite" class=""></blockquote> self.init(origin: Point(x: originX, y: originY), size: size)<br class=""><blockquote type="cite" class=""></blockquote> }</div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class="">}</div></div></blockquote></div><br class=""></div></div></div></blockquote></div><br class=""></div></blockquote></div><br class=""><br class="">-- <br class=""> -- Howard.<br class=""><br class="">
</div></blockquote></div><br class=""></body></html>