Characteristics of Smalltalk-72:
fred move up x inches
Smalltalk influenced the development of other object-oriented languages, such as C++, Objective C, CLOS, and our own Cecil and Kaleidoscope languages, as well as others.
Date today Time now hours Array new someCollection copy
Array new: 10 someArray at: 1 put: 54 anArray at: 1
5 * 9 3 + 2 * 5
Note that we will very frequently be composing messages -- for example
Time now hours + 1First sends the message
now
to the class Time
,
which returns the current time (an instance of Time). We then send this
object the message hours
, which returns an integer. Then we
send the message +
with the argument 1 to this integer,
returning another integer (which will be the current hour plus 1).
Object subclass: 'Stack' instanceVariables: 'store top' push: item top := top+1. store at: top put: item pop | item | item := store at: top. top := top-1. ^ item setsize: n store := Array new: n. top := 0.Adding error checking and growing:
push: item | oldStore | top := top+1. top > store size ifTrue: "store is about to overflow. make a new array twice as big, and copy the old values into it" [oldStore := store. store := Array new: 2 * oldStore size. 1 to: oldStore size do: [:k | store at: k put: (oldStore at: k)]]. store at: top put: item pop | item | self isEmpty ifTrue: [self error: 'trying to pop an empty stack']. item := store at: top. top := top-1. ^ item isEmpty ^ top=0