11-12-2013

posted Nov 12, 2013, 5:40 AM by Samuel Konstantinovich   [ updated Nov 12, 2013, 5:40 AM ]
Do now: 
A. 
0. Do the problem in part B while waiting for your browser to load part B
1. Open up your sentence generator so I can see it. 
2. Make it so that when you run it, it generates 10 sentences. (call the command 10 times)
3. Post your 10 sentences on Piazza in the appropriate category. 

B. 
Trace the following function:
(define (bar L s)
   (if (null? L)
        s
        (bar (cdr L) (+ s (car L)))))
(define (foo L) 
   (bar L 0) )
(foo '(1 9 3 2)) ;ON PAPER! 

This style of recursion maintains part of the solution as a parameter.

(function p1 p2... px partial_solution) 
where p1...px are the normal parameters
the partial_solution is where you store the answer so far.
when the recursion stops, you return partial_solution instead of 

normally the recursion call looks like this:
(+ x (function rest) )
and the + x cannot finish until the next function finishes. 
This causes the expression to expand  like :
(+ 3 (+ 5 (+ 9 (+ 2 ...))))))

How is this different from the do now problem?


Comments