-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
replace itrunc(Uint8, 1234) => mod(1234, Uint8), etc. [fix #8646] #8648
Conversation
@@ -174,8 +174,8 @@ for to in tuple(IntTypes...,Char), from in tuple(IntTypes...,Char,Bool) | |||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you missed an itrunc on line 172
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, yes. it was initially unclear to me if that was this kind of itrunc
, but it must be.
it seems more idiomatic to do |
The reverse argument order of |
I liked the idea of using |
I think @simonbyrne made some pretty compelling arguments against cramming all of that into |
Ok, I guess I won't argue with Simon and Steve J on that. We can use mod or % here, and also replace |
I kind of like |
The only problem with using |
We could make |
Just subjective, but |
The operators syntax really feels right though and it's really concise :-) |
You humans and your infix. |
Humans are the worst, JeffBot2000. |
@simonbyrne, @stevengj – what do you think of the latest incarnation of this using |
i'm still waiting for convert to get it's own (strong bad) operator #1470 (comment) |
|
Can that just be called unsafe_trunc and safe itrunc gets folded into trunc? |
@JeffBezanson, are you cool with me merging this? This is going to cause a lot of updates to packages that just had to change convert to itrunc, but it seems unavoidable. |
Yes, I'm ok with it. More specifically, I don't have a better alternative to offer. It's kind of unfortunate that integer truncation has an operator, and |
This would seem less odd if there were more other cases of |
That is true. We could, of course, make more instances – e.g. |
I agree that it could be nice to have syntax for conversion too, though that particular syntax seems dangerously close to macro invocation? |
I'm still a fan of |
With an infix operator for convert, would it be possible to allow their use in method definition? E.g. have foo(x, y as Int, z) = x + y + z equivalent to foo(x, y, z) = foo(x, convert(Int, y), z)
foo(x, y::Int, z) = x + y + z |
@joehuchette That is a really interesting idea! |
It would be great for wrapping some of the C optimization libraries we work with (e.g. CPLEX, SCIP), where this is a common idiom. |
Yes, that's a really good idea. Syntactic interplay with type annotation on the same argument is a bit messy though. |
I like that idea too. (I think you would just disallow type annotation on the same argument: the |
There are inevitably going to be cases where you want both dispatch constraints and conversion. But maybe that doesn't matter. |
F(x::Real as Int) That last one is a bit strange, but they look quite readable +1 |
Can we move this thread to 8710? |
As far as I can tell there is no mention of this in the documentation. |
Here's the proposal I put forth in #8646 to replace
itrunc(Uint8, 1234)
etc. withmod(1234, Uint8)
. Not necessarily how we want to do this, but at least it (hopefully) identifies all the places in base where this needs to be changed.