mit-scheme-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[MIT-Scheme-users] SICP ex. 1.16


From: antiloquax
Subject: [MIT-Scheme-users] SICP ex. 1.16
Date: Thu, 16 Aug 2012 02:04:11 -0700 (PDT)

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.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]