CSC151 2007S, Class 48: Variable-Arity Procedures Admin: * A favor - Can a few of you try http://language.grinnell.edu/names/ and let me know by early this afternoon what you think about it? * Due: HW 16 * Exam 3 distributed. * EC for Monday's Alumna Scholar talk by Dr. Nesbitt. * EC for any softball (here) or baseball games (Illinois) that happen to happen this weekend. and for Rugby (here) Overview: * Definition of arity. * Why have variable-arity procedures. * How to write variable-arity procedures. * Lab. /Definition of arity/ * "arity" - a way to say "the number of parameters a procedure has" * sqrt - arity is 1 * tally - arity is 2 (tally pred? lst) * + - arity is zero or more (NO MATTER WHAT THE READING SAID, AND I DENY WRITING IT OR EDITING IT) * - - arity is one or more * "variable arity" - formal term for "or more" /Why have variable-arity procedures?/ * For some operations, like +, it gets tedious to write a lot of pluses (and twice as many parens) * For some operations, it is necessary * We can't write list without variable-arity * The current display is incredibly annoying, and always gives us errors the first time we try to display multiple values * The "hack" to deal with this - put 'em in a list * Philosophy: If the language designers need it, so do programmers * Paden can now write "padens-much-better-display" (disp) /How to write variable-arity procedures/ * Tradition (lambda (params) body) - fixed arity * First technique (lambda params body) - variable arity, 0 or more When you call the procedure, params are passed as a list * Second technique (lambda (first . rest) body) - variable arity, 1 or more * Variants on second (lambda (first second . rest) body) - variable arity, 2 or more /Lab/