CSC151.02 2003F, Class 40: Variable-Arity Procedures Admin: * Labs due Thursday * What does Sam mean by "remove" * Yay! Reese is back. In honor (or is that horror) of her return, I've changed the topic of today's class * It's 11/11. Overview: * Terminology * About variable-arity procedures * Writing your own variable-arity procedures * Lab * Reflection Lab Writeups: * Intersection: remove, complement, member (or member?), right-section Definition: "Arity": A property of a procedure. In particular, the number of parameters the procedure expects. "Binary procedure": A procedure whose arity is 2; A procedure that expects two parameters. "Unary procedure": A procedure whose arity is 1; A procedure that expects one parameter. "Variable-Arity procedure": A procedure that may operate with different numbers of parameters What variable-arity procedures do you know? * list: 0 or more parameters * string-append, append: 0 or more * +: 0 or more parameters * map: 2 or more parameters (the first is a function, the remaining parameters are lists) * display: one or two * -: 0? No. 1 or 2? No. 1 or more? Yes. * One argument: Negate the argument * Two or more: Subtract all but the first from the first We've been using lots of these variable-arity procedures, so we may want to write them. We write them using variants of lambda. (define foo (lambda stuff ...)) If you don't put parens around the parameters, you get the parameters as a list. Another interesting variant: one or more (define bar (lambda (stuff . morestuff) ...)) stuff is the first parameter morestuff is a list of all remaining parameters (except stuff) (define baz (lambda (a b . stuff) ...)) a is the first param b is the second stuff is a list of all the remaining params DO THE LAB For Thursday: Read "Tail Recursion"