Suppose I have a list
{a[1], a[2], a[3], ...}
and a function
y = f[x1, x2]
Is it possible to return a list like
{a[1], f[a[2],a[1]], f[a[3], f[a[2],a[1]]], ... ]
This may look like a little bit confusing. Actually, it just applies the function across consecutive elements in this list in order.
1st time, take a[1] and a[2] and act on a[2]:
{a[1], f[a[2], a[1]], a[3], ...}
2nd time, take a[3] and the new a[2] and act on a[3]:
{a[1], f[a[2], a[1]], f[a[3], f[a[2], a[1]]], ...}
In other words, although the problem is very similar to Span a function across several consecutive elements in a list, the order / history of the application matters.
Is there a way that it can be realized elegantly without using For loop?