diff options
Diffstat (limited to 'ps03_evalapply')
-rw-r--r-- | ps03_evalapply/bnewbold_ps3.txt | 28 | ||||
-rw-r--r-- | ps03_evalapply/bnewbold_work.scm | 11 |
2 files changed, 9 insertions, 30 deletions
diff --git a/ps03_evalapply/bnewbold_ps3.txt b/ps03_evalapply/bnewbold_ps3.txt index 9bcaa26..6cfbb4c 100644 --- a/ps03_evalapply/bnewbold_ps3.txt +++ b/ps03_evalapply/bnewbold_ps3.txt @@ -15,6 +15,7 @@ have just asked! [see bnewbold_work.scm] + Problem 3.2 ------------------------ It would probably make more sense to have some symbols and functions as tagged @@ -29,6 +30,7 @@ character names and required registration with declare-literal-function. [see bnewbold_work.scm] + Problem 3.3 ------------------------ a. @@ -41,21 +43,7 @@ b. We have to delay the integrand call even further than kons does; fortunately we have good syntax for this now! -#| -(define (integral (integrand lazy) initial-value dt) - (define int - (kons initial-value - (add-streams (scale-stream integrand dt) - int))) - int) -; integral -(define (solve f y0 dt) - (define y (integral dy y0 dt)) - (define dy (map-stream f y)) - y) -; solve -(ref-stream (solve (lambda (x) x) 1 0.001) 1000) -; 2.716923932235896 +[see bnewbold_work.scm] Problem 3.4 @@ -63,6 +51,8 @@ Problem 3.4 a. I will answer with a quick program (see code). +[see bnewbold_work.scm] + b. CONS wants a list as it's second argument (at least most schemes, MIT/GNU seems a little looser?), (dy lazy memo) would have to get checked sooner rather than @@ -77,20 +67,20 @@ created, blocking garbage collection. Problem 3.5 ------------------------ I implemented crude profiling: after evaluating an expression, a table can be -printed out showing the number of procedure and primative calls. +printed out showing the number of procedure and primitive calls. A pair of eq-based hash tables are used to store the running call counts. Performance does seem to be negatively effected (eg (fib 12) took 10+ seconds using a very crude algorithm vs. almost instant in the top level repl), but that might just be the generic dispatch stuff. -I put in code for an enable/disable flag but i'm not sure it's even neccessary. +I put in code for an enable/disable flag but i'm not sure it's even necessary. -The most-needed-change is to print just the primative/compound procedure name +The most-needed-change is to print just the primitive/compound procedure name symbols, not their string representations. I wanted to make sure that the same procedure by different names would be counted together, but in the end it looks like a big mess. My scmutils-enabled version of MIT Scheme has a procedure-name method that does the trick, but it doesn't seem to be in the default distribution so I left it out. - +[see bnewbold_work.scm] diff --git a/ps03_evalapply/bnewbold_work.scm b/ps03_evalapply/bnewbold_work.scm index e74c65e..d968fd2 100644 --- a/ps03_evalapply/bnewbold_work.scm +++ b/ps03_evalapply/bnewbold_work.scm @@ -232,17 +232,6 @@ sandwich (define *compound-call-database* (make-eq-hash-table)) -#| -(define (clear-profile-results) - (set! PROFILING-ENABLED #f) - ( *primative-call-database* - (set! *compound-call-database* - (make-eq-hash-table)) - (set! PROFILING-ENABLED #t)) -(define cpr clear-profile-results) ; shorter -|# - - (define (print-profile-results) (set! PROFILING-ENABLED #f) (begin |