On Thu, 06 Aug 2009 15:06:49 -0400, 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. > > 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. > > It seems to me that this could be added to D with very little effort and > would add a feature to the language. > > 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... > > I will also throw out (at no cost) a suggestion for the Python people: > Why not make "/%" the divmod operator (returning the quotient and > remainder)? It would return a tuple, but Python is used to that. > > Paul
// has potential to be useful as an operator. Maybe # would be a nice replacement. Easier to type, used as comment in other languages and no apparent use as operator. Imho, for D, to change the meaning for // might be too much of a breaking change.
