Hi, I am learning Scheme using SCIP and R. Kent Dybvig's "The Scheme
Programming Language".
I am stuck on exercise 1.16 in Abelson and Sussman.
The task is to "design a procedure that evolves and iterative exponentiation
process that uses successive squaring".

Well, I can't seem to get it working.
The code I have tried looks something like this:
[code]
; iterative process for fast exponent
; NOT WORKING!!!

(define (expt b p)
  (exp-it b p 1))

(define (exp-it b p a)
  (cond 
    ((= p 0) a)
    ((even? p) (exp-it b (/ p 2) (* a (square b)))))
    (else (exp-it b (- p 1) (* b a)))))
[/code]

-- 
View this message in context: 
http://old.nabble.com/SICP-ex.-1.16-tp34305765p34305765.html
Sent from the Gnu - MIT Scheme - Users mailing list archive at Nabble.com.


_______________________________________________
MIT-Scheme-users mailing list
MIT-Scheme-users@gnu.org
https://lists.gnu.org/mailman/listinfo/mit-scheme-users

Reply via email to