Paul D. Anderson wrote: > I was browsing the Python spec yesterday and came across this interesting > and useful syntax: > > "/" (one slash) means floating point division, e.g. 5/2 = 2.5 even though > 5 and 2 are integers > > "//" (two slashes) means integer (floor) division, e.g. 5.0//2.0 = 2.0 > even though 5.0 and 2.0 are floats.
Yeah, I love that distinction. As a matter of fact, I've added it to my own language. Same syntax, too, though there was some thought about using the "div" keyword instead. > I've always been a little troubled by the standard division operator being > dependent on the types of the operands. (I understand the need for it, I > just didn't like it much.) Now here is an elegant (IMHO) solution. I agree. It's one of those C idiosyncrasies the world could do without. > It seems to me that this could be added to D with very little effort and > would add a feature to the language. Seems like trouble to me. If we ignore for the moment the fact that "//" is used for line comments (D could use "div", for example), changing the meaning of "/" for integer operands would probably break many programs. > Oh wait...I think "//" is used elsewhere. Well, we could still use it but > mark it as a breaking change. Then users could simply remove all previous > uses of "//" from their code. If they REALLY need to retain the old "//" > functionality we could replace it with a new symbol. How about "--", like > Ada? Oh wait... Line-comments are very useful. My language uses "|". -- Michiel Helvensteijn