<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="">I think that his number assignment (via `<~`) depends on the current state of `amount`, and that using FloatLiteralConvertible does not provide enough information at the call site (since the current value is not available in the initializer).<div class=""><br class=""></div><div class="">Stephen</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 6, 2015, at 1:43 PM, Alex Lew via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Don, have you considered making your Number type FloatLiteralConvertible? This would allow you not just to <b class="">let number: Number = 4.9</b>, but also pass in 4.9 to a function that expected a <b class="">Number</b>. It would not let you set Number variables to be equal to other variables of type Float, it seems your main use case here is literals anyway.<div class=""><br class=""></div><div class=""><a href="http://swiftdoc.org/v2.0/protocol/FloatLiteralConvertible/" class="">http://swiftdoc.org/v2.0/protocol/FloatLiteralConvertible/</a><br class=""></div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Sun, Dec 6, 2015 at 9:26 AM, Don Wills via swift-evolution <span dir="ltr" class=""><<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="">
Silvan,
</div>
<div class="">
<br class="">
</div>Yes, I understand the concern you raise. I too have held that general opinion of overloading operators in other languages for many years. That said, overloading arithmetic and other operators causes the same opportunity for abuse. For example, overloading + for integers to do something different (like rounding instead of truncation) would make maintenance of existing programs into a giant guessing game.
<div class="">
<br class="">
</div>
<div class="">
That said, once the cat is out of the bag to overload operators, I don't see how adding support for = makes things any worse.
</div>
<div class="">
<br class="">
</div>
<div class="">
FYI, the reason for my suggestion is to add support for fixed decimal arithmetic just like that available in COBOL. Yeh I can hear the groans now. However, for business applications, fixed decimal arithmetic is a basic feature that has been tossed away in new languages by language designers who don't actually labor in the trenches. I've built a simple class to do just that - here is some sample code that uses my Number class that gives an idea of what the code does:
</div>
<div class="">
<br class="">
</div>
<div class="">
var amount = Number(left: 6, right: 2);
</div>
<div class="">
var result = Number(left: 9, right: 2);
</div>
<div class="">
amount <- 3.9;
</div>
<div class="">
amount += 1;
</div>
<div class="">
result <- amount * 4;
</div>
<div class="">
print(result)
</div>
<div class="">
<br class="">
</div>
<div class="">
Note that <- is the assignment operator. I am sure all would agree that = is superior in this situation. Such code would be far more readable and the Number values would act just like and interoperate with Float and Int in all regards *except* that currently the = operator is not available for assignment.
</div>
<div class="">
<br class="">
</div>
<div class="">
Don Wills
</div>
<div class="">
<br class="">
</div>
<div class="">
PS. FWIW, the IEEE 754-2008 d128 alternative that Chris Lattner mentioned to me is inferior to the kind of support for fixed decimal arithmetic that I believe would help make Swift superior to C# for business applications.
</div>
<div class="">
<br class="">
</div>
<div class=""></div>
<div class="">
<br class="">
<blockquote type="cite" class="">
<div class="">
On Dec 6, 2015, at 6:58 AM, Silvan Mosberger <
<a href="mailto:kametrixom@icloud.com" target="_blank" class="">kametrixom@icloud.com</a>> wrote:
</div>
<br class="">
<div class="">
<div style="word-wrap:break-word" class="">
<div class="">
Hi Don
</div>
<div class="">
<br class="">
</div>
<div class="">
I think this is a terrible idea! Imagine what you’d be able to do with that:
</div>
<div class="">
<br class="">
</div>
<div class="">
<div style="margin:0px;font-size:18px;line-height:normal;font-family:Menlo" class="">
<span style="color:#35568a" class="">let</span> x :
<span style="color:#c35900" class="">String</span> =
<span style="color:#35568a" class="">3</span>
</div>
</div>
<div class="">
<br class="">
</div>
<div class="">
This would lead to the same problems already discussed with implicit initialisers:
<a href="https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20151130/000531.html" target="_blank" class="">https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20151130/000531.html</a>, just worse. Also assignment is something more fundamental than other operators, I doubt it’s even possible to do that.
</div><div class=""><div class="h5">
<br class="">
<div class="">
<blockquote type="cite" class="">
<div class="">
On 06 Dec 2015, at 14:44, Don Wills via swift-evolution <
<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>> wrote:
</div>
<br class="">
<div class="">
<div class="">
The ability to overload operators is very useful. However, that utility is diminished without the ability to overload the simple assignment operator ( = ). I vaguely recall reading somewhere that there is a reason for this having to do with syntax ambiguity. Can this problem be solved so that = can be overloaded?
<br class="">
<br class="">Don Wills
<br class="">_______________________________________________
<br class="">swift-evolution mailing list
<br class="">
<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>
<br class="">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a>
<br class="">
</div>
</div>
</blockquote>
</div>
<br class="">
</div></div></div>
</div>
</blockquote>
</div>
<br class="">
<div style="margin-top:10px;font-size:12px;font-family:Helvetica,Arial;color:#999" class="">
Untracked with
<a style="color:#999" href="https://trackbuster.com/?sig" target="_blank" class="">Trackbuster</a>
</div><br class="">_______________________________________________<br class="">
swift-evolution mailing list<br class="">
<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="">
<br class=""></blockquote></div><br class=""></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=5xu02FVv-2BCbxTLHpBsC0RVeXVC5uCln3pUIIeLTlIi0hen7IaMSZSFNO0EzFEndTn-2Bd8LBYiEgZ6mPDwbZ2jKftf5SlSc-2FJM4TjPKjRbKb6fY63b18px4-2Fzxv6yjBL2soA3p0gGrcgzXuol6YTfVMLHwNyyQCeqnq93oZmaihSAzLFgPxqqddxu6nM8MoV2QBoWZnyCIcjnzRjGqJwtEcnC0f0MvC97FL2fqLlVjvyA-3D" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;" class="">
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></div></body></html>