This is a hw assignment that requires me to write a scheme function that takes a function(with two params) and a list as parameters, then returns a list where each consecutive pair of the elements of the list is replaced by the value of the function applied to these two elements.
For example - If the list has an odd number of elements, the last element is ignored. For example, (apply-to-pairs (lambda (x y) (+ x y)) '(3 9 5 8 2 4 7)) should return (12 13 6).
so far what I have got is:
(define (fn-name fn l)
(if (null? (cdr l))null
(cons
(fn((car l)(car (cdr l)))
(fn-name fn (cdr l))))))
However, im getting this error in Racket(DrRacket):
application: not a procedure;
expected a procedure that can be applied to arguments
given: 3
arguments...:
9
... and it highlights fn((car lst)(car (cdr lst)))
. I'm trying to find out how to handle the function parameter. Thanks for the help!
"application: not a procedure" site:stackoverflow.com
turns up lots of results that explain this for you: you've got extra parens.(fn ((car l) (car (cdr l))))
should be(fn (car l) (car (cdr l)))
. Generally, when you encounter an error, you'll do well to search for the exact error message. – Joshua Taylor