| While experimenting, I thought I'd take the definition of foldl from SICP and implement it in Arc. My first draft was: (def foldl (op initial sequence)
(def iter (result rest)
(if (no rest)
result
(iter (op result (car rest))
(cdr rest))))
(iter initial sequence))
arc> (foldl + 1 '(2 3 4))
10
but that redefines iter each time. What is the proper way to do this in Arc while keeping the structure of the original? I know I can just use a recursive function and pass the op, but the point is to create a self-referencing lambda in Arc. |