<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div><br></div><div>On Dec 28, 2016, at 14:24, Xiaodi Wu <<a href="mailto:xiaodi.wu@gmail.com">xiaodi.wu@gmail.com</a>> wrote:<br><br></div><blockquote type="cite"><div><div dir="ltr">On Wed, Dec 28, 2016 at 5:21 PM, Anton Zhilin <span dir="ltr"><<a href="mailto:antonyzhilin@gmail.com" target="_blank">antonyzhilin@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="m_5844606051936114984markdown-here-wrapper"><p style="margin:0px 0px 1.2em!important">What about “Rust way”?</p>
<pre style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px"><code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline;white-space:pre-wrap;overflow:auto;border-radius:3px;border:1px solid rgb(204,204,204);padding:0.5em 0.7em;display:block!important">protocol Default {
static var `default`: Self { get }
}
protocol Setupable {
mutable func setup(with params: Params)
}
func setupArray<T>(type: T.Type, params: Params) -> [T]
where T: Default & Setupable
{
return (1...42).map { i in
var next = T.default
next.setup(with: params)
return next
}
}
</code></pre><p style="margin:0px 0px 1.2em!important"><code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">default</code> is literally a “default” value. For primitives like <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">Int</code>, <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">Char</code>, <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">Bool</code>, <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">Float</code> etc. it is all zeros. For structs with <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">Default</code> fields, it’s all <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">default</code>s—unless some special semantics is given to them. For complex types, it’s an “empty” value, the most sane value before any setup or specification.</p></div></div></blockquote><div><br></div><div>The objection is not about the spelling. The point here is that such a protocol does not make sufficient semantic guarantees to enable any interesting generic algorithms not possible without it. As I pointed out, Rust explicitly makes no guarantees as to what the default value is and tells you that you must not care; "most sane" does not cut it as a guarantee.</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="m_5844606051936114984markdown-here-wrapper">
<div title="MDH:PGRpdiBjbGFzcz0iZ21haWxfZXh0cmEiPldoYXQgYWJvdXQgIlJ1c3Qgd2F5Ij88L2Rpdj48ZGl2
IGNsYXNzPSJnbWFpbF9leHRyYSI+PGJyPjwvZGl2PjxkaXYgY2xhc3M9ImdtYWlsX2V4dHJh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bGFzcz0iZ21haWxfZXh0cmEiPiZuYnNwOyAmbmJzcDsg
Jm5ic3A7ICZuYnNwOyBuZXh0LnNldHVwKHdpdGg6IHBhcmFtcyk8L2Rpdj48ZGl2IGNsYXNzPSJn
bWFpbF9leHRyYSI+Jm5ic3A7ICZuYnNwOyAmbmJzcDsgJm5ic3A7IHJldHVybiBuZXh0PC9kaXY+
PGRpdiBjbGFzcz0iZ21haWxfZXh0cmEiPiZuYnNwOyAmbmJzcDsgfTwvZGl2PjxkaXYgY2xhc3M9
ImdtYWlsX2V4dHJhIj59PC9kaXY+PGRpdiBjbGFzcz0iZ21haWxfZXh0cmEiPmBgYDwvZGl2Pjxk
aXYgY2xhc3M9ImdtYWlsX2V4dHJhIj48YnI+PC9kaXY+PGRpdiBjbGFzcz0iZ21haWxfZXh0cmEi
PmBkZWZhdWx0YCBpcyBsaXRlcmFsbHkgYSAiZGVmYXVsdCIgdmFsdWUuIEZvciBwcmltaXRpdmVz
IGxpa2UgYEludGAsIGBDaGFyYCwgYEJvb2xgLCBgRmxvYXRgIGV0Yy4gaXQgaXMgYWxsIHplcm9z
LiBGb3Igc3RydWN0cyB3aXRoIGBEZWZhdWx0YCBmaWVsZHMsIGl0J3MgYWxsIGBkZWZhdWx0YHMt
LXVubGVzcyBzb21lIHNwZWNpYWwgc2VtYW50aWNzIGlzIGdpdmVuIHRvIHRoZW0uIEZvciBjb21w
bGV4IHR5cGVzLCBpdCdzIGFuICJlbXB0eSIgdmFsdWUsIHRoZSBtb3N0IHNhbmUgdmFsdWUgYmVm
b3JlIGFueSBzZXR1cCBvciBzcGVjaWZpY2F0aW9uLjwvZGl2Pg==" style="height:0;width:0;max-height:0;max-width:0;overflow:hidden;font-size:0em;padding:0;margin:0"></div></div></div></blockquote></div></div></div>
</div></blockquote><div><br></div><div>Correct. Treating protocols as "bags of syntax" is tempting (I still find myself accidentally doing it from time to time), but that's not what a Swift protocol is.</div><div><br></div><div>Perhaps adding syntax to express a "bag of syntax" could be discussed either as its own topic (probably phase 2, but that's not my call), or later on as part of the macro system (it does sound rather macroish, IMHO).</div><div><br></div><div>- Dave Sweeris</div></body></html>