4 ms·
> Why don't we just get our computer languages to understand what "2, 3, ..., 12" means? Some languages already do: for example, in Ruby you can use (-5..-1) t
by crooked-v 7y ago
> Why don't we just get our computer languages to understand what "2, 3, ..., 12" means?
Some languages already do: for example, in Ruby you can use (-5..-1) to get [-5, -4, -3, -2, -1]. It's lazy evaluation, so you can even do stuff like:
Infinity = 1.0/0.0
(1..Infinity).step(2).take(5) #=> [0, 2, 4, 6, 8]
- burlesona 7y agoJust FYI you can get infinity without evaluating an expression: it’s defined on Float, Float::INFINITY
- acqq 7y ago> Ruby And before, Perl: https://perldoc.perl.org/perlop.html#Range-Operators https://perldoc.perl.org/perlop.html#Range-Operators I like ranges in Perl.
- noisem4ker 7y agoSame as in Haskell. https://wiki.haskell.org/List_comprehension https://wiki.haskell.org/List_comprehension
- mark-r 7y agoI remember seeing a rather convincing argument that 1.0/0.0 should not be infinity, but zero.
- jolmg 7y agoYou mean mathematically, or specifically for programming? For programming, I imagine it's better for it to be infinity than 0 since having 0 in the denominator implies that it's changing (who would write a constant 0 in a denominator?), and so as the denominator is approaching 0, the fraction is getting closer and closer to pos/neg infinity, not 0. Making it evaluate to zero would imply a change of direction for whatever the fraction represents. So, if it's a position, as the position goes 1000/1000, 1000/500, 1000/100, 1000/1, etc. it's getting closer to infinity. Having it suddenly go to 0 would break the pattern of movement. Mathematically, there is no x that satisfies x = 1/0 -> x * 0 = 1, since anything multipled by 0 is 0, so it's undefined.
- mark-r 7y agoYes, there's a discontinuity between the positive and negative numbers, that was part of the argument. Another part was that certain mathematical formulas get simpler when x/0 = 0.
- smabie 7y agoDo you remember seeing or do you remember?
- mark-r 7y agoIt was something on the internet. I wish I could come up with the proper search terms to find it again.
- QuinnWilton 7y agoThis is how Pony handles division. There's a good summary of possible motivations here: https://www.hillelwayne.com/post/divide-by-zero/ https://www.hillelwayne.com/post/divide-by-zero/
- QuinnWilton 7y agoI pasted the wrong link above, but my mobile app isn't letting me edit it. This is the link that describes their reasoning: https://tutorial.ponylang.io/gotchas/divide-by-zero.html https://tutorial.ponylang.io/gotchas/divide-by-zero.html
- mark-r 7y agoThank you! The mention of Pony gave me just enough ammunition to search for the article I remembered seeing. https://news.ycombinator.com/item?id=17736046 https://news.ycombinator.com/item?id=17736046 P.S. the link you provided is exactly the one.