Skip to content
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

Conditional Expression without else #102

Open
alongubkin opened this issue Nov 29, 2014 · 6 comments
Open

Conditional Expression without else #102

alongubkin opened this issue Nov 29, 2014 · 6 comments

Comments

@alongubkin
Copy link
Owner

var v = x if a;

compiles to:

var v = x if a else null;

which compiles to:

var v = a ? x : null;
@Namek
Copy link
Collaborator

Namek commented Nov 29, 2014

will this work?
(x if a) == 5

@alongubkin
Copy link
Owner Author

@Namek yes

@mationai
Copy link

+1. Will it still work if if <expr> then <expr> else <expr> #98 is to be added?

@andrewluetgers
Copy link

I have rarely ever though I would want something like this, ternary expressions never felt wrong. But when I have more than one condition the ternary mode can become a mess. This is not the best example in the world but it illustrates my point.

var size = useLarge ? "large" : useSmall ? "small" : "medium";

rewritten with the proposed form

var size = "large" if useLarge else "small" if useSmall else "medium";

formats nicely too

var size = "large" if useLarge else 
           "small" if useSmall else 
           "medium";

@Namek
Copy link
Collaborator

Namek commented Nov 30, 2014

@andrewluetgers ❤️

@nmn
Copy link

nmn commented Dec 1, 2014

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants