Quantcast
Channel: How to add in a list in racket - Stack Overflow
Viewing all articles
Browse latest Browse all 7

How to add in a list in racket

$
0
0
For example:• (sum empty) ⇒ 0• (sum (list 1 2 3)) ⇒ 6• (sum (list 1 (list 2) 3 (list 4 5))) ⇒ 15

What I have so Far. It calculates the sum of the numbers in the list. The test passes for some of the examples. However, I don't Know how to add if it did consist of numbers, such as example 3.

(define (sum lloi)  (cond    [(empty? lloi) 0]    [else (+ (first lloi) (sum (rest lloi)))]))

Viewing all articles
Browse latest Browse all 7

Latest Images

Trending Articles





Latest Images