Syntax Proposals / Dictionnaries
Is your feature request related to a problem? Please describe. Currently GBOML can only receive data in the form of single-line CSV files. This imposes most modelers (me included) to preprocess other file formats, such as JSON, to transform them to CSV, losing valuable information ("what is config[4]? ah yeah it's "capex" in that JSON file") and costing dev time. Some data is given in the form of matrices (aka multi-line csvs...)...
This proposal aims to allow storing the content of a JSON file in GBOML. We need dictionnaries for that.
Describe the solution you'd like I propose a simple extension of the language, where a dictionnary can be composed like this:
dict: "{" _separated_list{dict_entry, ","} "}"
dict_entry: dict_key ":" _dict_value
_dict_value: expression | STRING | array
dict_key: STRING | expression
To give an example of such valid dict:
d = {
"a": 2,
x: {2, 22, 3}
}
The semantics of this must be carefully designed. I propose the following:
- If an expression is used as key, its evaluated value is actually used as key instead
- It is forbidden to reuse twice the same key inside a given dictionnary. Doing so (even implicitly after evaluation) raises an error.
- Alternatively, the last usage of a key can supersede others
- Nodes/hyperedges can be used as key, and comparison works by strict equality
Accessing an entry of a dictionnary would be done via a natural extension of the current array-indexing mecanism:
d["a"]
d[x]