Nevvea
Nevvea

Reputation: 67

Scheme function doesn't work when 'car'ed from a list

So I'm trying to apply only the first function of a function list to a list of arguments. I noticed this would work:

    (apply + '(1 2))

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

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

Any idea why? Doesn't (car '(+ -)) return a +? And actually that's what I get in the error message:

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

I feel like the answer to this might be super simple and I would feel stupid, but I've been trying to add and take out parentheses for a while but I still don't get it...Please help! Thanks in advance!

Upvotes: 3

Views: 99

Answers (1)

leppie
leppie

Reputation: 117360

'(+ -) is a list of symbols which is effectively the same as (list '+ '-).

What you want is a list of procedures:

(list + -)

Upvotes: 6

Related Questions