126x Filetype PDF File size 0.05 MB Source: www.cs.utoronto.ca
The current topic: Review Announcements • Lab 3 was due today at 10:30 am. !Introduction !Object-oriented programming: Python • Aids allowed for the final exam: !Functional programming: Scheme – One double-sided aid sheet, produced however you like, on standard letter-sized !Python GUI programming (Tkinter) (8.5" x 11") paper. !Types and values • Exam period office hours: !Logic programming: Prolog – Monday Dec. 8th, 12:30-1:30, SF3207 !Syntax and semantics – Wednesday Dec. 10th, 12:30-1:30, SF3207 !Exceptions – Friday Dec. 12th, 12:30-1:30, SF3207 – Monday Dec. 15th, 12:30-1:30, SF3207 – Tuesday Dec. 16th, 11:00-12:00, SF3207 • Lab 3 and Project marking: – Marking reports will be emailed (as usual) to your ECF accounts. – Watch the Announcements page for re-marking deadlines. Fall 2008 Review 1 Fall 2008 Review 2 Review Object-oriented programming: Python • Disclaimer: This is not a comprehensive review. Topics that aren't • Variables: mentioned here may still appear on the final exam. – Variables store references, not actual values. – Built-in types include: • Lists • Tuples • Dictionaries. • Strings. • Booleans. • Numbers: int, float, complex, long int • Types: – Strongly typed: Type restrictions are enforced. – Dynamically typed: Types are determined at runtime; there are no type declarations for variables, parameters, return values, etc. • Code structure: – Indentation is meaningful. Fall 2008 Review 3 Fall 2008 Review 4 Object-oriented programming: Python Object-oriented programming: Python • Containers: • Dictionaries – Collections of objects. – Mutable. – Sequences are containers that have some kind of ordering. – Not a sequence. – Mutable vs. immutable. – Set of key-value pairs. • Lists: • Loops: – Mutable sequences. – While loops. – Slicing: getting a portion of a list. – For loops. – Splicing: assigning to a slice. • Using the range function to make a list of numbers. • May cause the list to grow or shrink. • Classes: • Tuples: – Inheritance. – Immutable sequences. – Constructors. – Instance methods and variables. • Strings: – Class variables. – Immutable sequences where each element is a single character. – Static and class methods. – Name mangling. – Operator overloading. Fall 2008 Review 5 Fall 2008 Review 6 Object-oriented programming: Python Object-oriented programming: Python • Exceptions: • Working with files. – Raising. – Catching. • Modules: – Defining. – Importing modules. – Getting short-form naming. • Parameters and arguments: – Keyword vs non-keyword – Mandatory vs optional parameters • Regular expressions. • List comprehensions. e.g. T = [2*x for x in range(4)] • Iteration: – How this relates to __getitem__() and IndexError. Fall 2008 Review 7 Fall 2008 Review 8 Object-oriented programming: Python Functional programming: Scheme • An example: • Functions as first-class values. class A: • List operations: y = 1 – car def __init__(self): – cdr self.y += 2 – cons b = A() – append c = A() • Other operations: b.y # Value is: – Numeric (e.g. +, –, *, /) c.y # Value is: – Comparison (e.g. >, <, <=, >=, =) A.y # Value is: – Type-checking (e.g. number?, symbol?, list?) – Boolean (e.g and, or, not) • Defining functions. • Conditional execution: if, cond Fall 2008 Review 9 Fall 2008 Review 10 Functional programming: Scheme Functional programming: Scheme • Efficiency: • Trees: – let, let* – representing trees – helper functions – working with BSTs – using an accumulator – tail recursion • Mutual recursion. • Lambda expressions. • Higher-order functions: – functions as parameters – functions as return values • Built-in higher-order functions: – map – eval – apply – reduce (not built-in in mzscheme, but built-in in some other Schemes) Fall 2008 Review 11 Fall 2008 Review 12 Python GUI programming: Tkinter Types and values • The event loop. • Attributes of a variable: – static attributes vs dynamic attributes • Creating a root window. – name – And creating additional windows. – memory address – type • Widgets: – scope – creating – lifetime – arranging • Referencing environment: • Event-handling: – set of names that can be used at a particular point – creating callback functions – setting the callback function for a particular event • Referencing environment for functions passed as parameters: – Canvas event objects – shallow binding: names that can be accessed depend on where function is called – deep binding: names that can be accessed depend on where function is defined Fall 2008 Review 13 Fall 2008 Review 14 Logic programming: Prolog Logic programming: Prolog • Prolog statements: • Trees: – Facts. – representing trees – Rules. – working with BSTs – Queries. • Cut: • Answering queries: – what cut does – Unification. – avoiding wrong answers – Resolution. – avoiding duplicate answers – Backtracking. – avoiding unnecessary work – green vs red • Working with lists. • Negation: • Math. – what negation in Prolog really means – using negation safely • Structures: – No structural difference between queries and data. Fall 2008 Review 15 Fall 2008 Review 16
no reviews yet
Please Login to review.