public Variable atIndexList(DynamicList index_list) { // copy itself Variable sub_element = new DynamicList(getValue()); foreach (Integer index in index_list.getValue()) { // get next element sub_element = (sub_element as DynamicList).atIndex(index); } // return final result return(sub_element); }
/// <summary> /// Get the value at the index in a list /// </summary> /// <param name="list_expr"> The list</param> /// <param name="index_list_expr"> The index</param> /// <returns></returns> private static Variable listAtFunction(Expression list_expr, Expression index_list_expr) { // extract list Variable list_var = list_expr.evaluate(); Debugging.assert(list_var is DynamicList); // TypeError DynamicList list = list_var as DynamicList; // extract index Variable index_list_var = index_list_expr.evaluate(); Debugging.assert(index_list_var is DynamicList); // TypeError DynamicList index_list = index_list_var as DynamicList; /*// test run ? * if (Global.getSetting("test mode")) * { * // function to add to index dict * void addToIndexList(string var_name) * { * if (var_name == "") return; * var index_var_name_list = (List<string>) Global.test_values["index values"]; * // variable name already in index dict ? * if (index_var_name_list.Contains(var_name)) return; * // add to index dict * index_var_name_list.Add(var_name); * } * }*/ // access at index Variable result = list.atIndexList(index_list); // trace list if (!list_var.isTraced()) { return(result); } Tracer.printTrace("list_at last event: " + list_var.tracer.peekEvent()); handleValueFunctionTracing("list_at", list, new dynamic[] { index_list.getValue() }); // trace index //Tracer.printTrace("tmp list at ", index_list.toString()); /*var index_list_var_value = index_list_var.getValue(); * for (int i = 0; i < index_list_var_value.Count; i++) * { * Variable index_var = index_list_var_value[i]; * var numeric_index = (NumericalValue) index_var; * NumericalValue source = numeric_index.getTracedSource(); * if (source == null) * { * Tracer.printTrace("tmp index without source var"); * numeric_index.setName($"comp /{i}/"); * list.tracer.update(new Event(new Alteration("tmp_list_at", numeric_index, * numeric_index.getValue(), new[] {list.getName(), index_list.getValue()}, * mode:"index"))); * continue; * } * * Tracer.printTrace("Traced source var: " + source.getName()); * numeric_index.setName($"comp /{i}/"); * list.tracer.update(new Event(new Alteration("tmp_list_at", numeric_index, * numeric_index.getValue(), new[] {list.getName(), index_list.getValue()}, * mode:"index"))); * }*/ return(result); }