Parameter sets - Value Ranges

Prev Next

Parameter Sets - Simple Values

Simple parameter set values are 0, 1 or more values of any types, regardless if values, variables, expressions or subsets, embedded inside braces and separated with commas. Example: {} (empty set), { 1, a, {} } (contains 2 values and nested a empty set), and { {1,2},{3,4} } describing a nested parameter set which looks like a 2-dimensional matrix and can be used as such.

Parameter Sets - Value Ranges (Numerals)

Simple parameter sets become cumbersome when describing a sequence of incrementing values, e.g. { 1,2,3,4,5,6,7,8,9,10 }, especially much bigger ones. One way to do this is with a loop, but is cumbersome. Alternatively, value ranges can be specified. A range consists of a starting value and an ending value with '..' inbetween, e.g. { 1..10 }. The increment is 1, unless a second value in the middle is specified, e.g. { 2..4..10 } to describe the 2nd value. It may be bigger (for counting up), smaller (for counting down), but not equal to the 1st value (error message occurs).

A mixup of numerals and other types inside a range specification is invalid.

  print("Start with the classic way : ");
  a[] = {};
  for (i[]=1, i[]<=10, i[]++) a[] += {i[]};
  echo(a[]);

  echo("And the easy way           : ", {1 .. 10});
  echo("Steps of 2.5               : ", {1 .. 3.5 .. 10});
  echo("Steps of -1: Right way     : ", {10 .. 9 .. 1});
  echo("Steps of -1: Wrong way     : ", {10 .. 1}); // Returns empty set
  echo("Combination of 2 ranges    : ", {2..4..10, 20..40..100} );
  echo("Build a 3x3 matrix         : ", {{11..13},{21..23},{31..33}} );
Start with the classic way : {1,2,3,4,5,6,7,8,9,10}
And the easy way           : {1,2,3,4,5,6,7,8,9,10}
Steps of 2.5               : {1,3.5,6,8.5}
Steps of -1: Right way     : {10,9,8,7,6,5,4,3,2,1}
Steps of -1: Wrong way     : {}
Combination of 2 ranges    : {2,4,6,8,10,20,40,60,80,100}
Build a 3x3 matrix         : {{11,12,13},{21,22,23},{31,32,33}}
Try it yourself: Open LAN_Features_data_types_parameter_sets_value_ranges.b4p in B4P_Examples.zip. Decompress before use.

Parameter Sets - Value Ranges (Strings)

Value ranges are also supported for strings. The string values may consist of one or more characters. The intial value, optionally second value and final values must contain strings with same number of characters and only one character in the same position changing. An exception applies if the string contains numeric digits. Here, up to 8 digits are allowed. This allows counting from smaller numbers (fewer digits) to larger numbers (more digits). Minus signs are not considered as part of numbers. A mixup of strings and other types inside a range specification is invalid.
Following exampls are invalid:
{1 .. '5'} (Type mixup)
{Option A .. option C } (1st and last characters are different)
{Option A .. Option } (final value has fewer characters),
{Option A .. Option AA} fails because final value has more characters, and
{Point -3 .. Point 3 } fails because minus sign is an extra character.
Valid examples: See below

  echo("Start simple               : ", {a..z});
  echo("Every 2nd letter           : ", {a..c..z});
  echo("1 letter in string         : ", {'Article A:' .. 'Article F:'} );
  echo("Combination of 2 ranges    : ", {2..4..10, 'Article A:' .. 'Article F:'} );
  echo("Numbers in strings         : ", {'Chapter 9:' .. 'Chapter 12:'} );
  echo("Numbers in strings         : ", {'Chapter 09:' .. 'Chapter 12:'} );
Start simple               : {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}
Every 2nd letter           : {'a','c','e','g','i','k','m','o','q','s','u','w','y'}
1 letter in string         : {'Article A:','Article B:','Article C:','Article D:','Article E:','Article F:'}
Combination of 2 ranges    : {2,4,6,8,10,'Article A:','Article B:','Article C:','Article D:','Article E:','Article F:'}
Numbers in strings         : {'Chapter 9:','Chapter 10:','Chapter 11:','Chapter 12:'}
Numbers in strings         : {'Chapter 09:','Chapter 10:','Chapter 11:','Chapter 12:'}
Try it yourself: Open LAN_Features_data_types_parameter_sets_value_ranges_01.b4p in B4P_Examples.zip. Decompress before use.

Parameter Sets - Value Ranges (Dates)

Unique to Beyodn4P, Value ranges are also supported for dates and times. If the value consists of both date and time value, then the range may only be applied either on the date (with time kept unchanged) or time (with date kept unchanged).

For dates, the default increment is +1 day. For times, the default increment is +1 hour. Use the to influence the interval. Both positive and negative intervals are allowed. Time counting must not pass across midnights to cover additional days.

  echo("Dates                       : ", { date(30.03.2016) .. date(02.04.2016) });
  echo("Dates, 3 day intervals      : ", { date(01.04.2016) .. date(04.04.2016) .. date(10.04.2016) });
  echo("Today to yesterday - bad    : ", { date(today) .. date(today)-1 });
  echo("Today to yesterday - OK     : ", { date(today) .. date(today)-1 .. date(today)-1 });
  echo("Times, 1 hour intervals     : ", { time("12:15:00")..time("15:15:00") });
  echo("Times, 5 minute intervals   : ", { time("12:15:00")..time("12:20:00")..time("12:30:00") });
  echo("30 seconds back - bad       : ", { time(now) .. time(now)-30/(24*60*60) });
  echo("30 seconds back, 10s interv.: ", { time(now) .. time(now)-10/(24*60*60) .. time(now)-30/(24*60*60) });
  echo("Changing dates              : ", { date("05.06.2016 10:00:00")..date("08.06.2016 10:00:00") });
  echo("Changing times, seconds     : ", { date("05.06.2016 10:00:00")..date("05.06.2016 10:00:01")..date("05.06.2016 10:00:03") });

Dates                       : {'2016-03-30','2016-03-31','2016-04-01','2016-04-02'}
Dates, 3 day intervals      : {'2016-04-01','2016-04-04','2016-04-07','2016-04-10'}
Today to yesterday - bad    : {}
Today to yesterday - OK     : {'2024-07-14','2024-07-13'}
Times, 1 hour intervals     : {'12:15:00','01:15:00','02:15:00','03:15:00'}
Times, 5 minute intervals   : {'12:15:00','12:20:00','12:25:00','12:30:00'}
30 seconds back - bad       : {}
30 seconds back, 10s interv.: {'10:07:45','10:07:35','10:07:25','10:07:15'}
Changing dates              : {'2016-06-05 10:00:00','2016-06-06 10:00:00','2016-06-07 10:00:00','2016-06-08 10:00:00'}
Changing times, seconds     : {'2016-06-05 10:00:00','2016-06-05 10:00:01','2016-06-05 10:00:02','2016-06-05 10:00:03'}
Try it yourself: Open LAN_Features_data_types_parameter_sets_value_ranges_02.b4p in B4P_Examples.zip. Decompress before use.