SCIP 1.18
(defun squre(x)
(* x x))
(defun even?(x)
(= (mod x 2) 0))
(defun doublef(x)
(+ x x))
(defun half(x)
(/ x 2))
;ex1.18
;a*b
;1, b=0 temp
;2, b is even (iter product*2 b/2 temp)
;3, b is odd (iter product b-1 temp+product)
;
(defun multiply-iterative(a b)
(defun multiply-iter(product count temp)
(progn (format t "~% ~d ~d ~d" product count temp )
(cond ( (= count 0) temp)
( (even? count) (multiply-iter (* 2 product)
(/ count 2)
temp))
( (multiply-iter product
(- count 1)
(+ temp product))) )))
(multiply-iter a b 0))
Edit in Emacs with Slime and Steel Bank Common Lisp.