0

Hey I'm having trouble thinking about this and would like some help.

In Scheme if I'm given a list of functions (list square - double) I need to make a function that will encompass the list

For example

(let (f (co (list square - double))))  where co is the function name that combines

would be the same as

(square (- (double n))) where n is some number
So you can do the following
(f 2) => (16) 

(define (co functions) (lambda (n) (? functions)))

I'm not sure where to go from the ?. I know if you map it you end up getting the functions applied to the number but output as a list so it would be '(4 -2 4).

Any ideas would be appreciated

1 Answer 1

1

Hopefully it's not a homework.

> (define double (lambda (n) (* n 2)))
> (define square (lambda (n) (* n n)))
> (set! fs (list square - double))
> (define co
    (lambda (functions n)
      (cond 
        ((null? functions) n)
        (else ((car functions) (co (cdr functions) n))))))
> (co fs 6)
144
> (co fs 4)
64
> (co fs 2)
16
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.