The code below keeps throwing the following error:
caught ERROR:
illegal function call
(LET ((SOLUTION 'NIL) (FIRST 0) (SECOND 0))
(DOLIST (EL LST)
(IF (NUMBERP EL)
(PUSH EL SOLUTION)
((SETF #) (SETF #) (PUSH # SOLUTION))))
(CAR SOLUTION))
Can anyone see why? Syntactically I can't see anything wrong with it. Note: I'm using sbcl.
My code:
(defun evalpostfix (lst)
(let ((solution '())
(first 0)
(second 0))
(dolist (el lst)
(if (numberp el) ;if
(push el solution) ;then
((setf second (pop solution)) ;else
(setf first (pop solution))
(push (funcall el first second) solution))))
(car solution)))
Indeed, in order to group several forms together, use the special operator
progn
.You can make a step futher and group consequtive
setf
calls together:((setf second (pop solution))
- two opening parentheses? Why? The syntax forIF
with an else form is:A form cannot begin with two parentheses - there is only one exception:
((lambda (x) (+ x 1)) 2)
.If you want to group more than one expression use something like
(progn a b c ... z)
.