<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class="Apple-style-span" style="font-family: monospace; "><div><br></div><div>Hi Alexandrians,</div><div><br></div>Clojure has a function that I occasionally find useful, reductions. It's like reduce, only it returns not the last value of calling the two-arg function, but a list consisting of the first element of the input sequence, followed by the result of calling the two-arg with the first and second elements of the input sequence, then the  result of calling the two-arg function with the previous result and the third element, and so on... e.g.:</span><span class="Apple-style-span" style="font-family: monospace; "><br></span><span class="Apple-style-span" style="font-family: monospace; "><br>CL-USER> (reductions #'+ '(1 2 3 4))<br></span><div><span class="Apple-style-span" style="font-family: monospace; ">(1 3 6 10)</span></div><div><span class="Apple-style-span" style="font-family: monospace; "><br></span><span class="Apple-style-span" style="font-family: monospace; ">Here's the code. There are probably better ways to do this, but this is at least portable and simple. I think this would be a useful addition to alexandria.</span><span class="Apple-style-span" style="font-family: monospace; "><br></span><span class="Apple-style-span" style="font-family: monospace; "><br></span><span class="Apple-style-span" style="font-family: monospace; ">(defun reductions (function sequence &rest args)</span><span class="Apple-style-span" style="font-family: monospace; "><br></span><span class="Apple-style-span" style="font-family: monospace; "> (let ((l (list (first sequence))))</span><span class="Apple-style-span" style="font-family: monospace; "><br></span><span class="Apple-style-span" style="font-family: monospace; ">   (apply #'reduce</span><span class="Apple-style-span" style="font-family: monospace; "><br></span><span class="Apple-style-span" style="font-family: monospace; ">          (lambda (a b)</span><span class="Apple-style-span" style="font-family: monospace; "><br></span><span class="Apple-style-span" style="font-family: monospace; ">            (let ((val (funcall function a b)))</span><span class="Apple-style-span" style="font-family: monospace; "><br></span><span class="Apple-style-span" style="font-family: monospace; ">              (push val l)</span><span class="Apple-style-span" style="font-family: monospace; "><br></span><span class="Apple-style-span" style="font-family: monospace; ">              val))</span><span class="Apple-style-span" style="font-family: monospace; "><br></span><span class="Apple-style-span" style="font-family: monospace; ">          sequence</span><span class="Apple-style-span" style="font-family: monospace; "><br></span><span class="Apple-style-span" style="font-family: monospace; ">          args)</span><span class="Apple-style-span" style="font-family: monospace; "><br></span><span class="Apple-style-span" style="font-family: monospace; ">   (nreverse l)))</span><span class="Apple-style-span" style="font-family: monospace; "><br></span><span class="Apple-style-span" style="font-family: monospace; "><br></span></div><div><span class="Apple-style-span" style="font-family: monospace; ">thanks,</span></div><div><span class="Apple-style-span" style="font-family: monospace; "><br></span></div><div><span class="Apple-style-span" style="font-family: monospace; ">Cyrus</span></div><div><span class="Apple-style-span" style="font-family: monospace; "><br></span></div></body></html>