Hi Org List, I'd like to submit a patch so that all bash babel arrays are indexed. Are there cons to this that I'm not seeing? It might break some existing code that expects associative arrays. Could this be a breaking change that is included in Org 5.0? I'd like to check on the likely acceptance of such a patch before I take the time to code it.
Currently Org Babel uses associative arrays for multi-column bash :var inputs, and indexed arrays if single column. Put differently, for 1D tables the array is indexed [0,1,...,n] and for 2D arrays it is indexed using the first column. Example at the bottom of this email. There are some drawbacks to this method: 1) It drops rows if the first column is not unique (I have tables where the first three columns make a unique index from "|year|month|day|value") and 2) associative arrays do not maintain order, so the code cannot rely on the order of the rows (see example below where "foo2,bar2" order is swapped). If all arrays are indexed, these two issues would go away. -k. #+NAME: tbl1D | foo1 | | bar1 | #+NAME: tbl2D | foo2 | 42 | | bar2 | 24 | #+NAME: print_tbl #+BEGIN_SRC bash :var tbl=tbl1D for key in "${!tbl[@]}"; do row=${tbl[$key]} echo $key $row done #+END_SRC #+CALL: print_tbl(tbl=tbl1D) #+RESULTS: | 0 | foo1 | | 1 | bar1 | #+CALL: print_tbl(tbl=tbl2D) #+RESULTS: | bar2 | 24 | | foo2 | 42 |