Held Wednesday, March 14, 2001
Today we consider techniques for defining local procedures, procedures that are only available to select other procedures.
let. I hope to have them ready for tomorrow.
count-odd-rollsquestion. This person, like many of you, reflected on the possibility of using
roll-dieas a helper. Unfortunately, the solution does much more work than it needs to
(define count-odd-rolls (lambda (n) ; If you roll 0 dice, then you can have 0 odd numbers. (if (= n 0) 0 ; Otherwise ... (let ((dice (roll-dice n))) ; Roll some dice ; See if the first one is odd (if (odd? (car dice)) ; If so, count it and then do the rest (+ 1 (count-odd-rolls (- n 1))) ; Otherwise, just cound the remaining odd ; rolls (count-odd-rolls (- n 1)))))))
roll-diceto print a short note each time it is called.
let*works for recursive procedures.
Friday, 12 January 2001
Wednesday, 14 March 2001
Disclaimer: I usually create these pages on the fly. This means that they are rarely proofread and may contain bad grammar and incorrect details. It also means that I may update them regularly (see the history for more details). Feel free to contact me with any suggestions for changes.
This page was generated by Siteweaver on Wed May 5 12:15:02 2004.
This page may be found at
You may validate this page's HTML.
The source was last modified Wed Mar 14 08:17:13 2001.