4 ms·
The LOOP solution could be written using DOLIST or DO forms too (likewise built-in): (defun calculate (instructions) (let ((result 0)) (dolist (e i
by pooyamo 3mo ago
The LOOP solution could be written using DOLIST or DO forms too (likewise built-in):
(defun calculate (instructions)
(let ((result 0))
(dolist (e instructions result)
(destructuring-bind (operator operand) e
(setf result
(case operator
(add (+ result operand))
(multiply (* result operand))
(subtract (- result operand))))))))
(defun calculate (instructions)
(do ((result 0))
((null instructions) result)
(destructuring-bind (operator operand) (pop instructions)
(setf result
(case operator
(add (+ result operand))
(multiply (* result operand))
(subtract (- result operand)))))))