This preview shows page 1-2-3-4-5-6-7-50-51-52-53-54-55-56-100-101-102-103-104-105-106 out of 106 pages.
61A Lecture 17Friday, October 7Friday, October 7, 2011Today is Ada Lovelace Day2Images from WikipediaFriday, October 7, 2011Today is Ada Lovelace DayAda Lovelace, born 1815, was a writer, mathematician, and correspondent of Charles Babbage2Images from WikipediaFriday, October 7, 2011Today is Ada Lovelace DayAda Lovelace, born 1815, was a writer, mathematician, and correspondent of Charles Babbage2Images from WikipediaFriday, October 7, 2011Today is Ada Lovelace DayAda Lovelace, born 1815, was a writer, mathematician, and correspondent of Charles BabbageCharles Babbage designed the "analytical engine"2Images from WikipediaFriday, October 7, 2011Today is Ada Lovelace DayAda Lovelace, born 1815, was a writer, mathematician, and correspondent of Charles BabbageCharles Babbage designed the "analytical engine"2Images from WikipediaFriday, October 7, 2011Today is Ada Lovelace DayAda Lovelace, born 1815, was a writer, mathematician, and correspondent of Charles BabbageCharles Babbage designed the "analytical engine"Ada wrote its first program(to compute Bernoulli numbers)2Images from WikipediaFriday, October 7, 2011Generic Functions3Friday, October 7, 2011Generic FunctionsAn abstraction might have more than one representation3Friday, October 7, 2011Generic FunctionsAn abstraction might have more than one representation•Python has many sequence types: tuples, ranges, lists, etc.3Friday, October 7, 2011Generic FunctionsAn abstraction might have more than one representation•Python has many sequence types: tuples, ranges, lists, etc.An abstract data type might have multiple implementations3Friday, October 7, 2011Generic FunctionsAn abstraction might have more than one representation•Python has many sequence types: tuples, ranges, lists, etc.An abstract data type might have multiple implementations•Some representations are better suited to some problems3Friday, October 7, 2011Generic FunctionsAn abstraction might have more than one representation•Python has many sequence types: tuples, ranges, lists, etc.An abstract data type might have multiple implementations•Some representations are better suited to some problemsA function might want to operate on multiple data types3Friday, October 7, 2011Generic FunctionsAn abstraction might have more than one representation•Python has many sequence types: tuples, ranges, lists, etc.An abstract data type might have multiple implementations•Some representations are better suited to some problemsA function might want to operate on multiple data types3Today's Topics:Friday, October 7, 2011Generic FunctionsAn abstraction might have more than one representation•Python has many sequence types: tuples, ranges, lists, etc.An abstract data type might have multiple implementations•Some representations are better suited to some problemsA function might want to operate on multiple data types3Today's Topics:•Generic functions using message passingFriday, October 7, 2011Generic FunctionsAn abstraction might have more than one representation•Python has many sequence types: tuples, ranges, lists, etc.An abstract data type might have multiple implementations•Some representations are better suited to some problemsA function might want to operate on multiple data types3Today's Topics:•Generic functions using message passing•String representations of objectsFriday, October 7, 2011Generic FunctionsAn abstraction might have more than one representation•Python has many sequence types: tuples, ranges, lists, etc.An abstract data type might have multiple implementations•Some representations are better suited to some problemsA function might want to operate on multiple data types3Today's Topics:•Generic functions using message passing•String representations of objects•Multiple representations of abstract data typesFriday, October 7, 2011Generic FunctionsAn abstraction might have more than one representation•Python has many sequence types: tuples, ranges, lists, etc.An abstract data type might have multiple implementations•Some representations are better suited to some problemsA function might want to operate on multiple data types3Today's Topics:•Generic functions using message passing•String representations of objects•Multiple representations of abstract data types•Property methods Friday, October 7, 2011String Representations4Friday, October 7, 2011String RepresentationsAn object value should behave like the kind of data it is meant to represent4Friday, October 7, 2011String RepresentationsAn object value should behave like the kind of data it is meant to representFor instance, by producing a string representation of itself4Friday, October 7, 2011String RepresentationsAn object value should behave like the kind of data it is meant to representFor instance, by producing a string representation of itselfStrings are important: they represent language and programs4Friday, October 7, 2011String RepresentationsAn object value should behave like the kind of data it is meant to representFor instance, by producing a string representation of itselfStrings are important: they represent language and programsIn Python, all objects produce two string representations4Friday, October 7, 2011String RepresentationsAn object value should behave like the kind of data it is meant to representFor instance, by producing a string representation of itselfStrings are important: they represent language and programsIn Python, all objects produce two string representations•The "str" is legible to humans4Friday, October 7, 2011String RepresentationsAn object value should behave like the kind of data it is meant to representFor instance, by producing a string representation of itselfStrings are important: they represent language and programsIn Python, all objects produce two string representations•The "str" is legible to humans•The "repr" is legible to the Python interpreter4Friday, October 7, 2011String RepresentationsAn object value should behave like the kind of data it is meant to representFor instance, by producing a string representation of itselfStrings are important: they represent language and programsIn Python, all objects produce two string representations•The "str" is legible to humans•The "repr" is legible to the Python interpreterWhen the "str" and "repr" strings are the same, we're doing something right in our programming language!4Friday, October 7, 2011The "repr" String for an Object5Friday, October 7, 2011The "repr" String for
View Full Document