I6 suggestion: functionality like Extend but for arrays?

I was poking at something today and thought that it would be really nice to have the ability to extend an array in I6, like the way tables can be continued in I7.

Given any array X, an assertion like

ExtendArray X <array_type> val1 val2 val3 ... valN;

would add those to the values in an array declaration, so for example:

Array X --> 2 4 6 8;
...
ExtendArray X --> 10 12 14;

would be equivalent to have declared only;

Array X --> 2 4 6 8 10 12 14;

It might also be nice to allow arrays declared only by size to be extended:

Array Y --> 10;
...
ExtendArray Y --> 5;

would be equivalent to:

Array Y --> 15;

The compiler would reject an ExtendArray if the array type didn’t match, or if the declaration type (i.e. size vs. list of values) wasn’t compatible. The pre-exisiting syntax for single-item lists of values for Array would also apply to ExtendArray.

The idea is to make additions to tables in the Standard Library or library extensions a little easier on authors. Would this be feasible?

The one-pass nature of the I6 compiler makes this difficult, I’m afraid. The array section of memory is constructed incrementally; the compiler assumes that every new array immediately follows the end of the last one. Retooling this to allow expanding arrays would be a big rewrite.

1 Like

On the subject of arrays I encountered a problem where I needed to declare an array of arrays.

Array g1 static string "1:9"; 
Array g2 static string "6:19"; 
Array g3 static string "6:10"; 
Array g4 static string "2:10"; 
Array g5 static string "47:2"; 
Array g6 static string "30:20"; 
Array g7 static string "7:10"; 
Array g8 static string "21:4";
Array genesis_passage --> g1 g2 g3 g4 g5 g6 g7 g8;

(note that g1-g8 are ASCII-arrays.)

It’s a bit bulky that you need to declare the temporary variables g1-g8 for this and not can declare arrays inside an array in a nested way. In Zil you would define the same as:

<GLOBAL GENESIS_PASSAGE
  <PLTABLE
    <PTABLE (STRING) "1:9">
    <PTABLE (STRING) "6:19">
    <PTABLE (STRING) "6:10">
    <PTABLE (STRING) "2:10">
    <PTABLE (STRING) "47:2">
    <PTABLE (STRING) "30:20">
    <PTABLE (STRING) "7:10">
    <PTABLE (STRING) "21:4">>>

(There is no limit on how many levels the tables can be nested.)

Unfortunately I think this also would be hard/difficult in the one-pass compiler.

2 Likes