Skip to content

Syntax Proposals / Generative arrays/dict

Is your feature request related to a problem? Please describe. In link with #9 and #10, it is sometimes needed to list a subset of another set for simple reuse. For example, lets say I have a CSV file in the following format:

name1, value1, name2, value2, name3, value3, ...

If I import this file in GBOML, I'll have to work each time with a condition 2*i+1 to access values, for example. A syntax to produce arrays from other structures, on the fly, would be beneficial.

Describe the solution you'd like I propose the concept of "generated expressions", which is simply an expression with a for loop.

generated_expression: expression loop

Generated expression are already something quite common in other parts of GBOML (contraints/objective use them everywhere).

The semantic are as follows:

  • If an array (see #9) contains a generated expression, then at resolving time we would generate all the expression and include them in the array. Let's do an example:
      x = {2*i for i in [0:5]} 
    would be translated into
      x = {0, 2, 4, 6, 8, 10}
  • We can authorize arrays/dict to contain more than one generated expressions and/or to interleave them with other things:
      x = {2*i for i in [0:5], 1000, 2*i for i in [0:5]}
    would be translated into
      x = {0, 2, 4, 6, 8, 10, 1000, 0, 2, 4, 6, 8, 10}
    

The syntax for a dictionnary would be as follows:

   x = {2*i: i+1 for i in [0:5], "a": "b"}

which would be translated to

   x = {0: 1, 2:2, 4:3, 6:4, 8:5, 10:6, "a": "b"}

Note that this generalizes the syntax currently used for sum(_ for _ in [_:_]), which behaves in the same way.

Edited by Derval Guillaume
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information