Exercise 1.22. Most Lisp implementations include a primitive called runtime that returns an integer that specifies the amount of time the system has been running (measured, for example, in microseconds). The following timed-prime-test procedure, when called with an integer n , prints n and checks to see if n is prime. If n is prime, the procedure prints three asterisks followed by the amount of time used in performing the test. (define (timed-prime-test n) (newline) (display n) (start-prime-test n (runtime))) (define (start-prime-test n start-time) (if (prime? n) (report-prime (- (runtime) start-time)))) (define (report-prime elapsed-time) (display " *** ") (display elapsed-time)) Using this procedure, ...
Exercise 3.45. Louis Reasoner thinks our bank-account system is unnecessarily complex and error-prone now that deposits and withdrawals aren't automatically serialized. He suggests that make-account-and-serializer should have exported the serializer (for use by such procedures as serialized-exchange ) in addition to (rather than instead of) using it to serialize accounts and deposits as make-account did. He proposes to redefine accounts as follows: (define (make-account-and-serializer balance) (define (withdraw amount) (if (>= balance amount) (begin (set! balance (- balance amount)) balance) "Insufficient funds")) (define (deposit amoun...
Exercise 3.78. Figure 3.35: Signal-flow diagram for the solution to a second-order linear differential equation. Consider the problem of designing a signal-processing system to study the homogeneous second-order linear differential equation The output stream, modeling y , is generated by a network that contains a loop. This is because the value of d 2 y / d t 2 depends upon the values of y and d y / d t and both of these are determined by integrating d 2 y / d t 2 . The diagram we would like to encode is shown in figure 3.35 . Write a procedure solve-2nd that takes as arguments the constants a , b , and d t and the initial values y 0 and d y 0 for y and d y / d t and generates the stream of successive values of y . SOLUTION The code and tests are here . The plots are pasted below and also available here ....
Comments
Post a Comment