-
Notifications
You must be signed in to change notification settings - Fork 1.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
Lower the restrictions on if let
#2186
Comments
I'm not sure I understand. Do you mean to yield two values? let (a, b) = {
// ...
(a_value, b_value)
}; |
I guess what @fwrs means is that, as A concrete example: Current let a = {
let b = 1;
b + 1
}; Proposed let a = if let b = 1 {
b + 1
}; I'm not sure the above incentive is strong enough though. |
I don't understand why you'd want an |
I think I'd expect it to be something more SML-like, maybe let foo_squared =
let x = foo()
in x * x; (Though I'm not convinced that's worth supporting when the block works fine.) |
You can write it like this if you want to 🤷♂️: let a = { let b = 1;
b + 1
}; |
There's also this, which is closer in semantics to let a = match 1 {
b => b + 1
}; |
I'd suggest using a new keyword "with" for a construct like this. It already has similar usage as a keyword to specify RAII-style object disposal in other languages, and it suggests the right idea to someone not familiar with it. Something like: let a = with b = 1 {
b + 1
} |
Introducing language concepts for seldom useful stuff like this would only confuse people. You don't even save any time from typing it out and it removes no boilerplate. |
Fair enough. At the same time, I don't want to be put in the position where I'm cracking my head over rust code for hours, just to realize that "if" is syntactically overloaded to also "plant" variable within scopes. See c++ operator overloading and why some people will argue for days on end why it's a bad thing even though it makes many expressions cleaner. |
@eaglgenes101 But it's not, the |
This seems resolved per #2086. |
Sometimes, a construct like the following one is used.
I think it would look prettier with
if let
(it's also idiomatic in many lisps)But rust can likely fail with either https://doc.rust-lang.org/error-index.html#E0317 or https://doc.rust-lang.org/error-index.html#E0162 if in the place of
...
we have a known valueThe text was updated successfully, but these errors were encountered: