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

Allow stepped integer parameters. #2240

Merged
merged 5 commits into from May 12, 2017

Conversation

hjoliver
Copy link
Member

@hjoliver hjoliver commented Apr 11, 2017

[cylc]
   [[parameters]]
        idx = 1..9^2  # 1, 3, 5, 7, 9

[UPDATE: syntax changed to 1..9..2 below]

@hjoliver hjoliver added this to the next release milestone Apr 11, 2017
@hjoliver hjoliver self-assigned this Apr 11, 2017
@hjoliver
Copy link
Member Author

hjoliver commented May 5, 2017

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...

@@ -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
Copy link
Contributor

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.)

Copy link
Member Author

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Member Author

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?

Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Member

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.

@@ -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+))?')
Copy link
Contributor

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?

Copy link
Member

@oliver-sanders oliver-sanders left a 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.

@matthewrmshin
Copy link
Contributor

Hi @hjoliver Are you happy to settle for the START..END..STEP syntax?

@hjoliver
Copy link
Member Author

@matthewrmshin - yes I'm happy, just crazy busy this week (sorry). (have started the big review btw, but not finished...)

@matthewrmshin
Copy link
Contributor

(I'll merge after the CI test passes.)

@matthewrmshin matthewrmshin merged commit 0be1ed1 into cylc:master May 12, 2017
@hjoliver hjoliver deleted the params-integer-step branch October 18, 2017 22:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants