From jacobson@math-cs.cns.uni.edu Mon Jan 26 10:29:28 2004 Date: Mon, 26 Jan 2004 10:22:37 -0600 (CST) From: Mark Jacobson To: 810-151-04@uni.edu Subject: [810-151-04] Scheme quiz Wednesday, SumOfDigits solution... This will be posted on the class web page too. It goes without saying that your reading assigment between every class and the next class is to check out the URL: http://www.cns.uni.edu/~jacobson/scheme/ ; Sum of Digits - Monday, January 26th, 2004 ; Illustrates page 57 Integer Arithmetic in Scheme. (define sumOfDigits (lambda (number) (if (< number 10) number (+ (sumOfDigits (quotient number 10)) (modulo number 10)) ) ; **** end of the if ) ; **** end of lambda expression ) ; end of the definition I placed the ()s so it is easier to see the logic of the if statement and its two expressions: (define sumOfDigits (lambda (number) (if (< number 10) number (+ (sumOfDigits (quotient number 10)) (modulo number 10)) ) ) ) In the above, (< number 10) is the test, ---- number is the consequent, and ---------- (+ (sumOfDigits (quotient number 10)) (modulo number 10)) is the alternative. ----------- syntax: (if test consequent alternative) syntax: (if test consequent) returns: the value of consequent or alternative depending on the value of test test, consequent, and alternative are expressions. If no alternative is supplied and test evaluates to false, the result is unspecified. See you at the quiz on Wednesday. We will go over the solutions to the homework and review for the first half of the class, and have the quiz during the 2nd half of class. I will post a brief study guide or outline to the quiz later today. Much of it is here in this note! This email note is itself and excellent review for the quiz. What is illustrated? Scheme integer arithmetic (see page 57) Recursion. (if expressions and conditional logic using if) How to keep track of ()s when not in an environment like Dr. Scheme, by using a different indentation style to match them up. Your assignment that was handed back today is an excellent review for the quiz on Wednesday. Your assignment that is due on Wednesday, is an excellent review for the quiz on Wednesday. The URL http://www.cns.uni.edu/~jacobson/scheme is great review. Mark Welcome to DrScheme, version 204. > (sumOfDigits 1234) 10 > (sumOfDigits 1359) 18 > (sumOfDigits 8888) 32