Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Just implement infix:<%> and infix:<%%> already #132

Closed
4 tasks done
masak opened this issue Mar 14, 2016 · 3 comments
Closed
4 tasks done

Just implement infix:<%> and infix:<%%> already #132

masak opened this issue Mar 14, 2016 · 3 comments

Comments

@masak
Copy link
Owner

masak commented Mar 14, 2016

I just looked over the examples, and it maybe it's me being obsessed with modulo-related code examples — probably — but it would seem that all three of euclid-gcd.007, fizzbuzz.007, and nicomachus.007 would benefit from having infix:<%> (and infix:<%%>) built into the language.

So,

  • Let's implement those.
  • Let's not implement infix:</> for now. I'm still bothered by the things described in this comment.
  • There's the risk of a division by zero, even with infix:<%> and infix:<%%>. So we'll need a new 007-exception type, and we'll need tests that try catching it.
  • After we have the operators, we should go back and make the examples prettier.
@masak
Copy link
Owner Author

masak commented Mar 15, 2016

  • There's the risk of a division by zero, even with infix:<%> and infix:<%%>. So we'll need a new 007-exception type, and we'll need tests that try catching it.

Actually, I ended up just using the Perl 6 exception (X::Numeric::DivideByZero) for now. We can save the custom-exceptions work for some later time, when we do it across the board.

@masak masak closed this as completed in a276b04 Mar 15, 2016
@vendethiel
Copy link
Collaborator

actual commits: b19d939...8c0bb8e

@masak
Copy link
Owner Author

masak commented May 11, 2018

哈哈. I just read https://news.ycombinator.com/item?id=17045074 and got cold sweat. "Hey, did we ever consider this in 007?"

Turns out we did — the above commit range contains tests for negative divisor. Also, Perl 6 and Python agree that 5 % -2 = 1. Guido has a blog post explaining why this is sane semantics.

JavaScript on the other hand consider 5 % -2 to be -1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants