Builtin: Array Arithmetic Expressions
Now that we have support for string-based arithmetic, perhaps we might want to also implement array-based arithmetic? This issue will discuss possible syntax ideas that we could pursue.
Proposal # 1
This approach is commonly used in functional languages, so it might also be a natural fit here. Define a variable name to describe each element in the array, and then follow it with a mathematical expression to apply with each element in the array.
@[ELEMENT -> EXPR, ARRAY EXPR]
Examples
Example # 1
let array = [1 2 3]
for result in @[x -> x * x, array]
echo $result
end
Output # 1
1
4
9
Example # 2
let array = [1 2 3]
let value = 3
for result in @[x -> x * value, array]
echo $result
end
Output # 2
3
6
9