- Notifications
You must be signed in to change notification settings - Fork1.5k
Variadics syntax#4735
-
Hi everybody! After watching "How Designing Carbon C++ Interop Taught me About C++ Variadics & Bound Members - Chandler Carruth" variadics First of all apologies for potential misunderstandings since I could not get the examples from slides working on godbolt. There are few issues here that make syntax weird for me:
I have some ideas what would be nicer syntax but don't want to mention them since I know too little about language grammar, i.e. what options are available without making parsing a nightmare. |
BetaWas this translation helpful?Give feedback.
All reactions
Replies: 1 comment 4 replies
-
No problem, and yeah, this isn't yet implemented.
FWIW, I do understand this confusion, but I'm not sure how we can address it. Most of the variadics approaches I've seen suffer from this, and all I really know to do is document and teach it so people don't accidentally fall into the wrong mental model.
We have talked about requiring more parentheses to help reduce confusion here:
Yeah, we're just trying to find the right balance. We've seen in C++ a ton of reasons why havingsome syntactic marker for the expanded entity clarifies things, and the best syntax we saw for it came from Swift (huge props there). We thought we could minimize the syntactic weight of the whole construct by taking C++'s We could look at other balances, but I think here too it would be useful to get a bit more code written in Carbon before we spend a lot more time trying to tweak the exact syntactic balance. What we have seems reasonable solid and teachable, and so our current priority is to get more implemented and get code written using this. We should be able to then revisit some of these purely syntactic questions pretty easily based on feedback and user experience and any new ideas that folks have. |
BetaWas this translation helpful?Give feedback.
All reactions
👍 1
-
Thank you for reading and replying. I agree that there needs to be more feedback before making changes, this was just one user initial impression report. I fully understand that Swift user X might like it, Py user Y might want If you give another talk related to this(even if it not a full talk, i.e. lightning talk) would be nice to see potential changes and more complicated examples, I will write using C++ terminology since that is my primary language:
P.S. not related to Carbon itself, but for me style of slides in this video was quite nice, arrows really made it easy to follow. |
BetaWas this translation helpful?Give feedback.
All reactions
-
If you're interested in a deeper dive into Carbon variadics,this talk may be of interest (but note that it uses slightly different notation and terminology, because it's a little older). Plus of course there's thelanguage proposal anddesign doc. Both the talk and the docs have examples of packs where each element has the same type ( As for your cartesian-product-with-delimiter example, there are a couple of problems. First, the signature of the function would need to be something like The other problem is that we don't have a way to write the body (or return type) of a cartesian-product function, because we don't support nesting pack expansions. We're open to allowing that in the future, but it raises some difficult design questions, particularly about the ergonomics of the feature, so we'd need to have some clear, practical motivating use cases to evaluate the solution against. Seehere for a little more about that. |
BetaWas this translation helpful?Give feedback.
All reactions
👍 1👀 1
-
Very interesting, nice design to use Again nothing you need to focus on now, I fully agree with Chander policy to first get some more feedback, but would be nice to keep this in mind for the future. When this is on godbolt I will try to play around a bit and see if I can implement in usercode Once again thank you for the responses, if you know when this will approximately land on godbolt please let me know. |
BetaWas this translation helpful?Give feedback.
All reactions
-
@libbooze You may find this issue and the linked doc interesting:#5093 |
BetaWas this translation helpful?Give feedback.
All reactions
👍 1