Akash21
Akash21

Reputation: 39

I'm trying to create a function in scheme which sums numbers from 1 to n but I keep getting error messages

I recently started learning Scheme and I'm trying to create this recursive function which finds the number from 0 to the given parameter.

Below is my code:

(define (summer n)
((if (positive? n) (+ n (summer(- n 1))) 0)))

Upvotes: 0

Views: 38

Answers (1)

law-of-fives
law-of-fives

Reputation: 643

You simply have too many parentheses.

(define (summer n)
  (if (positive? n)
      (+ n (summer(- n 1)))
      0))

Upvotes: 2

Related Questions