'&$%CSE 341:Programming LanguagesWinter 2006Lecture 20— Introduction to SmalltalkCSE341 Winter 2006, Lecture 20 1'&$%TodayWhy Smalltalk?Some basics of smalltalk programs• Syntax• Messages• Blocks• Classes and Methods• Dynamic Dispatch• self and superSection: The Squeak environment (projects, saving your work, etc.)CSE341 Winter 2006, Lecture 20 2'&$%Smalltalk• Pure object-oriented• Class-based• Dynamically typedA good starting point for disc ussing what each of these means andwhat other languages look like.The language has been quite stable since 1980.Other points:• A tiny language; easy to learn almost all of it• A complete commitment to dynamic changes; little abstractionsupportCSE341 Winter 2006, Lecture 20 3'&$%Overview of Smalltalk1. All values are objects• Even numbers, code, and classes2. Objects communicate via messages (handled by methods)3. Objects have their own state4. Every object is an instance of a class5. A class provides behavior for its instancesThis sounds a lot like Java, but smaller.It’s also much more like Scheme than it seems; we’ll return to “whatreally makes something OO”But first we need to get “the feel for Smalltalk”CSE341 Winter 2006, Lecture 20 4'&$%Syntaxexp ::= atom | assign| unarySend | infixSend | keywordSend| ( exp ) | exp . exp | ^ expatom ::= ID | literal | blockliteral ::= INTEGER | STRING | ...block ::= [:ID1 ... :IDn | exp] | [ exp ]assign ::= name := exp | name _ expunarySend ::= exp IDinfixSend ::= exp OPERATOR expkeywordSend ::= exp ID1: exp ... IDn: expCSE341 Winter 2006, Lecture 20 5'&$%Some key ideas• Really, everything is an object• Blocks are lambdas• Return (↑) is special• Everything is “dynamic” – evaluation can add/remove classes,add/remove methods, etc.• Dynamic typing• Dynamic dispatch• Sends to self (a special identifier; Java’s this)CSE341 Winter 2006, Lecture 20 6'&$%Protection?• Fields are inaccessible outside of instance• All classes and methods are available to everyone• No namespace management; category has no semantic significanceCSE341 Winter 2006, Lecture 20
View Full Document