angelofdeath
angelofdeath

Reputation: 103

What is wrong with scheme code?

i am trying to write a scheme program which will take a list of marks as input and gives the output as a list of the grades.

i got this far , .. i dunno whats wrong i get an error the object () passed as the first argument to cdr is not the correct type ....

here is the code

(define (grades list1)
  (cons (cond ((= (car list1) 100) 'S)
              ((= (car list1) 90) 'A)) 
        (cons (grades (cdr list1)) '())))

Upvotes: 0

Views: 2548

Answers (2)

Dota2
Dota2

Reputation: 474

(define (grades list1)
  (cond((null? list1) `())
       (else(cons (cond ((= (car list1) 100) 'S)
                        ((= (car list1) 90) 'A)) 
                  (grades (cdr list1))))))

Upvotes: 0

hmakholm left over Monica
hmakholm left over Monica

Reputation: 23342

You're missing a base case for your recursion. How do you want your grades function to behave when the argument is an empty list? This requires an outer cond that tests is the list is empty and returns something appropriate when it is.

Upvotes: 5

Related Questions