I'm working with simple lists in Racket, and I was doing a function to sum the elements of a list.
But I would like to know if there is any simpler way to do this.
I did this function:
(define (mySum L)
(if (empty? L) 0
(+ (first L) (mySum (rest L))))
)
output:
(mySum '(1 2 3 4))
10
I wanted to know if anyone knows a simpler way to do this. I explain myself, for example: This is another function I did:
(define (myAppend L1 L2)
(if (empty? L1) L2
(cons (car L1) (myAppend (cdr L1) L2)))
)
But this function can be done more simply by doing just this:
(define (myAppend L1 L2)
(append L1 L2)
)
My problem is to know if there is a simpler way to do the sum of items in a list. Thanks