[racket] Calculating cumulative sum of the list

From: Pierpaolo Bernardi (olopierpa at gmail.com)
Date: Thu Jan 22 09:17:30 EST 2015

Here's a straightforward way:

(define (cumulative-sum list)
  (let loop ([list list] [acc 0])
    (if (null? list)
      list
      (let ([s (+ (first list) acc)])
        (cons s (loop (rest list) s))))))


On Thu, Jan 22, 2015 at 2:53 PM, Alexandr M <rus314 at gmail.com> wrote:
> Hello,
>
> I am trying to replicate functionality of this code in Python:
>
> https://gist.github.com/m-blog/22b7c5d31b3839ffba50#file-cumsum-py
>
> in Racket without usage of any libraries.
>
> What would the most optimal / concise way to do it in Racket?
>
> Thank you.
>
> --
> Best regards,
> Alex
>
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users
>

Posted on the users mailing list.