CSC151.01 2006S, Class 46: Variable-Arity Procedures Admin: * Time for questions on HW 16. * Reading for tomorrow (objects). (Please wait until afternoon.) Overview: * Definition of arity. * Why have variable-arity procedures. * How to write variable-arity procedures. * Lab. /Terms/ * "The number of parameters a procedure has": arity * "The arity of square root is 1" * "The arity of vector-ref is 2" (the vector and the position) * "A procedure of arity 3 is substring" * Add "-ary" to somethi8ng like a number * zeroary * unary * binary * trinary * arity 4 /Variable-Arity Procedures/ * Some procedures have multiple arities * + (plus) can take 0, 1, 2, 10, as many as you want * - (minus) can take 1 (negate) 2 or more (subtract all but first from first), but not 0 * Others: * * (multiply): 0 or more * / (divide): 1 (reciprocal) 2 or more (divide first by all the rest) * list: 0 or more * vector: 0 more more * string-append: 0 or more * append: 0 or more /Writing Our Own/ * Zero or more (lambda params body) * One or more (lambda (first . rest) body) * Two or more (lambda (first second . rest) body) /Lab!/ (define acronym (lambda words (list->string (map (lambda (word) (string-ref word 0)) words)))) (define acronym (lambda words (list->string (map (r-s string-ref 0) words))))