Define a function sum, which takes two numbers, or two real functions, and returns their sum. E.g.
(sum 1 2) => 3
((sum cos exp) 0) => 2
I get that for the sum of two numbers the code would be the following:
(define sum (lambda (x y)
(+ x y)))
But what would be the code for the two real functions...? How would I do this? can anyone please help?
Also how would I do this:
Define a function
sum-allwhich works likesum, but works on a list of numbers or a list of functions. Assume the list contains at least one element. E.g.(sum-all (list 1 2 3)) => 6 ((sum-all (list cos sin exp)) 0) => 2
Note: this is not homework... I was going through a past midterm.
((sum cos exp) 0)to worksumwould need to be(lambda (f g) (lambda (v) (+ (f v) (g v))))to combine this with the other sum function(lambda (a b) (+ a b))you'd need to look at the types of the arguments and decide what to do with them. - Dan D.(define sum (lambda (x y) (+ x y)))is nearly equivalent to(define sum +). - Christoffer Hammarström