0

I have a list in this format, (+ 2 3). Where the first character is a math symbol that can be applied to the other two elements. I cannot seem to get it to do the operations. I want to return 5 for the previous example.

I've tried this:

((car '(+ 2 3)) (cadr '(+ 2 3)) (caddr '(+ 2 3)))

But I get the following error:

application: not a procedure.

melwil
  • 2,547
  • 1
  • 19
  • 34
dest
  • 69
  • 1
  • 9

1 Answers1

1

You can try eval , should do it straight away:

> (eval '(+ 1 2))
3

If you'd like to have more control over the input, write a funcion:

(define solver
     (lambda (exp_lst)
             (let ((op (car exp_lst))
                   (vars (cdr exp_lst)))
              #do/check stuff
             (apply (eval op) vars)
)))
Eggcellentos
  • 1,570
  • 1
  • 18
  • 25