-
Notifications
You must be signed in to change notification settings - Fork 308
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
please support range syntax #326
Comments
This is actually not a bad idea. @d5 any thoughts on this? I wouldn't mind making some time for this. |
Sure. Can we discuss more details on the syntax first? |
Just looking up how this is done in other languages now but from a cursory overview I’m leaning towards the python style |
Haha. Yeah I like that! |
So the new builtin function will return an array of ints? |
Yes, an array of ints from 0 to a |
I think if it's just a built-in, function, and we already have enough APIs to implement it ourselves, the built-in bracket syntax support would be much easier to read for line expression scenarios |
I’m not sure I agree that brackets add something to expressiveness that a builtin It’s also IMO an unnecessary addition to the syntax which I’d rather leave as is unless there’s a really good reason to change it. Additionally, the bracket syntax is limited. It doesn’t easily allow you to add a step size. |
I use Tengo in a database sharding proxy project, it allows me to simplify some definitions, such as database node definitions: DS_1, DS_2, DS_3. If I have this syntax I can say DS_{[1..3]}, this makes the configuration file simple and easy to read. If it's a function: DS_{rang(1,3)}, I don't think it's as clear so. In my project, the more complex This expression is in the configuration file, so avoiding the function is easier to read. |
BTW: Because missing this syntax, I implemented a "range" function on my project, and this issue comes from a feeling that the configuration file is ugly. |
I suppose we can achieve something like that with @d5 thoughts? |
Yeah I agree with @geseq. It's a nice-to-have feature and not worth all the extra efforts. |
In that case @endink would you be willing to create a PR with your implementation of the range function? If not I’ll work on implementing it. |
@geseq Alright, these days are the Chinese New Years. If need, I can provide this PR after this holiday . |
@endink any luck with the PR? If you prefer I can work on this as well. |
@geseq The Chinese New Year ends on February 27th, wait two days for me to do it or you do it. I'm fine with it anyway.You decide |
Oh no worries! I didn’t know that. Take your time. |
@geseq Pr has been commited, and the specific usage can be seen in unit tests range(start, stop[, step]) usage examples:
BTW: I don't think a single parameter is a good syntax because its semantics are not clear, so my implementation doesn't include it ( like: range(5) ----> [0,1,2,3,4] ) |
* builtin range function #326 * change empty range logic * fix unit test error message * fix github env (#329) * fix ErrInvalidRangeStep comments * fix github env (#329) * builtin range function #326 * change empty range logic * fix unit test error message * fix ErrInvalidRangeStep comments * fix lint Co-authored-by: geseq <[email protected]>
array define : [1,2,3,4,5]
range define: [1..5]
This syntax is useful in an inline environment to effectively shorten script lengths.
Some language support it like kotlin, groovy...etc
The text was updated successfully, but these errors were encountered: