Confusion about prod()

I edited just now to explain the function signatures. Re: lambdas, I guess they’re just called anonymous functions, I was thinking of Python.

What I’m doing here is passing in an anonymous function and looping over a list of x values in order to build a polynomial. Specifically these are Newton’s Divided Difference polynomials, and poly is just the helper function.

Here’s the relevant code:

# Newton's divided difference polynomial
function ndd(; data)
    n = length(data)
    # initialize nxn matrix
    m = zeros(Float64, n, n)
    
    # unzips list of (x,y) coords into separate lists
    # set first column of DD matrix to f(x) for x in xx
    xx, m[:,1] = map(y -> map(x -> x[y], data), 1:2)

    # generate lower triangular NDD matrix
    for i in 2:n
        for j in 2:i
            m[i,j] = (m[i,j-1]-m[i-1,j-1])/(xx[i]-xx[i-j+1])
        end
    end
    
    # return an anonymous function in x: 
    # sum the diagonal entries as coefficients
    # on the generated Newton polynomial
    return x-> sum(m[i,i]*poly(i, x, xx) for i in 1:n)
end

It needs a lot of work, as there’s a lot of silly things happening, but this was a past homework assignment that I’m just trying to clean up.