everything's an object
- ''You could think of Smalltalk's object model as Java on steroids''
- common superclass Object
- block construct to treat enclosed code as if it was an object: [n <- n+1]
but...
SmallTalk highly supports features of functional languages, such as
- higher order functions
- first-class types
communication via messages
- parameters passed by reference
- idealized: there is only one 2; every
smallInteger with value 2 actually is a reference to that object
Jack pass: theBall to: Jill
Language Properties
scoping, binding, types
scoping
static, one global name space
no private classes -- problematic in code reuse!
binding
dynamic (messages are bound to methods at run-time)
→Polymorphism (especially overloading) is supported
does SmallTalk have types?
- Variables are untyped, checking (and exception-raising in case of type errors) happens at run-time
- everything is of type Object, possibly subclassed
- they appear not to be necessary in the SmallTalk language concept...
Classes and Arrays of ... can be used to create new types.
memory management
stack
.. for procedure execution, as usual
dynamic for data
- scavenging to reclaim objects with short lifetime
- global garbage collection (mark-and-sweep) to reclaim
objects with long lifespan
other features
compiled, then executed on a VM
assertion
is supported, but beware of side effects inside assertions!
concurrency
threads can be forked out, then run until they're done
Example
Programming Language Pragmatics, p580:
gcd: other
[self = other]
ifTrue: [↑self].
[self < other]
ifTrue: [↑self gcd: (other-self)]
ifFalse: [↑other gcd: (self-other)]
|