CSC151, Class 39: Variable-Arity Procedures Overview: * Definition of arity. * Why write variable-arity procedures. * How to write variable-arity procedures. * Lab. Notes: * How was last night's talk? * Are there questions on the project proposal? * Reminder: Class Friday in Saints' Rest. Please arrive early if you can. We'll discuss exam 2. * Extra credit for attending cool Friday noon talk on mathematics education (even for those planning a career in the subject who probably have to attend anyway). * Thinking ahead to preregistration: Future courses in CS ---------------------------------------- Definitions: * Parameter: Something a procedure takes as input * Two ways to think about parameters: + The things in the procedure definition + The things in the procedure call (define foo (lambda (x) (+ x 2))) (foo 2) * The number of parameters a procedure expects is the "arity" of a procedure. foo has arity 1 foo is unary (define bar (lambda (x y) ...)) bar has arity 2 bar is binary What is the arity of +? + "As many as you want" 0 params: 0 Are there other procedures that take differing numbers of parameters? yes * String-append: 0 or more 0 params: Empty string * -: 1 or more Are there procedures we might want to write (or, more precisely, that you expect that I might assign) that take a variable number of parameters? Test 1: Write a markup procedure (markup "hr") "
" (markup "p" "hello") "

hello

" Interesting combinations of lists (intersect lst1 lst2 ... lstn) How to write a procedure of zero or more parameters (define proc (lambda paramlist body)) How to write a procedure of one or more parameters (define proc (lambda (firstparam . restofparams) body))