<div>Some days ago I came across Williams&#39; <a href="http://planet.racket-lang.org/display.ss?package=describe.plt&amp;owner=williams">describe</a> collection from PLaneT. That&#39;s pretty awesome.</div><div>And coincidentally came <a href="http://projecteuler.net/index.php?section=problems&amp;id=17">this problem</a> from Project Euler.</div>

<div><br></div><div>Then I wrote two solutions, and I was wondering which one of them have the best style, according to Racket&#39;s philosophy.</div><div><br></div><div><div>#lang racket</div><div>(require (planet williams/describe/describe))</div>

<div><br></div><div>(define N 1000)</div><div><br></div><div>;; Solution 1</div><div>(apply + (build-list N (compose string-length integer-&gt;string add1)))</div><div><br></div><div>;; Solution 2</div><div>(for/fold ([sum 0])</div>

<div>  ([i (in-range 1 (add1 N))])</div><div>  (+ sum ((compose string-length integer-&gt;string) i)))</div></div><div><br></div><div><br></div><div><br></div><div>For me solution 1 is compact, however it allocates the list without need (which gives out of memory error for large N). Solution 2 is more memory efficient, but more verbose.</div>

<div><br></div><div><br></div><div>BTW what&#39;s the recommended way to check &quot;per-function&quot; memory usage? There&#39;s an <a href="http://groups.google.com/group/racket-users/browse_thread/thread/d48ce09209a5aea4">unanswered question about memory profiling</a> in the mailing list, and I could find my way out searching PLaneT, the docs and the mailing list archive.</div>

<div><br></div><div><br></div><div>[]&#39;s</div><br clear="all">Rodolfo Carvalho<br>