[DGD] Referencing an array of variable depth

Michael McKiel crashnbrn71 at yahoo.ca
Mon Mar 1 18:23:33 CET 2004


 --- Robert Forshaw <iouswuoibev at hotmail.com> wrote: 
...[snip]...
> I can't see any clean way to reference the sub-arrays, even if the 
> extend_current_action is informed of the depth. There are two possible but 
> undesirable ways I can see to do it:
> 
> 1) Build a string containing the expression I want to perform on the
> arrays. 
> I.e.
> 
> string * expressions;
> string expression;
> int count;
> 
> expressions = allocate(depth);
> 
> expressions = action_queue[0];
> for(count = 0; count < depth; count++)
> {
>     expressions[count] = expression + "[INTERVAL] = time;";
>     expression[count] += "[SUB_ACTION_QUEUE][0];
> }
> 
> ------------------
> 
> There's a glaring flaw in this solution though, namely that there is no 
> built in way to turn a string into an expression (as far as I'm aware). The
> 
> only way to do it is to write it into a seperate file and run that, but
> that 
> won't work when trying to reference global variables of a particular
> object.
> 
> 2) Do a long and contrived switch statement checking for all the possible 
> values of 'depth' and then executing the appropriate expression. i.e.
> 
> switch(depth)
> {
>     case 0:
>         action_queue[0][INTERVAL] = time;
>     break;
>     case 1:
>         action_queue[0][INTERVAL] = time;
>         action_queue[0][SUB_ACTION_QUEUE][0][INTERVAL] = time;
>     break;
> /* aaaand so on... */
> 
> Which is unsightly to say the least. There must be a more efficient
> solution 
> I've overlooked, surely?

Wouldn't a mapping work? If every action can be sub_action'ed then every
further element of the mapping would be the sub_action of the previous action
and you could indice it based on numbers.

mapping action_queue;

action_queue = ([ ]);

action_queue += ([ 1 : ({ some_array }) ]);
/* have another action to tack onto so */
action_queue += ([ 2 : ({ another_arr }) ]);
/* etc */

yer map_sizeof(action_queue) will return 2. 
So the size of yer map will always be the last sub_action...
then you can fetch yer map_indices, and/or map_values as needed.

Just ma 2cents, seeing as no reply yet ;)



______________________________________________________________________ 
Post your free ad now! http://personals.yahoo.ca
_________________________________________________________________
List config page:  http://list.imaginary.com/mailman/listinfo/dgd



More information about the DGD mailing list