# [racket] section 11.5 from htdp

 From: Krzysztof Adamczyk (mr.k.adamczyk at gmail.com) Date: Sat May 28 17:27:25 EDT 2011 Previous message: [racket] section 11.5 from htdp Next message: [racket] section 11.5 from htdp Messages sorted by: [date] [thread] [subject] [author]

```The template is easy:

(define (exponent n x)
(cond [(zero? n) ...]
[else ... (sub1 n) ...]

and this, along with the hint from the book, leads very quickly to

(define (exponent n x)
(cond [(zero? n) 1]
[else (* (exponent (sub1 n) x) x)]))

It works perfectly with inexact numbers, but when I change " * " to my
multiply (which is very similar to the above exponent), it falls in an
unending loop. Should I redefine my multiply function and write it for
inexact numbers somehow? Or is the exponent wrong and my "is easy" and
"leads very quickly" approach is not the right one?

On 28 May 2011 21:30, Matthias Felleisen <matthias at ccs.neu.edu> wrote:
>
> A natural number is one of:
>  -- 0
>  -- one more than n for some natural number n
> Now create a template. Then fill the gaps.
>
>
> On May 28, 2011, at 2:50 PM, Krzysztof Adamczyk wrote:
>
> I am having some difficulties with section 11.5 from htdp. I'm of course not the first one encountering such problems:
>
> http://lists.racket-lang.org/users/archive/2008-November/028325.html
>
> but the above thread doesn't help in any way - Mr. Felleisen confirms that one shouldn't assume that x is a natural number. But in his next post he says that the function multiply from previous exercises should be used. Am I missing or misunderstanding something? Is it possible to multiply x by x n times with my multiply function when it needs both arguments to be natural numbers? My first idea was to use a different function, say multiply-by-inexact, which uses the + operator like multiply-by-pi, but it still needs one natural argument to stop recursion. In which direction should I go to solve this? My exponent function works for natural numbers, but I don't want to miss anything important while going through this textbook.
>
> Krzysztof
> _________________________________________________