On Sun, Jul 24, 2011 at 09:44, Stephan Houben <steph...@planet.nl> wrote:
> Hi Rodolfo, > Hi Stephan, Thanks for your considerations. > > I think solution 2 is generally preferred, and > solution 1 would be considered a slight abuse of apply. > Why is that an abuse? Is it an abuse just in this specific case, or in general? I thought of (apply + a-list) as a way of expressing something like (sum a-list), being "sum" an hypothetical function that takes a list and return the sum of its elements. > > On the other hand, I find that summing comes up sufficiently > often to deserve its own compact syntax, so I propose: > > ;; Solution 3 > (require (planet "mathsymbols.rkt" ("stephanh" "mathsymbols.plt" 1 0))) > > (Σ ([i (in-range 1 (add1 N))]) > (string-length (integer->string i))) > I like it. It looks neat and runs reasonably fast (and I imagine the memory usage is on pair with the other solutions, except for #1). I've added this to my script, now with 6 different implementations, line after line more messy :| (that's throw-away code anyway...) For now it's my preferred solution considering aesthetics, semantics and performance. Thanks. Rodolfo Carvalho
_________________________________________________ For list-related administrative tasks: http://lists.racket-lang.org/listinfo/users