CSC151 2007S, Class 41: Representing Color Palettes with Vectors Admin: * Notes distributed on Assignment 14, including sample solution. * EC: CS Extra today at 4:30 in 3821 on Scripting Vector Graphics. * EC: Comedian Kumail Nanjiani '01 at 8:00 Friday in Main. * EC: Women's Basketball Saturday at 1:30 in the new Darby. * In this class, Assignment 15 will be optional (for extra credit). Overview: * Problems with lists. * A solution: Vectors. * Important vector procedures. Lists: Our favorite way to group data: * Allow us to group data * Simple to use: car, cons, cdr and a few more operations But some problems * We can't change lists, we make copies with variations * Potentially wastes memory * Finding things deep in the list is expensive (proportional to the position in the list) Designers of Scheme created an alternative to lists: vector * Like a list: Collects lots of values * But fast to get to a specified point * And mutable So why have lists? * Sometimes immutable values are good * TO guarantee fast access, vectors have fixed size; lists are extensible Operations: * Creating: (vector val1 val2 ... valn) - like list (make-vector size value) - make a vector of the specified size, containing only one value #(val1 val2 ... valn) - DANGEROUS; USE SPARINGLY * Extract information: (vector-ref vec pos) (vector-length vec) * Change information (vector-set! vec pos newval) * COnversion list->vector vector->list * Fish : Ghoti