There are only 6 uses of // outside of rationals.jl in base (4 of those are 
in mpfr.jl), compared to 187 uses of div, and 22 uses of ÷. (that’s uses, 
not definitions, exports, documentation, although the ratios are very 
similar).
Looking at packages, it seems also that div is used frequently, and many 
times more than // for rational numbers.

I don’t think counting usages of // vs ÷ is necessarily fair, since I think 
// is used less than it should be (for reasons I eventually expanded into a 
section in the Julia style guide 
<http://docs.julialang.org/en/release-0.4/manual/style-guide/#avoid-using-floats-for-numeric-literals-in-generic-code-when-possible>).
 
More fair would be to compare the number of usages of ÷ with the number of 
usages of // *plus the number of float literals*. (The results might be the 
same, though - I haven’t actually made the comparison).

But more to the point:

That is your opinion, however a number of other people disagree.

*Exactly.* People disagree on this, and there seems to be a shortage of 
ASCII characters (or character sequences) for everyone to have it all. In 
the table you posted a while ago, I notice that Julia is the *only* 
language which has infix operators for both (int, int) -> float, (int, int) 
-> int and (int, int) -> rational division. I’m not saying the design of 
this is final (software design is never final for software reasons - only 
for people reasons…) but to me it looks like Julia has already hit a sweet 
spot in supporting as much as possible for as many tastes as possible.

Note that what the author *really wants* is to get the i-th potion of an 
array

Tamas Papp already posted an idiomatic solution for this:

Define 

portion(i,n,m=100) = 1+div(i*m,n):div((i+1)*m,n)

and use 

a[portion(i,n)]

// T

On Tuesday, April 5, 2016 at 4:55:05 AM UTC+2, Scott Jones wrote:


>
> On Monday, April 4, 2016 at 7:27:40 AM UTC-4, Stefan Karpinski wrote:
>>
>> Number does not imply or assume commutativity. The Quaternions package 
>> provides a Quaternion type which is a subtype of Number. Rational, however, 
>> only allows integer numerators and denominators. Since integer 
>> multiplication is commutative, rational multiplication is too. But I still 
>> think it best to reserve \\ with an analogous meaning to //. There are 
>> already two syntaxes for integer division, which is plenty.
>>
>
> That is your opinion, however a number of other people disagree. Every 
> other language I've dealt with has had a simple ASCII sequence for integer 
> division, / (in C, C++, Java, Python2 with integer operands), \ (in Mumps & 
> Caché Object Script), or // (Python and Lua).
> (and no, typing \div<tab> in the REPL and something else in an editor [as 
> well as having to customize one's editor] just to get a Unicode ÷ 
> character, is not really that useful)
>
> About \\ in particular, that's fine then, probably better to reserve that 
> for rationals.
> To me, it does seem a bit strange though that // was picked for rationals 
> in Julia, something sure to cause confusion for people coming from Python 
> (which seems to be a large part of people moving to Julia) or Lua, when 
> integer division is used so much more frequently than rational numbers.
> There are only 6 uses of // outside of rationals.jl in base (4 of those 
> are in mpfr.jl), compared to 187 uses of div, and 22 uses of ÷.  (that's 
> uses, not definitions, exports, documentation, although the ratios are very 
> similar).
> Looking at packages, it seems also that div is used frequently, and many 
> times more than // for rational numbers.
>
> What about a different two character ASCII sequence that is currently a 
> syntax error?
> I think /| could be used, and could be easily remembered as being integer 
> division (unlike ÷), it could be described as doing a division / and 
> cutting off the remainder |.
>
​

Reply via email to