3 ms·
Real example: I'm collecting some quality signals from a corpus, most of which are some form of ratio, average, weighted average, or scaled average of counting
by nostrademons 8y ago
Real example: I'm collecting some quality signals from a corpus, most of which are some form of ratio, average, weighted average, or scaled average of counting various quantities within the documents. If the elements being counted are missing, I want the term involving that quality signal to disappear from the final ranking calculation.
Defining x / 0 = 0 gets this behavior for free, while leaving zero as an exception means it has to be caught for every single signal calculation, which is a pain when there are potentially dozens of different signals, all of which are counting different things (and have different divisors). I've actually defined a helper function to do this automatically, which also lets me change the default "null object" easily if I choose a different representation or want to apply some baseline value.
- goerz 8y agoDefining a function would seem like exactly the right thing to do! There's no problem.
- nostrademons 8y agoModule-scoped operator overloading would be really, really nice in this situation, though.
- vmchale 8y agoNo, it probably wouldn't, unless you were using integers. Pony still uses floats and returns NaN or Infinity or something.