![]() |
![]() |
|
home—lectures—exams—hws—breeze (snow day)
Due Dec.07 (Fri) at the start of class.
Submit:
a hardcopy with
the first question's fill-in-the-blanks1
and the additional tests for N6 (since N4),
and the additional/changed function(s) for N6 (since N4).
Since N6 is an extension N5, you don't need any code or test-cases for N5 different from N6.
We continue to build on the language implementation started in hw07. You can implement this homework in either Java or Racket. Please indicate in your submitted file, what sections of code are udpated and what is unchanged from hw09/hw09-soln. You don't need to turn in any hardcopy of unchanged-code (but submit a fully-working copy in the drop-box).
(Scope, 15pts)
The racket form
(define x 5) (set! x (* 2 x)) ; the variable x is now bound to 10. |
1. (define a 10) 2. (define b 20) 3. (define make-foo 4. (let {[b 30]} 5. (lambda () ; ← make-foo is bound to this function. 6. (let {[c 40]} 7. (lambda (cmd) ; ← make-foo returns this function as its answer. 8. (let {[d 50]} 9. (cond [(symbol=? cmd 'incA) (set! a (+ a 1))] 10. [(symbol=? cmd 'incB) (set! b (+ b 1))] 11. [(symbol=? cmd 'incC) (set! c (+ c 1))] 12. [(symbol=? cmd 'incD) (set! d (+ d 1))] 13. [(symbol=? cmd 'get-all) (list a b c d)]))))))) |
(set! a 500) (set! b 600) (define counter1 (make-foo)) (define counter2 (make-foo)) (define counter3 (make-foo)) (counter1 'get-all) ; >>> TODO: (list ) (counter1 'incA) (counter1 'incB) (counter1 'incC) (counter1 'incD) (counter1 'get-all) ; >>> TODO: (list ) (counter2 'get-all) ; >>> TODO: (list ) |
(20pts) Complete N5, as per hw07—Interpreting N: project.
1If you want to have your fill-in-the-blank questions as a comment in your code file, that's fine — just have them at the top of the first page you turn in, so I see it immediately. ↩
home—lectures—exams—hws—breeze (snow day)
©2012, Ian Barland, Radford University Last modified 2012.Dec.02 (Sun) |
Please mail any suggestions (incl. typos, broken links) to ibarland ![]() |
![]() |