Add the Ternary Operator #99
Replies: 10 comments
-
The actual problem with ternary operator is that people can't agree on how to format it. Of course every serious person knows the one true way though: c1 ? v1 :
c2 ? v2 :
c3 ? c31 ? v31 :
v3d :
vd; |
Beta Was this translation helpful? Give feedback.
-
There is already |
Beta Was this translation helpful? Give feedback.
-
This will be in our "easy to use new super awesome gateway language" to introduce users from C#, Java, JavaScript, Python, etc. to the way of the crab: I don't have any responses on this one yet and it makes me sad :(. Lol. I actually believe in this one tho. I think it's the key ingredient to taking over the world. Although we need a new name for it now. Crabby has been taken for clippy. |
Beta Was this translation helpful? Give feedback.
-
Can we elaborate more on its integrarion with Let's we have
|
Beta Was this translation helpful? Give feedback.
-
What if this was done with a macro? let some_var = ?!(some_condition ? "true" : "false"); |
Beta Was this translation helpful? Give feedback.
-
And it would literally just expand to this |
Beta Was this translation helpful? Give feedback.
-
Brilliant. Just brilliant. Yes. |
Beta Was this translation helpful? Give feedback.
-
I know this is a pipe-dream which is why I didn't take my little "RFC" message seriously. I do think that I suggest we change it from let b = true;
let i = (b ?? "Yes") ?: "No"; In this snippet, // Impl for the `??` operator
impl<T> core::ops::IsTrue for bool {
type Output = T;
fn is_true(self, rhs: T) -> Option<Self::Output> {
if self {
Some(rhs)
} else {
None
}
}
} For With both operators implemented, the equivalent "desugared" code from the first snippet would look like this: let b = true;
let i = (if b {
Some("Yes")
} else {
None
}).unwrap_or("No"); There definitely could be a better way at implementing this, but using |
Beta Was this translation helpful? Give feedback.
-
If using the value if True else value2 yeah it is kinda the opposite of but still better than |
Beta Was this translation helpful? Give feedback.
-
Summary
Now that there's a fork getting enough traction, I'd like to propose our best competitive advantage: The Ternary Operator. It'll make my code look nice and run faster I think
Motivation
Please. Listen to me, okay. It's all I've wanted since like 2015. It can't be that hard, I've made my own language before and it had a ternary operator. Just figure it out idk
Guide-level explanation
Reference-level explanation
It would look like this
Drawbacks
None
Rationale and Alternatives
Rationale:
Alternatives:
Unresolved Questions
Future possibilities
Beta Was this translation helpful? Give feedback.
All reactions