I'm a Scheme newbie and trying to make sense of my homework. I've a function I made earlier called duplicate, and it looks like this:
( DEFINE ( duplicate lis )
(IF (NULL? lis) '())
((CONS (CAR lis) (CONS (CAR lis) (duplicate (CDR lis))))
))
A typical i/o from this would be i: (duplicate '(1 2 3 4)) o: (1 1 2 2 3 3 4 4), so basicly it duplicates everything in the list. Moving on: Now I'm supposed to make a function that's called comp. It's supposed to be built like this:
(DEFINE (comp f g) (lambda (x) (f (g (x))))
Where I could input '(1 2 3 4) and it would return (1 1 4 4 9 9 16 16)
so f = duplicate and g = lambda. I know lambda should probably look like this:
(lambda (x) (* x x))
But here's where the problem starts, I've already spent several hours on this, and as you can see not made much progress.
Any help would be appreciated. Best regards.
comp()you can't have(x);xis not a function: it should be(g x)instead of(g(x))2. To usecompwithlambda, your (lambda(x..)) needs to work on a list to be compatible withdouble; as it is, thislambdaonly works on a single number. That is hard to do without loop.