CSC151 2010S, Class 51: Project Assessment: Algorithms Overview: * Questions on the exam * Debriefing from yesterday. * Students discuss programming techniques. Admin: * Since you'll be working on the exam, there is no reading for Friday. * Yes, you are expected to show up for class next week. (and this week) * EC for Convo tomorrow. * EC for CS Table Friday. * EC for Belly Dancing Sunday at 1:30. * EC for Student Art Salon * Saturday's events Questions on the exam? Question on Problem 4 (average-v2 (1 2 3)) => (kernel 1 1 (2 3)) => (kernel _ _ _) (average-v3 (1 2 3) => (... (numbers-info (1 2 3)) ...) => (... (let ((results (numbers-info (2 3))) ..)) ...) Can you go over returning a procedure? Example: ;;; Procedure: ;;; make-log-function ;;; Parameters: ;;; k, an integer ;;; Purpose: ;;; Build a function that computes log_k(n) ;;; Produces: ;;; log_k, a function from reals to reals ;;; Preconditions: ;;; [No additional] ;;; Postconditions: ;;; (expt k (log_k n)) = n for all positive real n (define make-log-function (lambda (k) (lambda (n) (/ (log n) (log k))))) > (define log2 (make-log-function 2)) > (log2 2) 1.0 > (log2 4) 2.0 > (log2 8) 3.0 Generalization: (define function-that-returns-a-function (lambda (parameters) (lambda (other-parameters) ...))) Other possibilities (define make-log-function (lambda (k) (let ((log_k (lambda (n) (/ (log n) (log k))))) log_k))) If you're returning a recursive function, you'll probably use the pattern (define make-function (lambda (params) (letrec ((recursive-function (lambda (...) ...))) recursive-function))) But ... neither problem 9 nor problem 10 requires a recursive function. * 10 has a not-very concise explicitly recursive solution and a much more consise solution (w/o explicit recursion) How do I know when I've reached a leaf in problem 5? Presumably, your tree recursion procedure has the framework (cond ((pair? tree) (RECURSE-ON-BOTH-HALVES-AND-COMBINE)) ((number? tree) (BASE-CASE tree)) (else (error "Not a tree: " tree)))a Do we have to write error messages in all of our code? * No * Programming by contract: You can assume that people meet your preconditions.