proposed syntax change
Paul D. Anderson
paul.d.removethis.anderson at comcast.andthis.net
Thu Aug 6 13:59:08 PDT 2009
Robert Fraser Wrote:
> 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.
>
> I like the idea of adding a "floating point division", but I think it
> should be a *new* feature while the current / and // are left as they
> are. How about "./"?
>
> 5 / 2 = 2 // Current behavior
> 5.0 / 2.0 = 2.5 // Current behavior
> 5 ./ 2 = 2.5 // New behavior
> 5.0 ./ 2.0 = 2.5 // It always floating-point divides
>
> IOW, ./ is short for "cast operands to double and divide".
>
> If ./ proves too hard to parse (I think it might require some
> lookahead), then /^ might work.
To the extent that this was a serious proposal (that is, to a very, very small extent) I would rather reserve the ./ operator for element-wise array division, along with .*, etc., since I'm used to that in other languages. (And the whole point of proposing syntax is to make one's own self comfortable, right?)
Paul
More information about the Digitalmars-d
mailing list