-
Notifications
You must be signed in to change notification settings - Fork 775
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
Looping & Conditionals syntax spec #6
Comments
Love it... some thoughts in pseudo-random order...
Aside:
Should work when /subnets is not ambiguous???
I don't love it, but wondering if it has legs
Nit - It would be good to put a “completed” example in the “spec” so we can see the ideas come together, I kept trying that mental exercise as I was parsing this (I'm not great engineer, but I'm a good reverse engineer). |
Overall, I'm not in love with the syntax, but I do think it will work. Personally, I feel separating the condition and/or looping statement from the resource declaration helps with readability even though it might be a bit more verbose to author. The syntax feels like I'm writing a SQL query and less like authoring a programming language. Separating the syntax allows us to cover the "multi-resource" case and the single resource case with one syntax. If we ever do want to support a multi-resource syntax, then we will have two different ways to author conditions and loops.
|
The syntax for loops and conditionals builds on a plain resource declaration and I feel like we haven't truly nailed that down yet. Should we look at that first? @alex-frankel and @bmoore-msft
|
Also, should we consider a more imperative-looking but more familiar syntax for loops and conditions? Something like this, for example:
|
this is my preference, but I think the challenge with this syntax is how you reference the resource outside of the scope in which it is declared. At one point we were considering an
so to reference would you do the following?
it gets weird |
Good pt, I remember now. |
Ignoring the syntax, at a high level I feel like these are the viable options for resource-level looping/conditionals:
|
Amended spec to:
|
Putting this on hold for now as it's not going to be part of milestone 0. |
@lwang2016 just added #42 which covers his looping syntax proposal. Linking it here so everyone can see. |
Out of @shenglol's (#44) and @lwang2016's (#42 and #45), we have settled on the former for the following reasons:
|
How would I access the counter in a loop with: |
|
Discussed adding a filtering capability to the looping construct we selected previously. We settled on using the
@alex-frankel brought up a point that our resource declarations are getting long. We may need to allow the user to format them however they see fit without enforcing a specific format. Also discussed the condition syntax. There are limitations in the IL that prevent us from compiling a complex if/else construct when combined with a We have also decided that a conditional resource symbol whose condition is false will have an For example, given |
@alex-frankel, @marcre, @shenglol please add more comments if I missed anything from the meeting. |
Created #61 to update the language spec in the repo. |
Closing this as #61 was merged. |
Proposal - Looping & Conditionals
Goals
Resource-Level Looping: Spec
Example of a regular resource with no modifiers:
Conditional modifier
Example
The type assigned to the declared
<identifier>
should be<resource type> | null
. This should allow for compile time verification that the user is safely accessing the value with appropriate null checks.Looping modifier
Examples
The type assigned to the declared
<identifier>
should be an array of the resource being declared.<loop_identifier>
will be assigned access to the item in the current iteration of the loop.Conditional and Looping modifiers
The MVP will not support both modifiers being combined. If a user wants to combine, they always have the option to use looping with
<condition> ? <array_expression> : range(0)
to access the same functionality.Notes/Caveats
Potential future improvements not covered in this spec
n...m
Property-Level Looping: Spec
Looping
Looping uses a very similar syntax to resource-level looping, and behaves like a map function, where the value generated is written inline, and has access to the item being iterated over. This syntax generates an array of items.
This syntax is valid in any place expecting an expression.
Example
Conditionals
Conditionals use a ternary syntax. This syntax is valid in any place expecting an expression.
Notes/Caveats
a ? b : null
quick to write as either setting some value or null is a common use case.<array_expression> <value_expression>
makes the looping syntax a little hard to parse.The text was updated successfully, but these errors were encountered: