IS IT A BUG???
Author Message
IS IT A BUG???

hi,
I should display the time taken by the execution of teh procedure "rec-expt" in the format h:m:s:ms
So here the code
-----------------------------------
(define (clock x)
(define (find-hours)
(quotient x 3600000))
(define (rest-from-hours)
(remainder x 3600000))
(define (find-minutes)
(quotient (rest-from-hours) 60000))
(define (rest-from-minutes)
(remainder x 60000))
(define (find-seconds)
(quotient (rest-from-minutes) 1000))
(define (rest-from-seconds)
(remainder (rest-from-minutes) 1000))
(define (find-ms)
(rest-from-seconds) )

(display (find-hours))
(display ":")
(display (find-minutes))
(display ":")
(display (find-seconds))
(display ":")
(display (find-ms))
(newline))

(define (rec-expt x y)
(define (expt y)
(if (= y 0)
1
(* x (expt (- y 1)))))
(if (>= y 0)
(expt y)
(/ 1 (expt (abs y)))))

(clock (time (rec-expt 1 3000)))
---------------------------------------------------
So why the execution of (clock (time (rec-expt 1 3000))) returns 0:0:0:1 and not  0:0:0:50 since the execution time is equal to 50 ms.?
It seems that  the function "clock is applied to the result of "(rec-expt 1 3000)" which is actually equal to 1 and not applied to the execution time " (time (rec-expt 1 3000))" What is wrong???

Tue, 07 May 2002 03:00:00 GMT
IS IT A BUG???

Quote:

>So why the execution of (clock (time (rec-expt 1 3000))) returns 0:0:0:1
>and not  0:0:0:50 since the execution time is equal to 50 ms.?
>It seems that  the function "clock is applied to the result of
>"(rec-expt 1 3000)" which is actually equal to 1 and not applied to the
>execution time " (time (rec-expt 1 3000))" What is wrong???

I can't find a "time" macro in R5RS.  I suggest you read the documentation
of your implementation carefully to find out how this macro works.

If it's like Common Lisp's TIME macro, (time <expression>) is supposed to
return what <expression> returns, as well as printing out information about
how long it took.  This allows you to wrap (time ...) around existing
expressions in a program, e.g. if you have

(* (func1 ...) (func2 ...))

you can change it to

(* (time (func1 ...)) (time (func2 ...)))

and the multiplication will receive the same parameters that it would have
without the time diagnostics.

--