-1

The function applyToAll is suppose to take in a function and a List, then take the car of the list and apply each element to the fuction.

This is what I have worked out so far:

(define applyToAll(lambda (f L)
                (cond
                  ((null? L)       '())
                  (#t              (cons (L) (applyToAll f(car L))))
                  )))

I'm not sure what I am doing wrong. A fuction call would look like

(applyToAll  (lambda (n) (* n n))    '(1 2 3) )  

and it would return

(1 4 9)

Instead it returns: function call: expected a function after the open parenthesis, but received (list 1 2 3)

Any help as to why my code is not working?

Thanks

1 Answers1

0

It sounds like you are trying to implement map.

The error you are getting is because you are calling a list as though it's a function (lst1)

( ) this means function call in scheme

You are making the same mistake here:

 (#t              (cons (L) (applyToAll f(car L))))

the right way to apply is:

(function arg0 arg1 ... argn)

You need to apply f to each element in the list like so:

(cons (f (car L)) (applyToAll f (cdr L))))

OR just use map:

(map proc lst ...+)

gl

Eggcellentos
  • 1,570
  • 1
  • 18
  • 25