I want to make a function with “memory”, that only modifies the second argument if the first satisfies certain conditions and otherwise returns the same second argument. Both arguments should be “scalar”/only one scalar value is of interest.
In the solution below
b is not modified if
0 <= a <= 1:
function foo(a, b) if a < 0 b = 1 elseif a > 1 b = 0 end b end b =  foo(0.5, b) foo(1.5, b) foo(-0.5, b)
However, it seems clumsy to use a vector only to act as a container. Any good suggestions for a better solution?