Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 331 Principles of Programming Languages

Similar presentations


Presentation on theme: "CS 331 Principles of Programming Languages"— Presentation transcript:

1 CS 331 Principles of Programming Languages
A Smidgen of Smalltalk CS 331 Principles of Programming Languages

2 Overview Sethi’s book Section 7.7 and 7.8 Section 15.4 For an overview of Smalltalk, see Kaehler and Patterson’s “A Taste of Smalltalk” There are numerous Smalltalk resources on the Web We’ll be using Squeak to demonstrate

3 Fundamental Concepts The big idea: everything happens as a result of messages sent to objects Smalltalk code is written in the context of the Smalltalk development environment The Smalltalk system provides lots of classes which you can use and study

4

5 Message keywords Class instances are created by class methods
Most classes understand the “new” message Some messages have keyword arguments which end with a colon, e.g. aStack push:10 A message may have two or more keywords, e.g. moveTower fromPin:1 toPin:3

6 Smalltalk Syntax Values to be returned are indicated by ^
e.g. ^ lastObject Conditionals and blocks e.g. x > y ifTrue: [max := x] ifFalse: [max:=y] Objects can send themselves messages e.g. Self isEmpty The name super accesses an overridden method

7 More Syntax The character $a, the string ‘foo’
Assignment operator is the left arrow e.g. index <- self find: oldObject. Using arrays and array elements e.g. A at: I put: x e.g. y <- A at: I e.g. A <- #(1 2 3)

8 Example testVar is 1 arrayTest "See if we can access array elements"
testVar <- A at: 1. Transcript cr. Transcript show:('testVar is ', testVar printString). " (Object new) arrayTest " testVar is 1

9


Download ppt "CS 331 Principles of Programming Languages"

Similar presentations


Ads by Google