CSC151.01 2006S, Class 08: Procedure Definitions Admin: * Absent: Wood (excused), Zamora * Same week -> Same groups * Are there questions on the lab? * Are there questions on the homework? * What should I do with number? Well ... you need strings so ... * Reading for Friday: Boolean values. * EC: Osgood at 11 a.m. tomorrow. Overview: * Why define your own procedures? * How to define your own procedures. * Lab. * Reflection What are the components of an algorithm? * Basic data and operations on them * Lists, symbols, numbers, characters, strings, procedures * About a dozen or more operations each * Naming things * (define name thing) * Sequencing operations * Give them in order (in the definitions panel before the "run") * The arguments to a procedure call are evaluated in some sequence (+ (* 2 3) (sqrt 2)) * Make choices - Not yet * Repeat - Not yet * Define "subroutines" - Today's topic Subroutine: You want to do something similar multiple times, but perhaps with different data * Simple strategy: Copy and paste and update * Sometimes you get it wrong (you forget to update everythjing) * Sometimes you get the initial code wrong * Also hard to read * Better strategy: Name and Parameterize code * Form (define NAME-OF-PROCEDURE (lambda (PARAM1 PARAM2 ... PARAMN) THE-CODE-YOU-WANT-TO-NAME)) /Notes/ * You do /not/ need to document (unless I tell you to do so). * Do not do problem 3.c * (define root1 (/ (+ (- b) (sqrt (- (* b b) (* 4 a c)))) (* 2 a)))