3 ms·
OK. I've been coding in a lot of rust recently, and I can't make heads or tails of why that expression is legal and why the resulting type is (bool, bool). I as
by michael_j_ward 6y ago
OK. I've been coding in a lot of rust recently, and I can't make heads or tails of why that expression is legal and why the resulting type is (bool, bool). I assume that this is part of the point.
Anyone care to spell it out for me?
- michael_j_ward 6y agoAnd here's the answer: https://github.com/rust-lang/rfcs/pull/2527#issuecomment-414635205 https://github.com/rust-lang/rfcs/pull/2527#issuecomment-414... WOW that's certainly a `wat` EDIT: ok - now that I look at it, I understand. My brain was very, very primed to see the <woe, is> as type parameters - and it's late
- cies 6y agoI'm not sure if this is were it came from, but "wat" reminds me of this short funny talk: https://www.destroyallsoftware.com/talks/wat https://www.destroyallsoftware.com/talks/wat Just some context.
- wffurr 6y agohttps://knowyourmeme.com/memes/wat https://knowyourmeme.com/memes/wat
- michael_j_ward 6y agoThat page should have a link to that talk by Gary Bernhardt, because is the reason I reach for the term for "unexpected code behavior." And I'd wager that's true of many in the software community.
- Sharlin 6y agoTo some extent the problem exists in all languages that overload the less than and greater than symbols to also mean angle brackets. C++ infamously has to disambiguate using either the `template` or `typename` keyword in some cases; Rust on the other hand uses the shorter `::` sigil but also more consistently so the programmer doesn’t have to guess or memorize complex rules. Java uses the rather awkward `object.<Type>method()` syntax when you need to explicitly specify a type parameter in a method invocation (which luckily is not very often, and to be fair does mirror the method declaration syntax so there’s that).
- ArchOversight 6y agofn main() { let (oh, woe, is, me) = ("the", "Turbofish", "remains", "undefeated"); let _: (bool, bool) = (oh<woe, is>(me)); } So we have four strings, one named "oh", one named "woe", one named "is" and one named "me". (varA, varB) is a tuple in Rust that contains two variables, named varA and varB. oh < woe Is checking to see if "oh" is less than "woe" is > (me) is checking to see if "is" is greater than "me" (ignore the extra parentheses. So: (oh<woe, is>(me)) with some more spacing to make it easier to see, and with the extra parentheses removed is: (oh < woe, is > me) Basically it creates a tuple with the result of the above comparisons.
- amouat 6y agoAnd for anyone (like me) that thought, "ok that's fair enough, what's the problem?", the issue is that it could also be interpreted as generic arguments. A full explanation of the ambiguity is in the linked issue: let a = (b<c, d>(e)); This can either mean a tuple let a = ((b < c), (d > e)); Or a pair of generic arguments. let a = b::<c, d>(e);