The "Scheme" function does not work when "from the list"

So, I am trying to apply only the first function of the function list to the argument list. I noticed that this would work:

    (apply + '(1 2))

      

but if I try to apply the add function like this it doesn't work:

    (apply (car '(+ -)) '(1 2))

      

Any idea why? No (car "(+ -)) returns +? And actually this is what I get in the error message:

    application: not a procedure;
    expected a procedure that can be applied to arguments
    given: +
    arguments.:

      

It seems to me that the answer to this question could be very simple, and I would feel stupid, but I have been trying to add and pull parentheses for a while, but I still don't understand ... Please help! Thanks in advance!

+3


source to share


1 answer


'(+ -)

is a list of characters that actually matches (list '+ '-)

.

What you want is a list of procedures:



(list + -)

      

+6


source







All Articles