-
Notifications
You must be signed in to change notification settings - Fork 187
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
[enhancement] Allow if
without else
in DSLX
#1980
Comments
One of the major considerations around why we didn't add a "statement if" historically is that people can get confused about how to "evolve values" outside of the if block if they are written in side-effecting statement style; e.g. a new user going:
The fact that all conditions are actually ternaries (and that we can flag the syntax doesn't make sense for the if block) is supposed to help guide on the fact that it's all dataflow without mutation. If we want to keep that property since there should not be a ton of side-effect-only operations an alternative here would be to add |
Related: #707 |
I would vote for supporting it like in Rust. We could guide the user about data flow via the error/warning messages for invalid or useless assignments in an if block. Needing to manually implement a foo_if! for every foo! feels like a non-sustainable strategy, which is why issues get filed about missing ones, though we could "auto-generate" those. I think the bigger concern is that the current strategy promotes duplication of predicates. |
No objections so long as we check the diagnostics are good first so it's not an immediate stumbling block for new users. I've seen conditionals are usually the first place new users run into this. 👍 |
What's hard to do? (limit 100 words)
Currently, you can't have an
if
without anelse
part, which is different from Rust, where anif
without anelse
always returns a unit type:This is a small addition with well-defined behavior that can move DSLX closer to Rust syntax.
The change is not crucial by any means. We usually write empty
else
blocks when printing data withtrace_fmt!
.Current best alternative workaround (limit 100 words)
Write
if
with an emptyelse
Your view of the "best case XLS enhancement" (limit 100 words)
As stated before, this is not a crucial addition to the language, but in my opinion, it could make code more readable. One thing to consider is the usage of IO operations in such statements, but this IO operations would have to ignore the returned token. Once again, this should be well-defined behavior.
The text was updated successfully, but these errors were encountered: