[racket] Calculating cumulative sum of the list
Well, there is always the amazing math library. But somehow, the author
of `math/base` forgot to include a `sums` function!
There *is* a `flvector-sums` in `math/flonum`, which operates only on
flonums. If you can believe this, the documentation for that function
even *gives example code* for computing cumulative sums!
Stupid git.
Neil ⊥
On 01/22/2015 07:35 PM, Matthias Felleisen wrote:
>
> NOTE TO EVERYONE: The OP asked for "without usage of any libraries".
> I am sure that sooner or later we will find a library so that we
> can say (require lib/cumulative) cumulative-sum.
>
>
>
> On Jan 22, 2015, at 7:16 PM, William James wrote:
>
>> Here's a way using map-accum in Gauche.
>>
>> (use gauche.collection)
>>
>> (define (cumulative-sums xs)
>> (map-accum (lambda (x sum) (values (+ x sum) (+ x sum))) 0 xs))
>>
>> (cumulative-sums '(1 3 5 7))
>> ===>
>> (1 4 9 16)
>>
>>
>> --------------------------------------------
>> On Thu, 1/22/15, Alexandr M <rus314 at gmail.com> wrote:
>>
>> Subject: [racket] Calculating cumulative sum of the list
>> To: users at racket-lang.org
>> Date: Thursday, January 22, 2015, 7:53 AM
>>
>> 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
>>
>>
>> -----Inline Attachment Follows-----
>>
>> ____________________
>> Racket Users list:
>> http://lists.racket-lang.org/users
>>
>>
>> ____________________
>> Racket Users list:
>> http://lists.racket-lang.org/users
>
> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users
>