<div dir="ltr"><div>If you're using all of racket, here's a way to do it with heavy usage of higher order functions</div><div><br></div><div>#lang racket</div><div><br></div><div><div>(define (cumulative-sum xs)</div><div>  (map (curry foldl + 0)</div><div>           (build-list (length xs)</div><div>                           (compose (curry take xs)</div><div>                                            add1))))</div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jan 22, 2015 at 6:34 AM, Matthias Felleisen <span dir="ltr"><<a href="mailto:matthias@ccs.neu.edu" target="_blank">matthias@ccs.neu.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
#lang racket<br>
<br>
;; [Listof Number] -> [Listof Number]<br>
;; given (a b c ...) produce (a (+ a b) (+ a b c) ...)<br>
(define (cumulative-sum l #;"final private:" [so-far 0])<br>
  (cond<br>
    [(empty? l) '()]<br>
    [else (define next (+ so-far (first l)))<br>
          (cons next (cumulative-sum (rest l) next))]))<br>
<br>
(module+ main<br>
  (cumulative-sum '(1 2 3)))<br>
<br>
;; The comments are HtDP-style, but the optional entry parameter is not available in the teaching languages.<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
On Jan 22, 2015, at 8:53 AM, Alexandr M <<a href="mailto:rus314@gmail.com">rus314@gmail.com</a>> wrote:<br>
<br>
> Hello,<br>
><br>
> I am trying to replicate functionality of this code in Python:<br>
><br>
> <a href="https://gist.github.com/m-blog/22b7c5d31b3839ffba50#file-cumsum-py" target="_blank">https://gist.github.com/m-blog/22b7c5d31b3839ffba50#file-cumsum-py</a><br>
><br>
> in Racket without usage of any libraries.<br>
><br>
> What would the most optimal / concise way to do it in Racket?<br>
><br>
> Thank you.<br>
><br>
> --<br>
> Best regards,<br>
> Alex<br>
</div></div><div class="HOEnZb"><div class="h5">> ____________________<br>
>  Racket Users list:<br>
>  <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
<br>
<br>
____________________<br>
  Racket Users list:<br>
  <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
</div></div></blockquote></div><br></div>