CSC151.02 2003F, Class 9: Procedures Admin: * Moment of silence * A gift * I'll probably discuss your Web sites on Monday. * Read Conditionals * Homework: Lab writeup on today's lab. Topics: * Followup questions on Tuesdays's lab * Writing your own procedures * Laboratory What can you tell me about the following procedures? * quotient, remainder, modulo * Divides two integers and gives you the whole portion of the result * Remainder gives the rest of the result * Sam writes unitelligble math gobbledygook: y = qx + r s.t r < x * modulo does something different: Gives you a result on the modulus number scale Normal number line: -2__-1__0___1___2___3___4___5 Modulus 4 num line: 2___3___0___1___2___3___0___1___2___3___0___1___2__3 A "positive" remainder, in some sense. * max: Given one or more reals, gives the highest min: Given one or more reals, gives the lowest * Why not complex parameters? * Hard to write * If we treat them as vectors, use magnitude of vector * Some people compare by using the sum of the parts * There are other metrics * What procedures take 0 or more parameters? * list * + * * (times) * numerator, denominator * One real parameter > (numerator 2.4 1.2) . numerator: expects 1 argument, given 2: 2.4 1.2 > (numerator 3/4) 3 > (denominator 3/4) 4 > (numerator 4/8) 1 > (numerator 1.2) 5404319552844595.0 > (denominator 1.2) 4503599627370496.0 > (numerator #e1.2) 6 > (denominator #e1.2) * gcd, lcm * Great common divisor: Given one or more numbers, The largest number that evenly divides all the numbers * Lowest common multiple: If given more than one integer, The smallest positive integer that is evenly divisible by all the integers. If given exactly one integer, that integer. ---------------------------------------- Writing Your Own Procedures * You must choose exactly how many parameters you have (define NAME_OF_PROCEDURE (lambda LIST_OF_PARAMETERS EXPRESSION)) For example (define square (lambda (x) (* x x))) (define addreese (lambda (lst) (cons 'reese lst))) You are now ready for the lab!