-
-
Notifications
You must be signed in to change notification settings - Fork 172
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
[Feature request] Ternary operator #621
Comments
Might as well make it short-circuiting too (#619). |
Lazy evaluation would make this more useful, but it's worth adding even before then. For example, this:
would become:
|
Also note that to be consistent with other operators, including mere parentheses, this should turn strings into numbers. Which would disallow things like |
Well, RGBASM is actually very strongly typed, with expression syntax depending on the expected type, so the ternary operator could be separately implemented for strings. |
True, but should it? And if so/regardless, should |
Is it? |
|
The Pasmo assembler also has a |
Another use case for ternary operators without waiting for lazy evaluation (even if they end up both being added in the same release): pokecrystal16's code-generating macros (a bad idea for small patterns, but necessary for cases like this).
This would be clearer as:
Also:
|
@ISSOtm's https://github.com/ISSOtm/rsgbds rewrite will make it more feasible to add a short-circuiting ternary operator. We're considering the syntax for it.
Wikipedia may have more ideas. (Note that short-circuiting (My personal vote is for 4 ( |
I think |
This would be mostly useful for within user-defined functions (#201), but would also be more terse than the current
if/else/endc
.Example:
The text was updated successfully, but these errors were encountered: