0
votes

I'm now using racket to build the function that return the list of animal's name corresponding to the given animal list. But there comes a problem.

(define (name-pets l)
    (cond
        [(eq? "dog" first(l)) (append 'happy (name-pets (rest (l))))]
        [(eq? "cat" first(l)) (append 'smart (name-pets (rest (l))))]
        [(eq? "pig" first(l)) (append 'pinky (name-pets (rest (l))))]
        [else (append 'unnamed (name-pets (rest (l))))]))
(name-pets (list "pig" "cat" "dog" "dolphin"))

And when I ran the code,

application: not a procedure; expected a procedure that can be applied to arguments
given: '("pig" "cat" "dog" "dolphin")
arguments...: [none]

What is the problem?

1

1 Answers

0
votes

Change first(l) to (first l) and (rest (l)) to (rest l). Note that you can't insert extra parentheses in Racket. The syntax (l) means call l, but since l is a list and not a function, you run into problems.