Hacker News new | ask | show | jobs
by roelschroeven 1081 days ago
But that can't be tail call optimized, so you should write something like

    sum(n, acc=0) = n == 0 ? acc : sum(n-1, acc+1)
To me that negates much of the 'declarative' character of a functional style. I don't feel it's really clearer than the imperative for-loop

    acc = 0
    for i = 1 to n
        acc += 1