Proposal
It would be extremely convenient to allow numeric arrays to be specified with a range and step. I propose the following syntactic sugar
Ranges can be specified as an element within an array or as a _bare_ range. Bare ranges are specified without brackets.
It may also be handy to permit date types as the start and end value.
Examples
1...3 -> [1, 2, 3]
3...1 -> [3, 2, 1]
[1...3, 10...15] -> [1, 2, 3, 10, 11, 12, 13, 14, 15]
[1:3] -> [1, 2, 3]
[2:6:2] -> [2, 4, 6]
[1:0:-.2] -> [1.0, 0.8, 0.6, 0.4, 0.2, 0.0]
Motivation
Creating an array of a large sequence can be tedious and error-prone to type in. Programming languages geared towards numeric processing like Python, Matlab, and Julia offer built in range operators which are VERY useful.
Possible use cases include:
Three counter-arguments:
@TheElectronWill I understand your concerns about the language becoming overly complicated; but I find minimal to be a somewhat arbitrary distinction. The most minimal format would only allow a single value per line. No types, no key names, no nested tables or arrays of tables, no nothing.
I think that adding ranges would enhance the clarity of TOML files and be generally useful in configuration settings. To me, declaring an array as:
key = [8001...8010]
is much easier to read and write than:
key = [8001,8002,8003,8004,8005,8006,8007,8008,8009,8010]
As the number of values increase in the array the better chance that I accidentally forget a comma by accident.
I tested this feature out in my own implementation of TOML and it only added 4 lines of additional code and no meaningful degradation of parse performance (at least as instruments measures it in Swift)
I work in the scientific community and a feature like this would be tremendously valuable because we are always creating configuration files that control how complex simulations are run. These configurations frequently require the specification of ranges of values. We can just model this as three keys:
value_start = 10
value_end = 300
value_step = 5
and do the parsing in application code but I find the proposed syntax to be a lot simpler.
@jdfergason if you want a one-liner, you could have a spec like this as well
value_min_max_step = [10, 300, 5]
One way to think about minimalism is to see if something can already be accomplished with the current feature set without undue consternation. In this case, ranges can be stated explicitly in an array, or in cases where applications expect a lot of large range scenarios, they can accept something like this:
key1 = 8000 # single value
key2 = [8000, 8001] # multiple values in standard array
key3 = { min = 8000, max = 9000 } # range spec using inline tables, default step = 1
key4 = { min = 8000, max = 9000, step = 10 } # range with custom step
As such, I think ranges are overly complex for TOML's current flavor of minimalism.
Most helpful comment
@jdfergason if you want a one-liner, you could have a spec like this as well