Note from archiver<at>cs.uu.nl:
This page is part of a big collection
of Usenet postings, archived here for your convenience.
For matters concerning the content of this page,
please contact its author(s); use the
source, if all else fails.
For matters concerning the archive as a whole, please refer to the
or contact the archiver.
Subject: Smalltalk FAQ (v.1.0)
This article was archived around: 21 May 2006 04:22:58 GMT
Last-modified: May 14,1996
Smalltalk Frequently Asked Questions
Copyright =A9 1994 Vikas Malik
All Rights Reserved
This FAQ may be posted to any USENET newsgroup, on-line service, or BBS as
long as it is posted in its entirety and includes this copyright statement.
This FAQ may not be distributed for financial gain.
This FAQ may not be included in commercial collections or compilations
without express permission from the author.
Vikas Malik - firstname.lastname@example.org
Knowledge Systems Corporation
* What is self?
* What is super?
* What are three different message types in Smalltalk?
* What is shallow copy?
* What is deep copy?
* What are class instance variables?
* What do you get when you inspect Smalltalk?
* How can I implement stack and queue operations in Smalltalk?
* What is the difference between an array and a set?
* What is the difference between protocol and category?
* What do I get from 1+2*3?
* How do I stop the execution of a program?
* What is the difference between =3D and =3D=3D ?
* How do I iterate a collection?
* How do I use message perform: ?
* What is the difference between detect: and select: methods for
* What is the result of sending collect: [ :each | each > 5 ] to
* What do I use to concatenate strings efficiently?
* What is superclass of Object?
* What is subclassResposiblity method used for?
* What is shouldNotImplement method used for?
* What methods do I need to implement if I implement =3D method for an
* What method do I need to implement for proxy objects?
* What are three pseudo variables used by VisualWorks?
* What is the difference between SmallInteger and LargeInteger?
* What is the difference between Symbol and String?
* What is the difference between Bag and Set?
* What is the difference between chaining and cascading?
* What is yourself method used for?
* What is the difference between isMemberOf: and isKindOf: methods?
* Where is the method new defined?
* Why is an IdentitySet faster than a Set?
* What happens when I modify a collection while iterating over it?
* What is nil?
* What are pool dictionaries?
* What is a literal?
* What is MVC?
* What is an aspect?
* What is a dependent?
* How do I add a dependent to a model?
* How do I release dependents from a model?
* What is the change/update mechanism?
* What happens when I send changed or changed: message to a Model?
* How do I implement an update method for a view?
* What does invalidateRectangle: method do?
* How does a controller accesses keyboard events and mouse state?
* What is a ValueHolder in VisualWorks?
* What is a channel?
* How do an object register interest in a ValueModel?
* What is a dependency transformer?
* How do I change the value of a ValueModel without triggering any
* What is an AspectAdaptor?
* What is the subject channel of an AspectAdaptor?
* What is a PluggableAdaptor?
* What is an IndexedAdaptor?
* What is a SelectionInList?
* What is a BufferedValueHolder?
* What is the difference between an IndexedAdaptor and an
Other VisualWorks Questions
* What is a BlockClosure in VisualWorks?
* What is the launcher in VisualWorks?
* What is a SpecWrapper?
* What is the difference between an active component and a passive
* What is a widget?
* What is difference between application model and aspect model?
* What is a keyboard hook?
* What is the Transcript?
* What is a dispatcher?
* What is a ComponentSpec?
* What is a builder in ApplicationModel architecture?
* What is a FullSpec?
* What is a builder's resource?
* What is the builder's source?
* How does a builder caches resources?
* What is a lookPolicy object?
* How can I change a builder's look policy?
* How is a VisualWorks component built?
* What methods are used to access window, keyboardProcessor, named
components and aspect models from a builder?
* What is a keyboard processor?
* What is the difference between preBuildWith: and postBuildWith:
methods of ApplicationModel?
* What is the difference between postBuildWith: and postOpenWith:
methods of ApplicationModel?
* How do I close a window programmatically?
* Which message is sent to anApplicationModel for notification of a
* Which message is sent to anApplicationModel for validation of a
* What do I mean by Parent application and subapplication?
* What is the SubCanvasSpec's clientKey?
* What is the SubCanvasSpec's majorKey?
* What is the SubCanvasSpec's minorKey?
* How do I rebuild a subcanvas?
* What is ScheduledControllers?
* How do I access active window?
* How do I access widget of a named component?
* How do I give keyboard focus to a widget?
* How do I change a component's label?
* How do I make a widget invisible/visible?
* How do I enable/disable a component?
* Which method is used by aSequenceView to display its contents?
* How do I use an arbitrary method to display contents in
* How do I change grid spacing of aSequenceView?
Q1. What is self?
Ans. self refers to the receiver of the message. It is usually used within
a method to send additional messages to the receiver. self is frequently=
when it is desired to pass the sender object (self), as a message argument,=
to a receiver who requires knowledege of the sender or who will in some way=
manipulate the sender.
Q2. What is super?
Ans. super refers to the superclass of the class that defines the message
sent to the receiver.Super is mechanism by which a sender can overide its=20
own defined method hierarchy.
Q3. What are three different message types in Smalltalk?
Ans. 1. Unary messages
2. Binary Messages
3. Keyword Messages
Q4. What is shallow copy?
Ans. shallowCopy returns a copy of receiver which shares the receiver's
Q5. What is deep copy?
Ans. deepCopy returns a copy of the receiver with shallow copies of each
Q6. What are class instance variables?
Ans. Class instance variables are similar to class variables, except that
they are created for eachsubclass of the defining class. When a class
declares a class instance variable, a new variable is created for each
subclass of that class. Each subclass then has its own instance of the
variable and retains its own value for the variable, but each subclass has
a variable with the same name. Only class methods of a class and its
subclasses can refer to class instance variables; instance methods cannot.
Q7. What do you get when you inspect Smalltalk?
Ans. An instance of SystemDictionary. SystemDictionary maintains all the
names of classes, global variables and pool dictionaries in the system.=20
Smalltalk is the sole instance of the class SystemDictionary.
Q8. How can I implement stack and queue operations in Smalltalk?
Ans. An OrderedCollection can be used to implement stack and queue
operations. A stack is implemented by using addLast: anObject and
removeLast methods for pushing and poping respectively. A Queue is
implemented by using addLast: anObject and removeFirst methods.
Q9. What is the difference between an array and a set?
Ans. An array is a fixed size collection whereas a set can grow in size. An
array has integer keys and a set is not keyed. A set enforces uniqueness=
Q10. What is the difference between protocol and category?
Ans. The methods of a class are organised in logical groups called
protocols. Classes are grouped together into groups called categories.
Q11. What do I get from 1+2*3?
Q12. How do I stop the execution of a program?
Ans. By sending message halt.
Q13. What is the difference between =3D and =3D=3D ?
Ans. =3D is a test for equality. =3D=3D is a test for identity (same=
Except for some special classes like Symbol, Character & SmallInteger, two
cases of a value (eg. 1.54) will not be the identical object, just one with
equal value. The special cases are "special" and any variables that points
to such an object will be by definition "Identical".
Q14. How do I iterate a collection?
Ans. By using the following enumeration messages.
1. do: aBlock
2. select: aBlock
3. reject: aBlock
4. detect: aBlock
5. collect: aBlock
6. inject: aValue into: aBlock
Q15. How do I use message perform: ?
Ans. perform: method is used to tell an object to execute a method whose
name, rather than being hardcoded, is sent as a parameter. This means that
the name of the message need not be know until runtime.
anObject perform: #methodName
Q16. What is the difference between detect: and select: methods for
Ans. detect: aBlock returns the first element of the collection for which
aBlock evaluates to true. select: aBlock returns a collection whose
elements are the elements of the receiver for which aBlock evaluates to
Q17. What is the result of sending collect: [ :each | each > 5 ] to
Ans. A collection whose elements are true and false.
collect:aBlock returns a collection which contains the results of
performing the same operation on each element in the receiver collection.
Q18. What do I use to concatenate strings efficiently?
Q19. What is superclass of Object?
Q20. What is subclassResposiblity method used for?
Ans. subclassResponsibility method is used to defer the actual
implementation of a method.
Q21. What is shouldNotImplement method used for?
Ans. shouldNotImplement method is used to indicate that a subclass wants to
undefine a method defined in a superclass.
Q22. What methods do I need to implement if I implement =3D method for an
Q23. What method do I need to implement for proxy objects?
Ans. doesNotUnderstand: aMessage
Q24. What are three pseudo variables used by VisualWorks?
Ans. self, super and thisContext.
Q25. What is the difference between SmallInteger and LargeInteger?
Ans. A SmallInteger has fixed number of bytes and a LargeInteger has
variable number of bytes.
Q26. What is the difference between Symbol and String?
Ans. Symbols are similar to strings except that they are unique. This means
that whilst one can create several string objects containing the same
sequence of characters, there will only be exactly one instance of a symbol
with a given sequence of characters.
Q27. What is the difference between Bag and Set?
Ans. A bag can have duplicates whereas a Set contains no duplicate objects.
Q28. What is the difference between chaining and cascading?
Ans. In Chaining, one message can follow on after another. In this case the
second message is sent to the object which is the result of the first
anObject msg1 msg2 msg3
In Cascading, each message is followed by a semicolon (;) and another
message. In Cascading, subsequent messages are sent to the first receiver.
anObject msg1; msg2; msg3
Q29. What is yourself method used for?
Ans. yourself method returns self. It is usually used while cascading
messages like add: .
| aCollection |
aCollection :=3D OrderedCollection new add: 1;
In the above example add: returns its argument, not the receiver.
Therefore, yourself message is sent to do the proper assignment of an
OrderedCollection to aCollection variable.
Q30. What is the difference between isMemberOf: and isKindOf: methods?
Ans. isMemberOf: aClass returns true if receiver is an instance of aClass.
isKindOf: aClass returns true if receiver is an instance of aClass or one
of its subclasses.
Q31. Where is the method new defined?
Ans. Method new is defined on instance side of class Behavior.
Q32. Why is an IdentitySet faster than a Set?
Ans. An IdentitySet is faster that a Set because =3D=3D is a faster test=
Q33. What happens when I modify a collection while iterating over it?
Ans. Modifying a collection while iterating over it will give unpredictable
Employees do: [:anEmployee | anEmployee isProgrammer ifTrue: [ Employees
Above example will not work as expected since we are changing the size of
Employees collection while iterating over it. Making a copy of the
collection will avoid the above problem.
Employees copy do: [:anEmployee | anEmployee isProgrammer ifTrue: [
Employees remove: anEmployee]]
Q34. What is nil?
Ans. nil is the only instance of the class UndefinedObject and it is the
default value for any new variable until a specific value is assigned to
Q35. What are pool dictionaries?
Ans. Pool dictionaries are created for providing access to pool variables
to several classes that are not related by inheritance.
Q35+. What is a literal?
Ans. A literal is a piece of Smalltalk code that the compiler converts
immediately to an object. Literals can be freely included in the programs
just by typing them.
Literal type Example
String 'David Letterman'
Array of literals #('apple' 12.9 name)
Q36. What is MVC?
Ans. MVC stands for Model-View-Controller. Model stores information/data.
Model notifies its dependents whenever one or more of its variables is
changed. View is the component for displaying output. Contoller is the
component that enables the user to interact with, or control, the
Q37. What is an aspect?
Ans. An aspect is a piece or subset of model's domain information.
Q38. What is a dependent?
Ans. A dependent is an object that is dependent on the information residing
in a model. A dependent object is usually a view, a window, or another
model and is contained in dependents collection of a model.
Q39. How do I add a dependent to a model? Ans. aModel addDependent:
This method adds aDependent to aModel's dependents collection.
Q40. How do I release dependents from a model?
Ans. aModel release replaces aModel's dependents collection with nil.
Q41. What is the changed/update mechanism?
Ans. The changed/update mechanism is used by a model to broadcast a
notification of change to all its dependents.
Q42. What happens when I send changed or changed: message to a Model?
Ans. A changed/changed: message sends an update message to all of
Q43. How do I implement an update method for a view?
Ans. The prototype for an update method for a view is
anAspect =3D anAspectOfInterest
ifTrue: [ self invalidate]
Q44. What does invalidateRectangle: method do?
Ans. Invalidate messages initiate a view's redrawing process.
invalidateRectangle: aRectangle invalidates only that area of the view
defined by aRectangle.
Q45. How does a controller accesses keyboard events and mouse state?
Ans. By using its instance variable sensor, which references a
Q46. What is a ValueHolder in VisualWorks?
Ans. A ValueHolder is a value model. It holds simple model objects like
numbers, strings, etc. A ValueHolder is created by sending asValue message
to any object or sending with: anObject to ValueHolder class
ValueHolder with: anObject
A ValueHolder understands value/value: protocol. value message is used to
access its value. value: anObject message is used to set its value to
Q47. What is a channel?
Ans. A channel is a value model that is used as a common access point for a
Q48. How do an object register interest in a ValueModel?
Ans. By sending onChangeSend: aChangeMessage to: anInterestedObject to a
ValueModel. The advantages of this approach are:
(i) The interested object does not need to be a dependent of the value
(ii) The interested object does not need to implement an update method.
Q49. What is a dependency transformer?
A DependencyTransformer implements the behavior needed by an object to
register interest in a value model. A dependencyTransformer is defined as a
dependent of a value model and converts an update message sent to itself
into a specific change message and sends this change message to the
Q50. How do I change the value of a ValueModel without triggering any
Ans. 1. By using setValue: newValue method instead of value: newValue
method. setValue: method replaces the value instance variable without
sending update messages to dependents.
2. Remove the DependencyTransformer from the ValueModel's dependents. Send
retractInterestsFor: anObject message to the ValueModel. This is done just
prior to sending value: newValue message.
Using setValue: disallows all updates. retractInterestsFor: only disallows
a specific update, allowing all others to proceed.
Q51. What is an AspectAdaptor?
Ans. An AspectAdaptor is a ValueModel whose value actually belongs to
another object called the subject. The task of AspectAdaptor is to
interface the general-purpose view object to just one aspect of the
model(subject). An AspectAdaptor is created as follows:
| aa |
aa :=3D AspectAdaptor subject: Employee new.
aa forAspect: #ssn.
One can change the ssn of this employee by using aa value: aNumber. An
AspectAdaptor needs to know which messages to send to the model to access
and assign value to one of its aspect. In the above example value/value:
messages sent to aa are converted into ssn/ssn: and sent to subject.
forAspect: #ssn message sets the getSelector to #ssn and sets the
putSelector to #ssn: The value method of AspectAdaptor is implemented as
^subject perform: self getSelector
Q52. What is the subject channel of an AspectAdaptor?
Ans. The subject channel is the ValueHolder containing the subject of an
AspectAdaptor. It is useful when several AspectAdaptors share the same
subject and its value of this subject needs to be changed.
Q53. What is a PluggableAdaptor?
Ans. A PluggableAdaptor uses blocks to adapt a model to a view instead of
using just selectors like AspectAdaptor. The blocks are called the
getBlock, the putBlock and the updateBlock. These blocks get executed when
a PluggableAdaptor receives value/value: and update messages. A
PluggableAdaptor can be created as follows:
| pa |
pa :=3D PluggableAdaptor on: Employee new.
pa getBlock: [ :m | m salary * 30 ]
putBlock: [ :m :v | m salary: (v/30)]
updateBlock: [ :m :a :p | .... ].
On sending value message to pa, getBlock gets executed. It send salary
message to employee(model), multiplies the result by 30 and returns it. In
this way, one can perform more complex operations on model as a result of
just sending the value message to pluggableAdapator.
Q54. What is an IndexedAdaptor?
Ans. An IndexedAdaptor is similar to AspectAdaptor except that its subject
is a sequenceable collection and value/value: messages are dispatched to
the subject as at:/at: put: . Q55. What is a SelectionInList?
Ans. A SelectionIinList is a selection model. It has two instance
(i) listHolder instance variable is a ValueModel containing a sequenceable
collection. listHolder acts as a model for SequenceView.
(ii) selectionIndexHolder instance variable is a ValueHolder with the index
of the current selection as its value.
SelectionInList does not have any dependents. Both of its instance
variables have two dependents : the SequenceView and the SelectionInList
Q56. What is a BufferedValueHolder?
Ans. A BufferedValueHolder is a ValueModel that references two other value
models called its subject and trigger channel. When a BufferedValueHolder
receives a value: message, it holds onto the new value and does not update
the subject until trigger channel becomes true.
Q57. What is the difference between an IndexedAdaptor and an AspectAdaptor?
Ans. An IndexedAdaptor operates on a numbered instance variable in the
subject, whereas an AspectAdaptor operates on a named instance variable.
Q58. What is a BlockClosure in VisualWorks?
Ans. Class BlockClosure implements the block notation in VisualWorks
Smalltalk. In VisualWorks, blocks are close to being closures. One can
declare variables local to the block, and the names of block parameters are
local to the block.
Q59. What is the launcher in VisualWorks?
Ans. The launcher is the root of the VisualWorks development environment.
Various development tools can be launched (or opened) from its menu.The
launcher is implemented by VisualLauncher which is a subclass of
Q60. What is a SpecWrapper?
Ans. A VisualWorks component is a SpecWrapper. A SpecWrapper is wrapper
that contains a widget, decoration for the widget, a copy of WidgetState
object and ComponentSpec.
Q61. What is the difference between an active component and a passive
Ans. An active component is a VisualWorks component whose widget is a View
and has a Model and a Controller. A passive component is a VisualWorks
component whose widget is not a View and it does not depend on a model and
Q62. What is a widget?
Ans. A widget is a visual part responsible for the visual representation of
a VisualWorks component.
Q63. What is difference between application model and aspect model?
Ans. An ApplicationModel is responsible for creating and managing a runtime
user interface. An aspect model contains a single aspect of info and
provides the model behavior for a single VisualWorks component. The
relationship between an application model and an aspect model is that an
application model contains one or more aspect models.
Q64. What is a keyboard hook?
Ans. A keyboard hook is a used for intercepting all the keyboard activity
going to a VisualWorks component. It is a block which is evaluated just
prior to the widget controller handling a keyboard event. Keyboard hook can
be set as follows:
| comp |
comp :=3D anApplicationModel builder componentAt:=
comp widget controller keyboardHook: aBlock.
Q65. What is the Transcript?
Ans. The Transcript is a text window used by the system to report important
events. The global variable Transcript is an instance of the class
TextCollector in VisualWorks and class TranscriptWindow in Digitalk.
Q66. What is a dispatcher?
Ans. A dispatcher is used by a widget controller to dispatch notification
and validation messages to the ApplicationModel. A dispatcher is an
instance of class UIDispatcher.
Q67. What is a ComponentSpec?
Ans. A ComponentSpec describes properties and features of a VisualWorks
component. ComponentSpec provides behavior for interface persistence in
form of source code or text file.
Q68. What is a builder in ApplicationModel architecture?
Ans. A builder is an instance of class UIBuilder. It is used to construct a
user interface according to the specifications. It also provides access to
the runtime interface. Builder provides access to named components, the
keyboard processor, the window and aspect models of a running application.
Q69. What is a FullSpec?
Ans. A FullSpec is a combination of a window spec and a spec collection. A
window spec describes a window and a spec collection is a collection of
component specs for all components of a window.
Q70. What is a builder's resource?
Ans. A resource is an object used by the builder to construct the interface
according to the specs. Examples of resources are aspect models, menus,
images, and labels. There are two types of resources:
1. Static resources - do not change during runtime.
2. Dynamic resources - change during runtime.
Q71. What is the builder's source?
Ans. The builder's source is an ApplicationModel that provides the
necessary resources to a builder for building an interface according to the
specs. It is kept in source instance variable of UIBuilder.
Q72. How does a builder caches resources?
Ans. A builder uses the following variables to cache resources.
1. bindings to cache aspect models reqired by active components.
2. labels to cache text labels.
3. visuals to cache visual components.
Q73. What is a lookPolicy object?
Ans. A lookPolicy object is an instance of one of the subclasses of the
UILookPolicy abstract class. A lookPolicy object is used to create a
VisualWorks component based on the componentSpec and the specific window
environment's look and feel.
Q74. How can I change a builder's look policy?
Ans. By sending policy: aLookPolicy message to a builder.
aBuilder policy: MotifLookPolicy new.
Q75. How is a VisualWorks component built?
Ans. A VisualWorks component is built by either the component spec or by
the builder's look policy object. Usually it is the look policy object that
builds a VisualWorks component. A look policy object uses its instance
methods, component building methods, to construct a VisualWorks component
based on a ComponentSpec and look & feel of that particular look policy.
Q76. What methods are used to access window, keyboardProcessor, named
components and aspect models from a builder?
aBuilder componentAt: #componentID.
aBuilder aspectAt: #aspect.
Q77. What is a keyboard processor?
Ans. A keyboard processor is an instance of class KeyboardProcessor. It
directs keyboard events to the current widget controller. There is only one
keyboard processor per window. A widget controller that takes focus has an
instance variable, keyboardProcessor, used to reference its window's
Q78. What is the difference between preBuildWith: and postBuildWith:
methods of ApplicationModel?
Ans. preBuildWith: aBuilder method allows anApplicationModel to make any
changes to its builder prior to handling its full spec. postBuildWith:
aBuilder method allows any final changes to the interface prior to opening.
Q79. What is the difference between postBuildWith: and postOpenWith:
methods of ApplicationModel?
Ans. In the postBuildWith: method, the interface is completely built but it
exists in memory only and window is not open. Whereas postOpenWith: method
allows the application model to make any changes to the interface with the
Q80. How do I close a window programmatically?
Ans. By sending the closeRequest message to anApplicationModel.
closeRequest method sends an update: #closeRequest to anApplication Model
dependents (window is one of the dependents).
Q81. Which message is sent to anApplicationModel for notification of a
Ans. noticeOfWindowClose: aWindow.
Q82. Which message is sent to anApplicationModel for validation of a window
Q83. What do I mean by Parent application and subapplication?
Ans. The subapplication is the application model that manages the
subcanvas. The parent application is the application model that provides
the subapplication as an aspect model.
Q84. What is the SubCanvasSpec's clientKey?
Ans. clientKey is the message name which is sent to parent application to
acquire the subapplication that manages the subcanvas.
Q85. What is the SubCanvasSpec's majorKey?
Ans. majorKey is the name of ApplicationModel subclass that builds and runs
the subcanvas component.
Q86. What is the SubCanvasSpec's minorKey?
Ans. minorKey is name of the class method that returns a full spec
describing the subcanvas interface.
Q87. How do I rebuild a subcanvas?
Ans. By sending one of the following messages to aSubCanvas.
client: appModel spec: aSpec
client: appModel spec: aSpec builder: aBuilder
appModel is subapplication, aSpec is full spec of subcanvas, and aBuilder
is an instance of UIBuilder.
Q88. What is ScheduledControllers?
Ans. ScheduledControllers is a global variable that refers to the only
instance of ControlManager. It is responsible for managing all current
Q89. How do I access active window?
Ans. ScheduledControllers currentController view
Q90. How do I access widget of a named component?
Ans. (anApplicationModel builder componentAt: #compID) widget
Q91. How do I give keyboard focus to a widget?
Ans. By sending takeKeyboardFocus to a VisualWorks component.
Q92. How do I change a component's label?
Ans. comp labelString: aString
Q93. How do I make a widget invisible/visible?
Q94. How do I enable/disable a component?
Q95. Which method is used by aSequenceView to display its contents?
Q96. How do I use an arbitrary method to display contents in aSequenceView?
Ans. By sending displayStringSelector: aSymbol message to aSequenceView.
aSymbol is the name of method used to display strings.
Q97. How do I change grid spacing of aSequenceView?
Ans. aSequenceView lineGrid: aNumber