Still waaay too imperative, how about this:
func [1,2,3,4,5] => [2,4,6,8,10] //Calculation inferred by compiler.
console.log (func [6,7,8,9,10]) //=> [12,14,16,18,20]
func [1,2,3,4,5] => [2,4,6,8,10] //Calculation inferred by compiler.
console.log (func [6,7,8,9,10]) //=> [12,14,16,18,20]
double xs => [xs[0] * 2, ..., xs[xs.length - 1] * 2]
map f xs => [f(xs[0]), ..., f(xs[xs.length - 1])]
sum xs => xs[0] + ... + xs[xs.length - 1]
foldl f z xs => f(f(..., f(z, xs[0])), xs[xs.length - 1])
foldr f z xs => f(xs[0], f(..., f(xs[xs.length - 1], z)))I'm playing around with a tool for building touch gestures visually, and I have some problems that look a bit like that (want to infer a function from some examples) but I don't yet know how.
If you are talking paths generated from touch gestures there is some research on that topic.
here is such psuedo code foo(x) { if (x <= 5) { x * 2 } else { x } } foo1(x) { if (x <= 6) { x * 2 } else { x+1 } } foo1(x) { if (x <= 7) { x * 2 } else { x+2 } }