github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/docs/mkarray/special.md (about)

     1  # Special Ranges
     2  
     3  > Create arrays from ranges of dictionary terms (eg weekdays, months, seasons, etc)
     4  
     5  ## Description
     6  
     7  Unlike bash, Murex also supports some special ranges:
     8  
     9  ```  
    10  » a [mon..sun]
    11  » a [monday..sunday]
    12  » a [jan..dec]
    13  » a [january..december]
    14  » a [spring..winter]
    15  ```
    16  
    17  Please refer to [a (mkarray)](../commands/a.md) for more detailed usage of mkarray.
    18  
    19  ## Usage
    20  
    21  ```
    22  a: [start..end] -> <stdout>
    23  a: [start..end,start..end] -> <stdout>
    24  a: [start..end][start..end] -> <stdout>
    25  ```
    26  
    27  All usages also work with `ja` and `ta` as well, eg:
    28  
    29  ```
    30  ja: [start..end] -> <stdout>
    31  ta: data-type [start..end] -> <stdout>
    32  ```
    33  
    34  You can also inline arrays with the `%[]` syntax, eg:
    35  
    36  ```
    37  %[start..end]
    38  ```
    39  
    40  ## Examples
    41  
    42  ```
    43  » a [summer..winter]
    44  summer
    45  autumn
    46  winter
    47  ```
    48  
    49  ## Detail
    50  
    51  ### Case Sensitivity
    52  
    53  Special ranges are case aware. If the ranges are uppercase then the return will
    54  be uppercase. If the ranges are title case (capital first letter) then the
    55  return will be in title case.
    56  
    57  #### lower case
    58  
    59  ```
    60  » a [monday..wednesday]
    61  monday
    62  tuesday
    63  wednesday
    64  ```
    65  
    66  #### Title Case
    67  
    68  ```
    69  » a [Monday..Wednesday]
    70  Monday
    71  Tuesday
    72  Wednesday
    73  ```
    74  
    75  #### UPPER CASE
    76  
    77  ```
    78  » a [MONDAY..WEDNESDAY]
    79  MONDAY
    80  TUESDAY
    81  WEDNESDAY
    82  ```
    83  
    84  ### Looping vs Negative Ranges
    85  
    86  Where the special ranges differ from a regular range is they cannot
    87  cannot down. eg `a: [3..1]` would output
    88  
    89  ```
    90  » a [3..1]
    91  3
    92  2
    93  1
    94  ```
    95  
    96  however a negative range in special ranges will cycle through to the end
    97  of the range and then loop back from the start:
    98  
    99  ```
   100  » a [Thursday..Wednesday]
   101  Thursday
   102  Friday
   103  Saturday
   104  Sunday
   105  Monday
   106  Tuesday
   107  Wednesday
   108  ```
   109  
   110  This decision was made because generally with ranges of this type, you
   111  would more often prefer to cycle through values rather than iterate
   112  backwards through the list.
   113  
   114  If you did want to reverse then pipe the output into another tool:
   115  
   116  ```
   117  » a [Monday..Friday] -> mtac
   118  Friday
   119  Thursday
   120  Wednesday
   121  Tuesday
   122  Monday
   123  ```
   124  
   125  There are other UNIX tools which aren't data type aware but would work in
   126  this specific scenario:
   127  
   128  * `tac` (Linux),
   129  
   130  * `tail -r` (BSD / OS X)
   131  
   132  * `perl -e "print reverse <>"` (Multi-platform but requires Perl installed)
   133  
   134  ### Supported Dictionary Terms
   135  
   136  Below is the source for the supported dictionary terms:
   137  
   138  ```go
   139  package mkarray
   140  
   141  var mapRanges = []map[string]int{
   142  	rangeWeekdayLong,
   143  	rangeWeekdayShort,
   144  	rangeMonthLong,
   145  	rangeMonthShort,
   146  	rangeSeason,
   147  	rangeMoon,
   148  }
   149  
   150  var rangeWeekdayLong = map[string]int{
   151  	"monday":    1,
   152  	"tuesday":   2,
   153  	"wednesday": 3,
   154  	"thursday":  4,
   155  	"friday":    5,
   156  	"saturday":  6,
   157  	"sunday":    7,
   158  }
   159  
   160  var rangeWeekdayShort = map[string]int{
   161  	"mon": 1,
   162  	"tue": 2,
   163  	"wed": 3,
   164  	"thu": 4,
   165  	"fri": 5,
   166  	"sat": 6,
   167  	"sun": 7,
   168  }
   169  
   170  var rangeMonthLong = map[string]int{
   171  	"january":   1,
   172  	"february":  2,
   173  	"march":     3,
   174  	"april":     4,
   175  	"may":       5,
   176  	"june":      6,
   177  	"july":      7,
   178  	"august":    8,
   179  	"september": 9,
   180  	"october":   10,
   181  	"november":  11,
   182  	"december":  12,
   183  }
   184  
   185  var rangeMonthShort = map[string]int{
   186  	"jan": 1,
   187  	"feb": 2,
   188  	"mar": 3,
   189  	"apr": 4,
   190  	"may": 5,
   191  	"jun": 6,
   192  	"jul": 7,
   193  	"aug": 8,
   194  	"sep": 9,
   195  	"oct": 10,
   196  	"nov": 11,
   197  	"dec": 12,
   198  }
   199  
   200  var rangeSeason = map[string]int{
   201  	"spring": 1,
   202  	"summer": 2,
   203  	"autumn": 3,
   204  	"winter": 4,
   205  }
   206  
   207  var rangeMoon = map[string]int{
   208  	"new moon":        1,
   209  	"waxing crescent": 2,
   210  	"first quarter":   3,
   211  	"waxing gibbous":  4,
   212  	"full moon":       5,
   213  	"waning gibbous":  6,
   214  	"third quarter":   7,
   215  	"waning crescent": 8,
   216  }
   217  ```
   218  
   219  ## See Also
   220  
   221  * [Calendar Date Ranges](../mkarray/date.md):
   222    Create arrays of dates
   223  * [`[ ..Range ]`](../parser/range.md):
   224    Outputs a ranged subset of data from STDIN
   225  * [`[[ Element ]]`](../parser/element.md):
   226    Outputs an element from a nested structure
   227  * [`a` (mkarray)](../commands/a.md):
   228    A sophisticated yet simple way to build an array or list
   229  * [`count`](../commands/count.md):
   230    Count items in a map, list or array
   231  * [`datetime`](../commands/datetime.md):
   232    A date and/or time conversion tool (like `printf` but for date and time values)
   233  * [`ja` (mkarray)](../commands/ja.md):
   234    A sophisticated yet simply way to build a JSON array
   235  * [`mtac`](../commands/mtac.md):
   236    Reverse the order of an array
   237  * [`ta` (mkarray)](../commands/ta.md):
   238    A sophisticated yet simple way to build an array of a user defined data-type
   239  * [index](../parser/item-index.md):
   240    Outputs an element from an array, map or table
   241  
   242  <hr/>
   243  
   244  This document was generated from [builtins/core/mkarray/ranges_doc.yaml](https://github.com/lmorg/murex/blob/master/builtins/core/mkarray/ranges_doc.yaml).