Smalltalk Syntax Cheat Sheet: Unterschied zwischen den Versionen
Cg (Diskussion | Beiträge) |
Cg (Diskussion | Beiträge) |
||
| (78 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt) | |||
| Zeile 1: | Zeile 1: | ||
A short, one page summary of what beginners need to know about Smalltalk/X syntax |
A short, one page summary of what beginners need to know about Smalltalk/X, its syntax and most useful code fragments.<br>As usual, this is only a tiny fraction of what is really awailable, and you should use the builtin class browser to find many more useful functions in the system. |
||
This page was extracted from the "Smalltalk/X Programmers guide - Smalltalk/X Cheat Sheet". |
This page was extracted from the "Smalltalk/X Programmers guide - Smalltalk/X Cheat Sheet". |
||
<br>Smalltalk/X language extensions are marked with '''(*)'''. |
<br>Smalltalk/X language extensions (w.r.t. other Smalltalk implementations) are marked with '''(*)'''. |
||
== Smalltalk Philosophy == |
|||
A very short summary and introduction to the fundamental principles underlying the Smalltalk language. |
|||
* Everything is an '''Object'''<br>this includes the most basic ''things'' like numbers, strings and characters, up to complex objects like windows, editors, compilers, applications etc. |
|||
* The world consists of objects which '''communicate by sending messages'''.<br>(in other languages this is also known as ''virtual function call'', but this term is not used in Smalltalk) |
|||
* A message looks like an english sentence, and might look like "<code>heyYou doSomething</code>".<br>In this example, the "heyYou" is called the "''receiver of the message''" and "doSomething" is called the "''message selector''" |
|||
: You may pass additional parameter objects (arguments) as in: "<code>heyYou doSomethingWith:arg</code>"<br>or multiple arguments as in "<code>heyYou doSomethingWith:arg1 and:arg2</code>". |
|||
: In these examples, the selectors are "doSomethingWith:" and "doSomethingWith:and:" respectively<br>(i.e. the concatenation of the so called ''keywords'').<br>They are two different messages with different selectors.<br>In contrast to most other languages, this is '''not''' the same message with different number of arguments, but two completely different messages). |
|||
* Messages without argument are called "''unary messages''"; those with arguments are called "''keyword messages''" |
|||
: For example "<code>Transcript clear</code>" sends the message "clear" to the Transcript object; a unary message, |
|||
: and "<code>Transcript show:'hello'</code>" sends the message "show:" to the Transcript, passing a string argument; a keyword message |
|||
* To allow for arithmetic operations, any non-letter character (except for a few) are treated like a message name and written between the receiver and the one and only argument. These are called "''binary messages''". |
|||
: For example: <code>"3+4"</code> or <code>"abc,def"</code> (yes, the comma is an operator; it does string concatenation).<br>You can place whitespace anywhere between selectors, keywords and arguemnts (eg. <code>"3 + 4"</code> and <code>"3+4"</code> are the same). |
|||
* An object may respond (or "''answer''") by returning a result object. In the above example, "<code>3+4</code>" would answer "7", and "<code>'hello' , 'world'</code>" would answer 'helloworld' |
|||
* binary messages have no meaning to the compiler; they all have equal precedence and are evaluated from left to right. |
|||
: Admitted, this makes arithmetic a little strange initially;<br>you'll need parentheses as there is not precedence of eg. * over +.<br>The expression "3 + 4 * 5" will be evaluated left to right and answer 35. |
|||
* Everything in this world is an object;<br>from low level things like booleans, true, false, integer numbers, floating point numbers characters etc. to the most complex objects. |
|||
: Objects can refer to (i.e. hold references) to other objects. Technically, all such references are via pointers. There is no way to directly embed an object into another object, except by reference. |
|||
* Every object is associated to a class. Classes define the behavior of their instances. I.e. they define how they respond to messages. The response is implemented by a so called ''method''. That is a piece of code which is executed when a message comes in. A method consist of a number of statements (which are mostly message sends), each separated by a full stop (as in english). |
|||
: Inside a method, the receiver object (the object which got the message and is now executing the method) is called the ''receiver'' and refered to by the reserved word "<code>self</code>". |
|||
* Classes are themself objects, which respond to messages. Typically class messages would answer new instances, constants or implement utility functionality. There are also class messages to create new classes. |
|||
* Class can inherit common functionality (i.e. method implementations) from a superclass. Thus creating a hierarchy of classes. Typical hierarchies are the Number hierarchy, Collections, Streams and UI Widgets. |
|||
: Inside a method, the special reserved word "<code>super</code>" also refers to the current receiver, but message sends will ignore any method implemented in the methods class, but instead look for inherited (superclass) methods. |
|||
* In Smalltalk, every behavior is defined by corresponding message implementations. This includes control features (i.e. if-then-else, loops and exception handling). All of them are implemented as messages being sent to booleans (<code>ifTrue:</code>/<code>ifFalse:</code>) or blocks (<code>whileTrue:</code>) |
|||
* Blocks are objects, which wrap a piece of code.<br>Other languages know them as ''anonymous functions'', ''lambdas'' or ''closures''.< |
|||
: But the Smalltalk syntax makes them super easy to use: just write a number of expressions inside square brackets,<br>as in:"<code>[ Transcript show: 10 factorial ]</code>". |
|||
: Blocks are real objects - they can be passed as argument in a message send;<br>for example to a boolean: "<code>aBoolean ifTrue: [ Transcript show: 'yes' ]</code>" |
|||
: they can be stored in variables and passed around just like any other object |
|||
: blocks can receive messages, especially loop messages: "<code>[ a < 10] whileTrue:[ Transcript showCR: a. a := a + 1 ]</code>", |
|||
: and they can be returned from a method (''answer from a message'') . |
|||
* a small language and a big library<br>the syntax of Smalltalk is tiny and learned in minutes. The library (i.e. the classes you get) is big, flexible and extendable. The IDE is really an "''integrated environment''" as it is both completely implemented in Smalltalk, part of the running system (not outside), immediately updating the running system. |
|||
== Syntax == |
== Syntax == |
||
| Zeile 24: | Zeile 70: | ||
==== Literal Constants ==== |
==== Literal Constants ==== |
||
===== Numbers ===== |
|||
{| class="wikitable" |
{| class="wikitable" |
||
| Zeile 43: | Zeile 91: | ||
| ''C/Java/JavaScript style: prepend radix indicator ('x', 'b', 'o')<br>One of hex, binary and octal'' |
| ''C/Java/JavaScript style: prepend radix indicator ('x', 'b', 'o')<br>One of hex, binary and octal'' |
||
|- |
|- |
||
| Floats<br>(IEEE double; roughly 17 |
| Floats<br>(IEEE double; roughly 17 digits) |
||
| 12.456<br>1.234e17<br>-6.9<br>-6e-10<br>Float pi<br>Float e |
| 12.456<br>1.234e17<br>-6.9<br>-6e-10<br>Float pi<br>Float e |
||
| ''called "Float", but actually hold double precision |
| ''called "Float", but actually hold double precision<br>Common constants can be referred to "by name".'' |
||
|- |
|- |
||
| Short floats<br>(IEEE single; roughly 8 |
| Short floats<br>(IEEE single; roughly 8 digits) (*) |
||
| <code>1. |
| <code>1.234e17f</code><br><code>-6e-10f</code> |
||
| <strike>''this is controlled by a ParserFlag (singlePrecisionFloatF), which is currently defaulted to false. Thus, by default, double precision floats are created with the 'f' exponent character.''</strike> |
|||
| |
|||
|- |
|- |
||
| Long floats<br>(IEEE |
| Long floats<br>(IEEE extended; roughly 20 digits) (*) |
||
| <code>1. |
| <code>1.234e17q</code><br><code>-6q-10q</code> |
||
| ''actual precision depends on the underlying CPU<br>( |
| ''actual precision depends on the underlying CPU<br>(x86/x86_64: 80bit; Sparc: 128 bit) |
||
|- |
|- |
||
| |
| Quad floats;<br>(IEEE quad; roughly 34 digits (*) |
||
| <code>1. |
| <code>1.234e17Q</code><br><code>-6e-10Q</code> |
||
| ''computed in software; therefore slower; this is not yet officially released. |
| ''computed in software; therefore slower; <strike>this is not yet officially released.</strike> |
||
|- |
|||
| Octuple floats;<br>roughly 60 digits (*) |
|||
| <code>1.234e17QO</code><br><code>-6e-10QP</code> |
|||
| ''computed in software; therefore slower; <strike>this is not yet officially released.</strike> |
|||
|- |
|||
| Large floats;<br>roughly 60 digits by default, but any precision possible (*) |
|||
| <code>1.234e17QL</code><br><code>-6e-10QL</code> |
|||
| ''computed in software; therefore slower; <strike>this is not yet officially released.</strike> |
|||
|- |
|- |
||
| Fractions |
| Fractions |
||
| <code>(1/3)</code><br><code>(17/2)</code> |
| <code>(1/3)</code><br><code>(17/2)</code><br>(-3/2) |
||
| |
| |
||
|- |
|||
| ScaledDecimals |
|||
| <code>1234.53s2</code> |
|||
| ''the number after the s specifies the number of digits'' |
|||
|- |
|||
| Complex |
|||
| <code>(1.5 + 3i)</code><br><code>2i</code><br><code>(3.0q + 5.0qi</code>) |
|||
|} |
|||
===== Characters and Strings ===== |
|||
{| class="wikitable" |
|||
|- |
|- |
||
| Characters |
| Characters |
||
| <code>$a</code><br><code>Character space</code><br><code>Character nl</code><br>Also: "<code>null</code>", "<code>tab</code>", "<code>return</code>", "<code>bell</code>"... |
| <code>$a</code><br><code>Character space</code><br><code>Character nl</code><br>Also: "<code>null</code>", "<code>tab</code>", "<code>return</code>", "<code>bell</code>"...<br>Or:<br><code>Character codePoint:n</code> |
||
| '' |
| ''Smalltalk does not support any escape sequence<br>Common constants can be referred to "by name".'' |
||
|- |
|- |
||
| Strings |
| Strings |
||
| <code>'hello'</code> |
| <code>'hello'</code> |
||
| ''traditionally, Smalltalk does not support any escape sequence inside'' |
| ''traditionally, Smalltalk does not support any escape sequence inside<br>(i.e. they are what Python calls "Raw Strings")<br>But see below...'' |
||
|- |
|- |
||
| Strings<br>(C Style) (*) |
| Strings<br>(C Style) (*) |
||
| <code>c'hello\nworld'</code> |
| <code>c'hello\nworld'</code> |
||
| ''supports the common escape sequences, such as "\n", "\t", "\xHH" '' |
| ''supports the common C-escape sequences, such as "\n", "\t", "\xHH", "\uXXXX"'' |
||
|- |
|||
| Strings<br>(with embedded expressios) (*) |
|||
| <code>e'hello {OperatingSystem getLoginName}'</code> |
|||
| ''expanded expression strings <br>expressions in braces are evaluated at runtime and sliced into the string (also a C-string). Similar to python's f-strings.'' |
|||
|- |
|||
| Strings<br>(national language translated with embedded expressios) (*) |
|||
| <code>i'hello {OperatingSystem getLoginName}'</code> |
|||
| ''international strings<br>like above, but the string is also possibly translated to a national language'' |
|||
|- |
|- |
||
| Symbols |
| Symbols |
||
| <code>#'hello'</code><br><code>#foo</code> |
| <code>#'hello'</code><br><code>#foo</code><br><code>#+</code> |
||
| without quotes, if only alphaNumeric characters |
| ''symbols are interned strings; two symbols with the same characters are guaranteed to be the identical object (not just equal)<br>without quotes, if only alphaNumeric characters'' |
||
|} |
|||
===== Arrays and Objects ===== |
|||
{| class="wikitable" |
|||
|- |
|- |
||
| Arrays<br> |
| Arrays<br> |
||
| Zeile 109: | Zeile 189: | ||
| Multiple arguments |
| Multiple arguments |
||
| <code>[ :a1 :a2 ... :aN |<br> expr1 . expr2 ... exprN<br>]</code> |
| <code>[ :a1 :a2 ... :aN |<br> expr1 . expr2 ... exprN<br>]</code> |
||
|- |
|||
| Local Variables inside a block |
|||
| <code>[ :a1 ... :aN |<br> |local1 local2 |<br> expr1 ... exprN<br>]</code> |
|||
|} |
|} |
||
| Zeile 156: | Zeile 239: | ||
|- |
|- |
||
| Array Indexing (*) |
| Array Indexing (*) |
||
| <code>coll[idx]</code> |
| <code>coll[idx]</code><br> <code>coll[idx1][idx2]</code><br> <code>coll[idx1][idx2][idx3]</code> |
||
|syntactic sugar for:<br><code>(coll at:idx)</code><br>where coll must be an indexable collection,<br>and idx of compatible index type.<br>I.e. integer for array-like collections, hash-key for dictionaries, etc. |
|syntactic sugar for:<br><code>(coll at:idx)</code><br>where coll must be an indexable collection,<br>and idx of compatible index type.<br>I.e. integer for array-like collections, hash-key for dictionaries, etc.<br>Up to 4 dimensions are (currently supported) |
||
|- |
|- |
||
| Collection instantiation (*) |
| Collection instantiation (*) |
||
| <code>someClass[sz]</code> |
| <code>someClass[sz]</code><br> <code>someClass[sz][sz]</code><br> ... |
||
|syntactic sugar for:<br><code>(someClass new:sz)</code><br>where someClass must be a collection class<br>I.e. Array[10] creates an empty array with 10 slots. |
|syntactic sugar for:<br><code>(someClass new:sz)</code><br>where someClass must be a collection class<br>I.e. Array[10] creates an empty array with 10 slots.<br>1, 2, 3 and 4 dimensions are supported |
||
|- |
|- |
||
| Zeile 220: | Zeile 303: | ||
{| class="wikitable" |
{| class="wikitable" |
||
|- |
|||
| Starting another Thread |
|||
| <code>p := [ ... ] fork</code> |
|||
|the code inside the block will execute in a separate thread |
|||
|- |
|||
| Creating, configuring and starting another Thread |
|||
| <code>p := [ ... ]<br> newProcess;<br> name:'my worker';<br> priority:5;<br> resume</code> |
|||
|the code inside the block will execute in a separate thread |
|||
|- |
|||
| Terminating a Thread |
|||
| <code>p terminate</code> |
|||
|with p referring to the thread as created by newProcess or fork |
|||
|- |
|||
| Interrupting a Thread |
|||
| <code>p interruptWith:[ ... ]</code> |
|||
|interrupt the thread and let it execute the given code (in its interrupt seervice) |
|||
|- |
|- |
||
| Exception Handling |
| Exception Handling |
||
| <code>[ ... ] |
| <code>[ ... ]<br> on:Error do:[:ex |<br> ...<br> ]</code> |
||
|the handler will get an exception argument (ex), which contains additional information, and can be told how to deal with the error |
|the handler will get an exception argument (ex), which contains additional information, and can be told how to deal with the error |
||
|- |
|- |
||
| Exception Handling - proceeding |
| Exception Handling - proceeding |
||
| <code>[ ... ] |
| <code>[ ... ]<br> on:Error do:[:ex |<br> ...<br> ex proceed<br> ]</code> |
||
|proceed, as if the error did not happen |
|proceed, as if the error did not happen |
||
|- |
|- |
||
| Exception Handling - restarting |
| Exception Handling - restarting |
||
| <code>[ ... ] |
| <code>[ ... ]<br> on:Error do:[:ex |<br> ...<br> ex restart<br> ]</code> |
||
|restart the code from the beginning (usually after the handler did some cleanup, such as lazy loading a missing file...) |
|restart the code from the beginning (usually after the handler did some cleanup, such as lazy loading a missing file...) |
||
|- |
|- |
||
| Exception Handling - |
| Exception Handling - printing |
||
| <code>[ ... ] |
| <code>[ ... ]<br> on:Error do:[:ex |<br> ...<br> ex description<br> ...<br> ]</code> |
||
|contains a human readable description of the error |
|contains a human readable description of the error |
||
|- |
|- |
||
| Ensure/Unwind Protect |
| Ensure/Unwind Protect |
||
| <code>[ ... ] |
| <code>[ ... ]<br> ensure:[<br> ...<br> ]</code> |
||
|the ensure block will be evaluated in any case |
|the ensure block will be evaluated in any case |
||
|- |
|- |
||
| Ensure/Unwind Protect |
| Ensure/Unwind Protect |
||
| <code>[ ... ] |
| <code>[ ... ]<br> ifCurtailed:[<br> ...<br> ]</code> |
||
|the |
|the ifCurtailed block will be evaluated only on a non-regular exit<br>(i.e. when an exception was raised, or the operation was aborted or the thread terminated) |
||
|- |
|||
| Early exit from Loops |
|||
| <code>[:exit |<br> ...<br> code with loop<br> ...<br> exit value<br> ...<br>] valueWithExit</code> |
|||
|the block will be left, when exit is evaluated. Often used as argument of ifTrue:, as in<br>cond ifTrue: exit |
|||
|- |
|- |
||
| Queries |
| Queries |
||
| <code>Query |
| <code>Query<br> answer:something<br> do:[<br> ...<br> Query query<br> ...<br> ]</code> |
||
|to provide answers way down to whoever is interested.<br>Queries answer nil if no one is there to answer.<br>Queries are usually more specifically used as subclasses of Query |
|to provide answers way down to whoever is interested.<br>Queries answer nil if no one is there to answer.<br>Queries are usually more specifically used as subclasses of Query |
||
|- |
|- |
||
| Notifications |
| Notifications |
||
| <code>Notification |
| <code>Notification<br> handle:[<br> ...<br> ]<br> do:[<br> ...<br> Notification notify:someArg<br> ...<br> ]</code> |
||
|to provide information way up to whoever is interested<br>Notifications are usually more specifically used as subclasses of Notification |
|to provide information way up to whoever is interested<br>Notifications are usually more specifically used as subclasses of Notification |
||
|- |
|- |
||
| Observers 1 |
| Observers 1 |
||
| <code>foo onChange:#bla evaluate:[...]<br>...<br>foo changed:#bla</code> |
| <code>foo onChange:#bla evaluate:[...].<br>...<br>foo changed:#bla</code> |
||
|observer with generic block to evaluate |
|observer with generic block to evaluate |
||
|- |
|- |
||
| Observers 2 |
| Observers 2 |
||
| <code>foo onChangeSend:#xyz to:someone<br>...<br>foo changed</code> |
| <code>foo onChangeSend:#xyz to:someone.<br>...<br>foo changed</code> |
||
|observer with message send |
|observer with message send |
||
|- |
|- |
||
| Observers 3 |
| Observers 3 |
||
| <code>foo addDependent:someone<br>...<br>foo changed</code> |
| <code>foo addDependent:someone.<br>...<br>foo changed</code> |
||
|observer with send to update method of target |
|observer with send to update method of target |
||
|} |
|||
Queries and Notifications can be seen as observers within the calling hierarchy (i.e. information flows up or down the calling hierarchy), whereas the dependency and anChange mechanisms are independent of the control flow (even between different threads) |
|||
==== Synchronization and Timers ==== |
|||
{| class="wikitable" |
|||
|- |
|||
| Timed Delay |
|||
| <code>Delay waitForSeconds:n</code><br><code>Delay waitUntil:(Timestamp now + 10 seconds)</code> |
|||
|self explaining |
|||
|- |
|||
| Sempaphore wait |
|||
| <code>s := Semaphore new.<br>...<br>s wait.<br>...<br>s signal</code> |
|||
|obviously, the signalling must be evaluated by another thread |
|||
|- |
|||
| Sempaphore wait with timeout |
|||
| <code>s := Semaphore new.<br>...<br>s waitWithTimeout:(5 seconds).<br>...<br>s signal</code> |
|||
|obviously, the signalling must be evaluated by another thread |
|||
|- |
|||
| Multi Sempaphore wait |
|||
| <code>s1 := Semaphore new.<br>s2 := Semaphore new.<br>...<br>which := (s1 , s2) wait.<br>...<br>s2 signal</code> |
|||
|wait for any of multiple semaphores |
|||
|- |
|||
| Synchronized Collections |
|||
| <code>a := OrderedCollection new asSharedCollection</code> |
|||
|will wrap the collection so that add/remove operations are atomic |
|||
|} |
|} |
||
| Zeile 272: | Zeile 401: | ||
| Logging and Messaging |
| Logging and Messaging |
||
| <code>Transcript</code> - the console window<br><code>Stdout</code> - standard output<br><code>Stderr</code> - standard error<br><code>Stdin</code> - standard input<br><code>Logger</code> - redefinable logger (defaults to standard error) |
| <code>Transcript</code> - the console window<br><code>Stdout</code> - standard output<br><code>Stderr</code> - standard error<br><code>Stdin</code> - standard input<br><code>Logger</code> - redefinable logger (defaults to standard error) |
||
|- |
|||
| Common Useful Dialogs |
|||
| <code>Dialog</code> - provides many useful utility functions for standard dialogs<br>eg.<code><br> Dialog warn:'message'<br> Dialog confirm:'question'<br> Dialog request:'question'<br> Dialog requestFilename:'question'<br> ...</code> |
|||
|} |
|} |
||
| Zeile 279: | Zeile 411: | ||
|- |
|- |
||
| Numbers |
| Numbers |
||
| <code>Integer</code><br><code>Float</code><br><code>Fraction</code><br><code>Complex</code> |
| <code>[http://live.exept.de/ClassDoc/classDocOf:,Number Number]</code>(abstract superclass)<br><code>[http://live.exept.de/ClassDoc/classDocOf:,Integer Integer]</code>(integral numbers)<br><code>[http://live.exept.de/ClassDoc/classDocOf:,Float Float]</code>(inexact)<br><code>[http://live.exept.de/ClassDoc/classDocOf:,Fraction Fraction]</code>(exact)<br><code>[http://live.exept.de/ClassDoc/classDocOf:,Complex Complex]</code> |
||
|- |
|- |
||
| Collections |
| Collections |
||
| <code>Array</code> (fixed size array)<br><code>OrderedCollection</code>, <code>List</code> (variable size)<br><code>SortedCollection</code><br><code>Set</code>, <code>Bag</code> (unordered)<br><code>Dictionary</code> (mapped collections)<br><code>BinaryTree</code>, <code>AVLTree</code><br><code>SharedQueue</code> (shared, synchronized)<br>many more... |
| <code>[http://live.exept.de/ClassDoc/classDocOf:,Array Array]</code> (fixed size array)<br><code>[http://live.exept.de/ClassDoc/classDocOf:,OrderedCollection OrderedCollection]</code>, <code>[http://live.exept.de/ClassDoc/classDocOf:,List List]</code> (variable size)<br><code>[http://live.exept.de/ClassDoc/classDocOf:,SortedCollection SortedCollection]</code><br><code>[http://live.exept.de/ClassDoc/classDocOf:,Set Set]</code>, <code>[http://live.exept.de/ClassDoc/classDocOf:,Bag Bag]</code> (unordered)<br><code>[http://live.exept.de/ClassDoc/classDocOf:,Dictionary Dictionary]</code> (mapped collections)<br><code>[http://live.exept.de/ClassDoc/classDocOf:,BinaryTree BinaryTree]</code>, <code>[http://live.exept.de/ClassDoc/classDocOf:,AVLTree AVLTree]</code><br><code>[http://live.exept.de/ClassDoc/classDocOf:,SharedQueue SharedQueue]</code> (shared, synchronized)<br>many more... |
||
|- |
|- |
||
| Process Handling |
| Process Handling |
||
| <code>Process</code> (lightweight thread)<br><code>OSProcess</code> (heavyweight OS process)<br><code>Semaphore</code>, <code>RecursionLock</code> (synchronization)<br><code>Monitor</code>, <code>BoltLock</code><br><code>Delay</code> (time delays) |
| <code>[http://live.exept.de/ClassDoc/classDocOf:,Process Process]</code> (lightweight thread)<br><code>[http://live.exept.de/ClassDoc/classDocOf:,OSProcess OSProcess]</code> (heavyweight OS process)<br><code>[http://live.exept.de/ClassDoc/classDocOf:,Semaphore Semaphore]</code>, <code>[http://live.exept.de/ClassDoc/classDocOf:,RecursionLock RecursionLock]</code> (synchronization)<br><code>[http://live.exept.de/ClassDoc/classDocOf:,Monitor Monitor]</code>, <code>[http://live.exept.de/ClassDoc/classDocOf:,BoltLock BoltLock]</code><br><code>[http://live.exept.de/ClassDoc/classDocOf:,Delay Delay]</code> (time delays) |
||
|- |
|- |
||
| Files & Streams |
| Files & Streams |
||
| <code>Filename</code> (file naming, directory access, mime type)<br><code>Stream</code> (basic stream framework) |
| <code>[http://live.exept.de/ClassDoc/classDocOf:,Filename Filename]</code> (file naming, directory access, mime type)<br><code>[http://live.exept.de/ClassDoc/classDocOf:,Stream Stream]</code> (basic stream framework) |
||
<br><code>ReadStream</code>,<code>WriteStream</code>,<code>EncodedStream</code><br><code>ExternalStream</code>, <code>FileStream</code>, <code>Socket</code> (OS streams) |
<br><code>[http://live.exept.de/ClassDoc/classDocOf:,ReadStream ReadStream]</code>,<code>WriteStream</code>,<code>[http://live.exept.de/ClassDoc/classDocOf:,EncodedStream EncodedStream]</code><br><code>[http://live.exept.de/ClassDoc/classDocOf:,ExternalStream ExternalStream]</code>, <code>[http://live.exept.de/ClassDoc/classDocOf:,FileStream FileStream]</code>, <code>[http://live.exept.de/ClassDoc/classDocOf:,Socket Socket]</code>, <code>[http://live.exept.de/ClassDoc/classDocOf:,PipeStream PipeStream]</code> (OS-cmd streams) |
||
|- |
|- |
||
| Low Level Access |
| Low Level Access |
||
| <code>OperatingSystem</code> (OS API calls)<br><code>Smalltalk</code>(startup, shutdown and globals)<br><code>ObjectMemory |
| <code>[http://live.exept.de/ClassDoc/classDocOf:,OperatingSystem OperatingSystem]</code> (OS API calls)<br><code>[http://live.exept.de/ClassDoc/classDocOf:,Smalltalk Smalltalk]</code>(startup, shutdown and globals)<br><code>[http://live.exept.de/ClassDoc/classDocOf:,ObjectMemory ObjectMemory]</code>(VM access) |
||
|} |
|} |
||
| Zeile 311: | Zeile 443: | ||
v1 := 42. |
v1 := 42. |
||
Transcript showCR: e'the root of the answer to all questions is: {v1 sqrt}'. |
Transcript showCR: e'the root of the answer to all questions is: {v1 sqrt}'. |
||
enumerating elements of an array: |
|||
exampleMethod2 |
exampleMethod2 |
||
| Zeile 319: | Zeile 453: | ||
Transcript showCR: el |
Transcript showCR: el |
||
] |
] |
||
enumerating elements of an array with additional index: |
|||
exampleMethod3 |
exampleMethod3 |
||
| Zeile 327: | Zeile 463: | ||
Transcript showCR: e'array element at {idx} is {el} and its class is {el class name}\n' |
Transcript showCR: e'array element at {idx} is {el} and its class is {el class name}\n' |
||
] |
] |
||
dialogs, string-to-number conversion, error handling: |
|||
exampleMethod4 |
exampleMethod4 |
||
|s1 nr1 s2 nr2| |
|s1 nr1 s2 nr2 rslt| |
||
s1 := Dialog request:'Enter the first number' initialAnswer:1. |
s1 := Dialog request:'Enter the first number' initialAnswer:1. |
||
| Zeile 350: | Zeile 488: | ||
Dialog information: e'the result is {rslt}' |
Dialog information: e'the result is {rslt}' |
||
dialogs, error handling and complex square root: |
|||
exampleMethod4 |
|||
|s nr rslt| |
|||
s := Dialog request:'Enter a number (may be negative)' initialAnswer:2. |
|||
s isNil ifTrue:[ ^ self ]. "/ cancelled - return from method |
|||
"/ convert; on error return from method |
|||
nr := Number readFrom:s onError:[^ self]. |
|||
"/ square root; catch imaginary result |
|||
[ |
|||
rslt := nr sqrt |
|||
] on: ImaginaryResultError do:[:ex | |
|||
(Dialog confirm: e'No solution in R; want to see the complex result?') |
|||
ifFalse:[^ self]. "/ no; return from method |
|||
rslt := Number trapImaginary:[ nr sqrt ]. |
|||
"/ rslt is now a complex number |
|||
]. |
|||
Dialog information: e'the result is {rslt}' |
|||
== Standard == |
|||
The ANSI Smalltalk standard was approved on May 19, 1998. The official name of the document is ANSI INCITS 319-1998 (R2002). You can order a copy of the final standard |
|||
from here: [http://www.techstreet.com/cgi-bin/detail?product_id=56122] |
|||
or here [http://webstore.ansi.org/ansidocstore/product.asp?sku=ANSI+INCITS+319%2D1998+%28R2002%29]. The name of the document is "American National Standard for Information Systems - Programming Languages - Smalltalk". |
|||
You can also download the final draft revision for free: standard_v1_9-indexed.pdf and at [https://wiki.squeak.org/squeak/uploads/172/standard_v1_9-indexed.pdf]. |
|||
The final draft is identical to the official standard except that the draft also has a rationale included (and thus, the draft is arguably more useful than the official standard). |
|||
Protocol from ANSI Meeting: [http://www.netjam.org/smalltalk/faq/ANSI-meeting.html] |
|||
== Common Language Extensions == |
|||
These are also found in other Smalltalk dialects (eg. [[Glossary#VW|VW]] or [[Glossary#Squeak|Squeak]]) |
|||
* { expr1 . expr2 . ... }<br>Brace Array Construction<br>Each expression is evaluated (left to right), and an Array with the results is created at execution time.<br>Notice that separating full stops are required, as opposed to constant literal arrays, where elements are separated by spaces. The generated Array is mutable (can be modified), whereas a constant array is not. |
|||
== Summary of Smalltalk/X Language Extensions == |
|||
These are ST/X specific, and not (as of 2026) implemented in other Smalltalk systems. |
|||
=== Comments === |
|||
* "/<br>End of line comment |
|||
* "<<X<br> ... <br>X<br>token delimited comment;<br>X can be any word and a line starting with X ends the comment |
|||
=== String Literals === |
|||
* c'...'<br>''c-strings''<br>C-like escapes (\n, \t, \xNN, \uNNNN) inside the string are expanded. |
|||
* e' ... {expr} ...'<br>''e-strings'' (expanded epression strings)<br>In addition to C-escapes, embedded expressions are evaluated and their printString is sliced in. Technically, it is converted to ' ... %1 ...' and then expanded using standard String methods. |
|||
* i' ... {expr} ...'<br>''i-strings'' (international strings)<br> similar to e-strings, but the converted string ('... %1 ...') is translated to a national string (via the *.rs file) and then expanded. Allows for different word ordering. |
|||
=== Integer Literals === |
|||
* 0xNNNN, 0oNNNN, 0bNNNN<br>C-style hex, octal and binary integers.<br>With arbitrary precision |
|||
=== Float Literals === |
|||
* <f>q, <f>Q, etc.<br>Float literal type suffix (q, Q, QD, QL, QO)<br>For a complete list and spec., see the Number documentation. |
|||
=== Compact Number Arrays === |
|||
* #u1, #u8, #u16, #u32, #u64<br>#i8, #i16, #i32, #i64<br>#f16, #bf16, #f32, #f64<br>Will generate dense packed vectors (similar to byteArray); format is #X(n1 n2 ... ) |
|||
Aktuelle Version vom 7. Juni 2026, 07:15 Uhr
A short, one page summary of what beginners need to know about Smalltalk/X, its syntax and most useful code fragments.
As usual, this is only a tiny fraction of what is really awailable, and you should use the builtin class browser to find many more useful functions in the system.
This page was extracted from the "Smalltalk/X Programmers guide - Smalltalk/X Cheat Sheet".
Smalltalk/X language extensions (w.r.t. other Smalltalk implementations) are marked with (*).
Smalltalk Philosophy
A very short summary and introduction to the fundamental principles underlying the Smalltalk language.
- Everything is an Object
this includes the most basic things like numbers, strings and characters, up to complex objects like windows, editors, compilers, applications etc.
- The world consists of objects which communicate by sending messages.
(in other languages this is also known as virtual function call, but this term is not used in Smalltalk)
- A message looks like an english sentence, and might look like "
heyYou doSomething".
In this example, the "heyYou" is called the "receiver of the message" and "doSomething" is called the "message selector"
- You may pass additional parameter objects (arguments) as in: "
heyYou doSomethingWith:arg"
or multiple arguments as in "heyYou doSomethingWith:arg1 and:arg2". - In these examples, the selectors are "doSomethingWith:" and "doSomethingWith:and:" respectively
(i.e. the concatenation of the so called keywords).
They are two different messages with different selectors.
In contrast to most other languages, this is not the same message with different number of arguments, but two completely different messages).
- Messages without argument are called "unary messages"; those with arguments are called "keyword messages"
- For example "
Transcript clear" sends the message "clear" to the Transcript object; a unary message, - and "
Transcript show:'hello'" sends the message "show:" to the Transcript, passing a string argument; a keyword message
- To allow for arithmetic operations, any non-letter character (except for a few) are treated like a message name and written between the receiver and the one and only argument. These are called "binary messages".
- For example:
"3+4"or"abc,def"(yes, the comma is an operator; it does string concatenation).
You can place whitespace anywhere between selectors, keywords and arguemnts (eg."3 + 4"and"3+4"are the same).
- An object may respond (or "answer") by returning a result object. In the above example, "
3+4" would answer "7", and "'hello' , 'world'" would answer 'helloworld'
- binary messages have no meaning to the compiler; they all have equal precedence and are evaluated from left to right.
- Admitted, this makes arithmetic a little strange initially;
you'll need parentheses as there is not precedence of eg. * over +.
The expression "3 + 4 * 5" will be evaluated left to right and answer 35.
- Everything in this world is an object;
from low level things like booleans, true, false, integer numbers, floating point numbers characters etc. to the most complex objects.
- Objects can refer to (i.e. hold references) to other objects. Technically, all such references are via pointers. There is no way to directly embed an object into another object, except by reference.
- Every object is associated to a class. Classes define the behavior of their instances. I.e. they define how they respond to messages. The response is implemented by a so called method. That is a piece of code which is executed when a message comes in. A method consist of a number of statements (which are mostly message sends), each separated by a full stop (as in english).
- Inside a method, the receiver object (the object which got the message and is now executing the method) is called the receiver and refered to by the reserved word "
self".
- Classes are themself objects, which respond to messages. Typically class messages would answer new instances, constants or implement utility functionality. There are also class messages to create new classes.
- Class can inherit common functionality (i.e. method implementations) from a superclass. Thus creating a hierarchy of classes. Typical hierarchies are the Number hierarchy, Collections, Streams and UI Widgets.
- Inside a method, the special reserved word "
super" also refers to the current receiver, but message sends will ignore any method implemented in the methods class, but instead look for inherited (superclass) methods.
- In Smalltalk, every behavior is defined by corresponding message implementations. This includes control features (i.e. if-then-else, loops and exception handling). All of them are implemented as messages being sent to booleans (
ifTrue:/ifFalse:) or blocks (whileTrue:)
- Blocks are objects, which wrap a piece of code.
Other languages know them as anonymous functions, lambdas or closures.<
- But the Smalltalk syntax makes them super easy to use: just write a number of expressions inside square brackets,
as in:"[ Transcript show: 10 factorial ]". - Blocks are real objects - they can be passed as argument in a message send;
for example to a boolean: "aBoolean ifTrue: [ Transcript show: 'yes' ]" - they can be stored in variables and passed around just like any other object
- blocks can receive messages, especially loop messages: "
[ a < 10] whileTrue:[ Transcript showCR: a. a := a + 1 ]", - and they can be returned from a method (answer from a message) .
- a small language and a big library
the syntax of Smalltalk is tiny and learned in minutes. The library (i.e. the classes you get) is big, flexible and extendable. The IDE is really an "integrated environment" as it is both completely implemented in Smalltalk, part of the running system (not outside), immediately updating the running system.
Syntax
Comments
| Regular comment | " this is a comment "
|
any text between double quotes |
| EOL-Comment (*) | "/ this is an End-of-Line comment
|
text from quote-slash to line end |
| Token-Comment (*) | "<<END
|
text up to line beginning with whatever token came after the initial "<<" |
Literal Constants
Numbers
| Integers | 12345-12345
|
|
| Large integers | 1234567890123456789012345…
|
arbitrary number of digits |
| Integers with radix (Smalltalk style) |
16rAFFE, 2r010101, 8r0777, 3r012012,16r-AFFE, 2r-010101
|
prepend the radix (base) any radix from 2..36 is possible (i.e. 3r222 is a ternary number) |
| Integers with radix (C style) (*) |
0xFEED-0xBEAF0b11011,-0b1100
|
C/Java/JavaScript style: prepend radix indicator ('x', 'b', 'o') One of hex, binary and octal |
| Floats (IEEE double; roughly 17 digits) |
12.456 1.234e17 -6.9 -6e-10 Float pi Float e |
called "Float", but actually hold double precision Common constants can be referred to "by name". |
| Short floats (IEEE single; roughly 8 digits) (*) |
1.234e17f-6e-10f
|
|
| Long floats (IEEE extended; roughly 20 digits) (*) |
1.234e17q-6q-10q
|
actual precision depends on the underlying CPU (x86/x86_64: 80bit; Sparc: 128 bit) |
| Quad floats; (IEEE quad; roughly 34 digits (*) |
1.234e17Q-6e-10Q
|
computed in software; therefore slower; |
| Octuple floats; roughly 60 digits (*) |
1.234e17QO-6e-10QP
|
computed in software; therefore slower; |
| Large floats; roughly 60 digits by default, but any precision possible (*) |
1.234e17QL-6e-10QL
|
computed in software; therefore slower; |
| Fractions | (1/3)(17/2)(-3/2) |
|
| ScaledDecimals | 1234.53s2
|
the number after the s specifies the number of digits |
| Complex | (1.5 + 3i)2i(3.0q + 5.0qi)
|
Characters and Strings
| Characters | $aCharacter spaceCharacter nlAlso: " null", "tab", "return", "bell"...Or: Character codePoint:n
|
Smalltalk does not support any escape sequence Common constants can be referred to "by name". |
| Strings | 'hello'
|
traditionally, Smalltalk does not support any escape sequence inside (i.e. they are what Python calls "Raw Strings") But see below... |
| Strings (C Style) (*) |
c'hello\nworld'
|
supports the common C-escape sequences, such as "\n", "\t", "\xHH", "\uXXXX" |
| Strings (with embedded expressios) (*) |
e'hello {OperatingSystem getLoginName}'
|
expanded expression strings expressions in braces are evaluated at runtime and sliced into the string (also a C-string). Similar to python's f-strings. |
| Strings (national language translated with embedded expressios) (*) |
i'hello {OperatingSystem getLoginName}'
|
international strings like above, but the string is also possibly translated to a national language |
| Symbols | #'hello'#foo#+
|
symbols are interned strings; two symbols with the same characters are guaranteed to be the identical object (not just equal) without quotes, if only alphaNumeric characters |
Arrays and Objects
| Arrays |
#( el1 el2 ... elN )
|
each element is a literal constant |
| Byte Arrays | #[ b1 b2 ... bN ]
|
each byte-element an integer constant in 0..255 |
| Special Number Arrays (*) | #XX( v1 v2 ... vN )
|
XX: is one of 'u8', 's8', 'u16', 's16', 'u32', 's32', 'u64', 's64', 'f32', 'f64' and each element being an integer or float constant |
| Immediate Inline Objects (*) | #{ foo: fooValue . bar: barValue }
|
fooValue and barValue: are constants |
Lambda Blocks (Closures)
| Without argument | [ expr1 . expr2 ... exprN ]
|
multiple expressions sep'd by period. When evaluated, the value is the value from the last expression, exprN |
| One argument | [ :arg |
| |
| Multiple arguments | [ :a1 :a2 ... :aN |
| |
| Local Variables inside a block | [ :a1 ... :aN |
|
Expressions
| Unary Expression (without argument) |
receiver messageName
|
receiver is itself either a constant, a lambda-block, a unary expression or a parenthesized expression |
| Keyword Expression (1 arg) |
receiver messageNamePart:argExpression
|
whitespace between the colon and the argExpression is optional. |
| Keyword Expression (any number of args) |
receiver
| |
| Binary Expression | receiver binOP arg
|
with binOP being any combination of special characters: * , + , - , % , & , / , \ , | , = , < , > , ? and ,
|
| Cascade Expression (multiple messages to the same receiver) |
receiver |
the receiver expression is evaluated, then multiple messages (separated by ";") are sent to this receiver. |
| Parentheses for grouping | ( any expression )
| |
| Assignment | variable := expression
|
can be used as expression. |
| Computed Array (Brace Construct) (*) | { expr1 . expr2 . ... . exprN }
|
instantiates a new Array object with elements from the expressions. |
| Computed Inline Object (*) | { foo: fooExpr . bar: barExpr }
|
fooExpr and barExpr: expressions |
| Inline string expressions (*) | e'p1{e1}p2{e2}...pN{eN}pM'
|
syntactic sugar for:('p1%1p2%2...pN%NpM' bindWith:e1 with:e2 ... with:eN)where each pI is a string with possible C-escapes and each eI is a Smalltalk expression |
| Array Indexing (*) | coll[idx]coll[idx1][idx2]coll[idx1][idx2][idx3]
|
syntactic sugar for:(coll at:idx)where coll must be an indexable collection, and idx of compatible index type. I.e. integer for array-like collections, hash-key for dictionaries, etc. Up to 4 dimensions are (currently supported) |
| Collection instantiation (*) | someClass[sz]someClass[sz][sz]... |
syntactic sugar for:(someClass new:sz)where someClass must be a collection class I.e. Array[10] creates an empty array with 10 slots. 1, 2, 3 and 4 dimensions are supported |
Remaining Syntax
| Local variables (in block or method) | | var1 var2 ... varN |
|
variable declarations must be at the beginning, before any expression. |
| Separating multiple expressions (sequence) | expr1 . expr2 . ... exprN
|
expressions (statements) are separated by fullstop (period) characters. The last expression may or may not be followed by a fullstop; if there is one, this is treated like a followup empty statement. |
| Return from method | ^ expression
|
returns from the enclosing method (also if inside a block-closure) |
Wellknown (Common) Messages
| Conditional Execution | boolExpr1 ifTrue:[ ... ] ifFalse:[ ... ]
|
variations without true-part, without false part and with the order reversed are available. |
| While-Loop (test at top) |
[ boolExpr1 ] whileTrue:[ ... ]
|
notice the receiver being a block. A whileFalse: variant is also available.
|
| Do-Loop (test at bottom) |
[ ... ] doWhile:[ boolExpr1 ]
|
notice the test being a block. A doUntil: variant is also available.
|
| For-Loop | start to:stop do:[:iterVar | ... ]
|
evaluates the block (lambda) for each value in start..stop. |
| Enumerating Collections | collection do:[:elementVar | ... ]
|
evaluates the block (i.e. lambda) for each element in the collection. |
| Evaluating a Lambda Block without arguments: with arguments: |
aBlock value
|
the number of arguments must match the number expected by the lambda (although varArg lambdas are also available) |
| Exception Handling | [ ... ] on:Error do:[:ex | ... ]
|
evaluates the first block; if an error is encountered, evaluate the handler |
Special 'Control Structures'
| Starting another Thread | p := [ ... ] fork
|
the code inside the block will execute in a separate thread |
| Creating, configuring and starting another Thread | p := [ ... ]
|
the code inside the block will execute in a separate thread |
| Terminating a Thread | p terminate
|
with p referring to the thread as created by newProcess or fork |
| Interrupting a Thread | p interruptWith:[ ... ]
|
interrupt the thread and let it execute the given code (in its interrupt seervice) |
| Exception Handling | [ ... ]
|
the handler will get an exception argument (ex), which contains additional information, and can be told how to deal with the error |
| Exception Handling - proceeding | [ ... ]
|
proceed, as if the error did not happen |
| Exception Handling - restarting | [ ... ]
|
restart the code from the beginning (usually after the handler did some cleanup, such as lazy loading a missing file...) |
| Exception Handling - printing | [ ... ]
|
contains a human readable description of the error |
| Ensure/Unwind Protect | [ ... ]
|
the ensure block will be evaluated in any case |
| Ensure/Unwind Protect | [ ... ]
|
the ifCurtailed block will be evaluated only on a non-regular exit (i.e. when an exception was raised, or the operation was aborted or the thread terminated) |
| Early exit from Loops | [:exit |
|
the block will be left, when exit is evaluated. Often used as argument of ifTrue:, as in cond ifTrue: exit |
| Queries | Query
|
to provide answers way down to whoever is interested. Queries answer nil if no one is there to answer. Queries are usually more specifically used as subclasses of Query |
| Notifications | Notification
|
to provide information way up to whoever is interested Notifications are usually more specifically used as subclasses of Notification |
| Observers 1 | foo onChange:#bla evaluate:[...].
|
observer with generic block to evaluate |
| Observers 2 | foo onChangeSend:#xyz to:someone.
|
observer with message send |
| Observers 3 | foo addDependent:someone.
|
observer with send to update method of target |
Queries and Notifications can be seen as observers within the calling hierarchy (i.e. information flows up or down the calling hierarchy), whereas the dependency and anChange mechanisms are independent of the control flow (even between different threads)
Synchronization and Timers
| Timed Delay | Delay waitForSeconds:nDelay waitUntil:(Timestamp now + 10 seconds)
|
self explaining |
| Sempaphore wait | s := Semaphore new.
|
obviously, the signalling must be evaluated by another thread |
| Sempaphore wait with timeout | s := Semaphore new.
|
obviously, the signalling must be evaluated by another thread |
| Multi Sempaphore wait | s1 := Semaphore new.
|
wait for any of multiple semaphores |
| Synchronized Collections | a := OrderedCollection new asSharedCollection
|
will wrap the collection so that add/remove operations are atomic |
Wellknown Globals
| Logging and Messaging | Transcript - the console windowStdout - standard outputStderr - standard errorStdin - standard inputLogger - redefinable logger (defaults to standard error)
|
| Common Useful Dialogs | Dialog - provides many useful utility functions for standard dialogseg.
|
Most Wellknown Classes
| Numbers | Number(abstract superclass)Integer(integral numbers)Float(inexact)Fraction(exact)Complex
|
| Collections | Array (fixed size array)OrderedCollection, List (variable size)SortedCollectionSet, Bag (unordered)Dictionary (mapped collections)BinaryTree, AVLTreeSharedQueue (shared, synchronized)many more... |
| Process Handling | Process (lightweight thread)OSProcess (heavyweight OS process)Semaphore, RecursionLock (synchronization)Monitor, BoltLockDelay (time delays)
|
| Files & Streams | Filename (file naming, directory access, mime type)Stream (basic stream framework)
|
| Low Level Access | OperatingSystem (OS API calls)Smalltalk(startup, shutdown and globals)ObjectMemory(VM access)
|
Examples
exampleMethod1
|v1 v2|
v1 := 42.
v2 := v1 sqrt.
Transcript showCR: 'the root of the answer to all questions is: %1' with: v2.
using expanded strings, this can be written as:
exampleMethod1_alternative
|v1|
v1 := 42.
Transcript showCR: e'the root of the answer to all questions is: {v1 sqrt}'.
enumerating elements of an array:
exampleMethod2
|arr|
arr := #( 1 2.0 'three' (4 4 4 4) ).
arr do:[:el |
Transcript showCR: el
]
enumerating elements of an array with additional index:
exampleMethod3
|arr|
arr := #( 1 2.0 'three' (4 4 4 4) ).
arr doWithIndex:[:el :idx |
Transcript showCR: e'array element at {idx} is {el} and its class is {el class name}\n'
]
dialogs, string-to-number conversion, error handling:
exampleMethod4
|s1 nr1 s2 nr2 rslt|
s1 := Dialog request:'Enter the first number' initialAnswer:1.
s1 isNil ifTrue:[ ^ self ]. "/ cancelled - return from method
s2 := Dialog request:'Enter the second number' initialAnswer:2.
s2 isNil ifTrue:[ ^ self ]. "/ cancelled - return from method
"/ convert; on error return from method
nr1 := Number readFrom:s1 onError:[^ self].
nr2 := Number readFrom:s2 onError:[^ self].
"/ save division
[
rslt := nr1 / nr2
] on: Error do:[:ex |
(Dialog confirm: e'Error encountered: {ex description}\nProceed with zero?')
ifFalse:[^ self]. "/ no; return from method
ex proceedWith:0
].
Dialog information: e'the result is {rslt}'
dialogs, error handling and complex square root:
exampleMethod4
|s nr rslt|
s := Dialog request:'Enter a number (may be negative)' initialAnswer:2.
s isNil ifTrue:[ ^ self ]. "/ cancelled - return from method
"/ convert; on error return from method
nr := Number readFrom:s onError:[^ self].
"/ square root; catch imaginary result
[
rslt := nr sqrt
] on: ImaginaryResultError do:[:ex |
(Dialog confirm: e'No solution in R; want to see the complex result?')
ifFalse:[^ self]. "/ no; return from method
rslt := Number trapImaginary:[ nr sqrt ].
"/ rslt is now a complex number
].
Dialog information: e'the result is {rslt}'
Standard
The ANSI Smalltalk standard was approved on May 19, 1998. The official name of the document is ANSI INCITS 319-1998 (R2002). You can order a copy of the final standard from here: [1] or here [2]. The name of the document is "American National Standard for Information Systems - Programming Languages - Smalltalk".
You can also download the final draft revision for free: standard_v1_9-indexed.pdf and at [3].
The final draft is identical to the official standard except that the draft also has a rationale included (and thus, the draft is arguably more useful than the official standard).
Protocol from ANSI Meeting: [4]
Common Language Extensions
These are also found in other Smalltalk dialects (eg. VW or Squeak)
- { expr1 . expr2 . ... }
Brace Array Construction
Each expression is evaluated (left to right), and an Array with the results is created at execution time.
Notice that separating full stops are required, as opposed to constant literal arrays, where elements are separated by spaces. The generated Array is mutable (can be modified), whereas a constant array is not.
Summary of Smalltalk/X Language Extensions
These are ST/X specific, and not (as of 2026) implemented in other Smalltalk systems.
Comments
- "/
End of line comment - "<<X
...
X
token delimited comment;
X can be any word and a line starting with X ends the comment
String Literals
- c'...'
c-strings
C-like escapes (\n, \t, \xNN, \uNNNN) inside the string are expanded.
- e' ... {expr} ...'
e-strings (expanded epression strings)
In addition to C-escapes, embedded expressions are evaluated and their printString is sliced in. Technically, it is converted to ' ... %1 ...' and then expanded using standard String methods.
- i' ... {expr} ...'
i-strings (international strings)
similar to e-strings, but the converted string ('... %1 ...') is translated to a national string (via the *.rs file) and then expanded. Allows for different word ordering.
Integer Literals
- 0xNNNN, 0oNNNN, 0bNNNN
C-style hex, octal and binary integers.
With arbitrary precision
Float Literals
- <f>q, <f>Q, etc.
Float literal type suffix (q, Q, QD, QL, QO)
For a complete list and spec., see the Number documentation.
Compact Number Arrays
- #u1, #u8, #u16, #u32, #u64
#i8, #i16, #i32, #i64
#f16, #bf16, #f32, #f64
Will generate dense packed vectors (similar to byteArray); format is #X(n1 n2 ... )