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
Allow stepped integer parameters. #2240
Conversation
I can't recall if I had a reason for not assigning reviews on this 3 weeks ago 😬 - looks good to go, including documentation and tests. See what you think... |
doc/src/cylc-user-guide/cug.tex
Outdated
@@ -4379,6 +4379,7 @@ \subsubsection{Parameter Expansion} | |||
[[parameters]] | |||
obs = ship, buoy, plane | |||
run = 1..5 # 1, 2, 3, 4, 5 | |||
idx = 1..9^2 # 1, 3, 5, 7, 9 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a matter of interest, did you borrow this syntax from any language? (In both Perl and Python, the ^
operator appears to be the bitwise XOR operator.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, thought that might be a point of contention. We can't use comma, obviously.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact, the ^
operator appears to be the bitwise XOR operator in most languages derived from C. The only other thing I can think of is to use ..
again in a ternary way, START..END[..STEP]
, e.g. 1..9..2
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think @matthewrmshin's solution makes sense as it's in line with what you'd expect from something like python's range(start, end, step=1)
function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe... IMO ..
is intuitive syntax for a range, but ideally we'd have something else for step. What about 1..9;2
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or how about 1:9:2?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I could go for the colon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ..
operator is a well known operator in various languages including Perl and Ruby, but none of them have thought about steps.
I don't like :
or ;
for the same reason as ^
- both are well known operators that mean something else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1..9..2
mimics bash, 1:9:2
is python slice style...I like either. Making up our own seems confusing possibly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 for START..END..STEP
. In python's slice syntax the end-point is excluded i.e. 1:9:2 = 1, 3, 5, 7
, whereas in bash this is inclusive i.e. 1..9..2 = 1, 3, 5, 7, 9
.
lib/cylc/cfgspec/suite.py
Outdated
@@ -36,7 +36,7 @@ | |||
from cylc.network import PRIVILEGE_LEVELS | |||
|
|||
|
|||
REC_PARAM_INT_RANGE = re.compile('(\d+)\.\.(\d+)') | |||
REC_PARAM_INT_RANGE = re.compile('(\d+)\.\.(\d+)(\^(\d+))?') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose you can do:
REC_PARAM_INT_RANGE = re.compile('(\d+)\.\.(\d+)(?:\^(\d+))?')
to avoid capturing the 3rd bracket?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Same comment from me about making the "junk" regex group non-capturing.
Hi @hjoliver Are you happy to settle for the |
@matthewrmshin - yes I'm happy, just crazy busy this week (sorry). (have started the big review btw, but not finished...) |
(I'll merge after the CI test passes.) |
[UPDATE: syntax changed to
1..9..2
below]