4 ms·
Instead of Crema's int i = 0 int values[] = [6, 3, 8, 7, 2, 1, 4, 9, 0, 5] foreach (values as dummy) { int_print(values[i]) i = i + 1
by tromp 11y ago
Instead of Crema's
int i = 0
int values[] = [6, 3, 8, 7, 2, 1, 4, 9, 0, 5]
foreach (values as dummy) {
int_print(values[i])
i = i + 1
}
it would be more straightforward to define loops over array indexing ranges, as in
foreach (int i indexing values) {
int_print(values[i])
}
- adrusi 11y agoIt would seem that you could implement that abstraction within the language def int int_indexing(int values[])[] { int i = 0 int result[] = list_create(list_length(values)) foreach (values as dummy) { result[i] = i i = i + 1 } return result } I haven't tested this, and I had to look in the source code to find the list_create function from the standard library. Of course, since the language lacks type parameterization, you'd need a different indexing function for each type of array.