CSC 151: Extra Session (Thursday, 4 Sept. 2014) =============================================== Overview * You ask questions. * I give long rambling answers. * You ask for clarification. * I attempt to clarify. * We do it all over again (stopping when we run out of questions or out of time) What should we submit for the labs? * Your answers to the questions, fairly briefly. * Cut-and-paste code. * Type your reflection. Why can't I get the image to show up on the reading for tomorrow? * Ignore the error message at the bottom. * Images don't show up until you use `image-show`. What if I want to see the full circle? (define d2 (hshift-drawing 50 (vshift-drawing 50 d1))) What is this strange `(provide (all-defined out))` incantation? * Model: We have some definitions in one file and we're trying to use them in another file. * Experience suggests that we only want to reveal some of those definitions to the the "client" * `(export ...)` says which definitions get exported * `(export (all-defined out))` says "export everything I've defined; don't make me retype" Extra 1 on yesterday's lab asks us to round a number to the hundredth place. How do we do that? * I'd prefer not to give a full answer because it's on the homework. * What might be helpful? * round (or truncate, or floor, or ceiling) * Would it be helpful to move the decimal place? How can we see what's defined? * The reference links *should* lead to useful references. (They don't always, so let me know when links are broken.) Will you ask us some questions so that we can check our knowledge? * Four mechanisms for dropping decimal portion: round, truncate, floor, and ceiling. * When do round and truncate give the same value? * When the portion after the decimal point is below .5 * When do round and truncate give different values? * When the portion after the decimal point is .5 or above * Or is it the other way around? * Observation: * Slightly different behavior for negative numbers * Also seemingly inconsistent behavior (round 2.5) -> 2.0 (round 3.5) -> 4.0 * Is it that there is a hidden approximation? * Experiment suggests no * Further experiments: Rounds .5 toward even * When do floor and truncate give the same value? When do floor and truncate give different values? * Think about it on your own * Reminder: What are the key components of an algorithm? * Variables * Typing? You need to input information, and variables represent information * "today's eboard" names the random thoughts Sam is recording * Parameters * question - the input to the "Sam Rambles" algorithm * Conditionals * Student: If you understand, nod. If you don't understand, frown or ask for clarification. * Repetition * Repeat (Accept question, Give answer) until we run out of time. * Subroutine/Procedure * `define` in all of the Scheme code Sam typed * "answer question" encoded in Sam's head * "choose a student to call on" * "typing" * Sequencing * questions should normally come before answers * Some set of built-in operations * typing * Fill in the following table val -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 (mod val 5) 2 3 4 0 1 2 3 4 0 1 2 3 4 0 1 2 (rem.. val 5) -3 -2 -1 0 -4 -3 -2 -1 0 * Why might you ever want the `mod` operation? * Maybe while we're counting, we also want to do some sort of cycle. * How might you explain the `mod` operation to someone who didn't understand it? * "Math on a clock" - E.g., if there are five hours in a day, and Corey works for 7 hours and starts at 2, what time is Corey done? * For positive numbers, it's the same as the remainder. * For negative numbers, it's more complicated. (take the remainder and add the modulus/divisor) * On the negative side of the number line, the mod approaches the number from the right, the remainder from the left? (Sam did not phrase this well.)