[go: nahoru, domu]

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

Add ternaries (b ? c : d) #221

Open
1 task
staycoolcall911 opened this issue Oct 4, 2022 · 9 comments
Open
1 task

Add ternaries (b ? c : d) #221

staycoolcall911 opened this issue Oct 4, 2022 · 9 comments
Labels
🛠️ compiler Compiler good first issue Good for newcomers 📜 lang-spec-impl Appears in the language spec roadmap roadmap 📜 spec Requires a change in the Language/SDK spec

Comments

@staycoolcall911
Copy link
Contributor
staycoolcall911 commented Oct 4, 2022

We'd like to add support for ternaries.

  • Also add to the winglang reference
@staycoolcall911 staycoolcall911 added the 📜 spec Requires a change in the Language/SDK spec label Oct 4, 2022
@eladb eladb changed the title Add ternaries to the spec (let a = b ? c : d;) Add ternaries to the spec (b ? c : d) Oct 6, 2022
@github-actions
Copy link
github-actions bot commented Dec 6, 2022

Hi,

This issue hasn't seen activity in 60 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days.
Feel free to re-open this issue when there's an update or relevant information to be added.
Thanks!

@github-actions github-actions bot added the Stale label Dec 6, 2022
@staycoolcall911
Copy link
Contributor Author

Keep

@staycoolcall911 staycoolcall911 added good first issue Good for newcomers and removed good first issue Good for newcomers labels Dec 6, 2022
@github-actions github-actions bot removed the Stale label Dec 7, 2022
@github-actions
Copy link
github-actions bot commented Feb 7, 2023

Hi,

This issue hasn't seen activity in 60 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days.
Feel free to re-open this issue when there's an update or relevant information to be added.
Thanks!

@Chriscbr
Copy link
Contributor
Chriscbr commented Feb 7, 2023

It would be pretty cool if we could reuse if / else / elif in the expression position (like Rust and Swift allows) since IMO it's slightly more readable than the archaic ?: ternary. See this Swift proposal for more details: https://github.com/apple/swift-evolution/blob/main/proposals/0380-if-switch-expressions.md. What do others think?

@yoav-steinberg
Copy link
Collaborator

I like the idea of turning if statements into expressions (like rust). I also think that given the extensive use of the ? char when dealing with optionals we might run into grammar challenges or just confusion because ? is usually related to optionals:
let x = (a ?? b?) ? c?.y : 1; // Explain this

@staycoolcall911 staycoolcall911 changed the title Add ternaries to the spec (b ? c : d) Add ternaries (b ? c : d) Mar 23, 2023
@staycoolcall911 staycoolcall911 added 📜 lang-spec-impl Appears in the language spec roadmap 🛠️ compiler Compiler labels Mar 23, 2023
@MarkMcCulloh
Copy link
Contributor

Personally I find ternaries readable and dislike if expressions. I also dislike variable shadowing though so I'm probably just a luddite ¯\(ツ)

@hasanaburayyan
Copy link
Collaborator

I agree with @MarkMcCulloh I find the if expressions to make things look very busy but thats just preference.

@github-actions
Copy link

Hi,

This issue hasn't seen activity in 60 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days.
Feel free to re-open this issue when there's an update or relevant information to be added.
Thanks!

@Chriscbr
Copy link
Contributor

The syntactic ambiguity raised by @yoav-steinberg is valid - fortunately, I think the visual similarity between expr ? ... and expr? ... should be addressed by removing the unwrap/condition expression syntax (#5942).

The "traditional" ternary syntax a ? b : c is already in a lot of languages today (C, C++, Java, JavaScript, PHP, Ruby, Swift, Perl) so I think going forward with this design makes the most sense. One of our design goals is to make Wing to feel familiar to people who have used other popular languages.

Type checking this expression can be modeled after the logic already used for type checking simple if/else statements in the compiler.

I'll mark this as a good issue if anyone wants to pick this up!

@Chriscbr Chriscbr added the good first issue Good for newcomers label May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🛠️ compiler Compiler good first issue Good for newcomers 📜 lang-spec-impl Appears in the language spec roadmap roadmap 📜 spec Requires a change in the Language/SDK spec
Projects
Status: 🤝 Backlog - handoff to owners
Status: Todo - p1
Development

No branches or pull requests

5 participants