We are going to get some practice using set! and set-structure!. Our examples will use the following structure types:
(define-struct posn (x y)) (define-struct counter (name value))Thus, we'll use set-posn-x! and set-posn-y!, etc., in addition to set!.
As a reminder,
(set! v expr) changes the value of the variable/placeholder v to be the result of evaluating the expression expr.
(set-posn-x! posn expr), for example, changes the value stored in the x component of a posn to be the result of evaluating expr.
To do:
Develop switch* : list-of-symbol-or-number -> void, which initializes a variable switch-state to #f, and then toggles it between the two boolean values for each symbol it encounters. (Note: As in the previous examples, you should use a helper function to do the toggling.)
Develop factorial-count! : natnum -> number, which computes the factorial of its argument. It also keeps track of how many times the user has called in function, using the variable factorial-count. It does not count any recursive calls, e.g.,
> (factorial-count! 3) 6 > factorial-count 1 > (factorial-count! 5) 120 > factorial-count 2
Develop posn+! : posn posn -> void which changes the fields of the first argument so that, after this call, the first posn will be the sum of the two arguments.
Develop move-all! : list-of-posn posn -> void, which adds the second argument to each of the posns in the list.
Develop count! : symbol list-of-counter -> void, which increments the value of the counter named by the symbol. If the symbol isn't the name of any of the counters, ignore it.
Develop count*! : list-of-symbol list-of-counter -> void, which increments the values of the corresponding counters, for each of the symbols.