Junior — Senior
Creating a function with support for currying
livecode
Task condition
You need to write a function that supports consecutive calls with one argument and returns the current sum only when called without arguments. The function's behavior should match the following examples:
sum() == 0
sum(1)() == 1
sum(1)(4)() == 5
sum(5)(2)(2)() == 9
The function should correctly handle any number of nested calls, accumulating the passed numbers and returning their sum when called without parameters.