← Back to context

Comment by ted_dunning

1 month ago

Broadcasting is a great thing, but the author of this article missed the most important example of a language that handles higher order funcions, as well as broadcast and array operations as well.

That language is Julia.

The approach in the article layers an inefficient interpreter in a slow interpreted language. The result is going to be terse (and nearly unreadable) but glacially slow. Julia, otoh, is a high performance language.

An example of this performance with higher order functions is this implementation of cubic splines in 7 lines of readable code. The idea is to implement interpolation between points and functions and then define first, second and third order splines in that many lines of code. This isn't quite as terse as it would be in APL, but it has the virtue of compiling into code that runs as fast as a native C implementation.

``` import Base.+, Base., Base./

+(f, g) = x -> f(x) + g(x) (t::Number, g) = x -> t * g(x)

interpolate(a, b) = t -> (1.0-t)a + tb b1(p1, p2) = interpolate(p1, p2) b2(p1, p2, p3) = interpolate(b1(p1, p2), b1(p2, p3)) b3(p1, p2, p3, p4) = interpolate(b2(p1, p2, p3), b2(p2, p3, p4)) ```

See https://discourse.julialang.org/t/seven-lines-of-julia-examp...