Smalltalk Syntax Cheat Sheet/en: Unterschied zwischen den Versionen
Cg (Diskussion | Beiträge) (Die Seite wurde neu angelegt: „A short, one page summary of what beginners need to know about Smalltalk/X (ST/X) syntax. Non standard ST/X extensions are marked with (*). <BR>A list of most…“) |
Cg (Diskussion | Beiträge) |
||
Zeile 6: | Zeile 6: | ||
=== Comments === |
=== Comments === |
||
<table border> |
<table border> |
||
<tr> |
<tr> |
||
Zeile 31: | Zeile 32: | ||
=== Literal Constants === |
|||
<table border> |
<table border> |
||
Zeile 164: | Zeile 165: | ||
</table> |
</table> |
||
=== Blocks (aka Lambdas / Closures) === |
|||
<table border> |
<table border> |
||
Zeile 192: | Zeile 193: | ||
</table> |
</table> |
||
=== Expressions === |
|||
<table border> |
<table border> |
||
Zeile 228: | Zeile 229: | ||
<tr> |
<tr> |
||
<td width="50%">Cascade Expression<br>(sending multiple messages to the same receiver)</td> |
<td width="50%">Cascade Expression<br>(sending multiple messages to the same receiver)</td> |
||
<td width="45%"><code><i>receiver</i><br> <i>message1</i> ;<br> <i>message2</i> ;<br> ...<br> <i>messageN</i></code>< |
<td width="45%"><code><i>receiver</i><br> <i>message1</i> ;<br> <i>message2</i> ;<br> ...<br> <i>messageN</i></code><p>the receiver expression is evaluated, then multiple messages (separated by ";") are sent to this receiver. |
||
<p>the receiver expression is evaluated, then multiple messages (separated by ";") are sent to this receiver. |
|||
<br>The value of the cascade is the value returned by the last message. |
<br>The value of the cascade is the value returned by the last message. |
||
</td> |
</td> |
||
Zeile 262: | Zeile 262: | ||
</table> |
</table> |
||
=== Remaining Syntax === |
|||
<table border> |
<table border> |
||
Zeile 291: | Zeile 291: | ||
</table> |
</table> |
||
=== Wellknown (Common) Messages === |
|||
<table border> |
<table border> |
||
Zeile 342: | Zeile 342: | ||
</table> |
</table> |
||
=== Wellknown Globals === |
|||
<table border> |
<table border> |
||
Zeile 359: | Zeile 359: | ||
</table> |
</table> |
||
=== Most Wellknown Classes === |
|||
==== Numbers ==== |
|||
<table border> |
<table border> |
||
<tr> |
<tr> |
||
<td width=50%>Numbers</td> |
<td width=50%>Numbers</td> |
||
⚫ | |||
⚫ | <br>[http://live.exept.de/ClassDoc/classDocOf:,Integer <code>Integer</code> ] (integral numbers),<br> [http://live.exept.de/ClassDoc/classDocOf:,Float <code>Float</code>] (inexact)<br>[http://live.exept.de/ClassDoc/classDocOf:,Fraction <code>Fraction</code>] (exact)<br>[http://live.exept.de/ClassDoc/classDocOf:,Complex <code>Complex</code>]<br>a few more... |
||
⚫ | |||
<br><code><A HREF="http://live.exept.de/ClassDoc/classDocOf:,Integer">Integer</A></code> (integral numbers),<br><code><A HREF="http://live.exept.de/ClassDoc/classDocOf:,Float">Float</A></code> (inexact) |
|||
⚫ | |||
</td> |
</td> |
||
</tr> |
</tr> |
||
</table≈> |
|||
==== Collections ==== |
|||
⚫ | |||
<tr> |
<tr> |
||
<td width=50%>Collections</td> |
<td width=50%>Collections</td> |
||
Zeile 386: | Zeile 389: | ||
</td> |
</td> |
||
</tr> |
</tr> |
||
</table≈> |
|||
==== Process Handling ==== |
|||
⚫ | |||
<tr> |
<tr> |
||
Zeile 394: | Zeile 402: | ||
</td> |
</td> |
||
</tr> |
</tr> |
||
</table≈> |
|||
==== Files & Streams ==== |
|||
<table border> |
|||
<tr> |
<tr> |
||
Zeile 404: | Zeile 417: | ||
</td> |
</td> |
||
</tr> |
</tr> |
||
</table≈> |
|||
==== Low Level Access ==== |
|||
<table border> |
|||
<tr> |
<tr> |
||
Zeile 409: | Zeile 427: | ||
<td width=45%><code>OperatingSystem</code> (OS API calls) |
<td width=45%><code>OperatingSystem</code> (OS API calls) |
||
<br><code>Smalltalk</code> (startup, shutdown and globals) |
<br><code>Smalltalk</code> (startup, shutdown and globals) |
||
<br><code>ObjectMemory </code>(VM access) |
|||
</td> |
</td> |
||
</tr> |
</tr> |
||
⚫ | |||
<H2>Command Line</H2> |
|||
A more complete description is found in the |
|||
<A href="../getstart/TOP.html#COMMANDLINE">Command Line</A> section |
|||
of the getting started document. |
|||
⚫ | |||
<tr> |
|||
<td width=50%>-I</td> |
|||
<td width=45%>ignore snapshot image |
|||
</td> |
|||
</tr> |
|||
<tr> |
|||
<td width=50%>--quick</td> |
|||
<td width=45%>quick startup; no banner shown |
|||
</td> |
|||
</tr> |
|||
<tr> |
|||
<td width=50%>--repl</td> |
|||
<td width=45%>start an interactive read-eval-print-loop |
|||
</td> |
|||
</tr> |
|||
<tr> |
|||
<td width=50%>--print <i>expr</i></td> |
|||
<td width=45%>eval expr, print its value then exit |
|||
</td> |
|||
</tr> |
|||
<tr> |
|||
<td width=50%>--eval <i>expr</i></td> |
|||
<td width=45%>eval expr (without printing) then exit |
|||
</td> |
|||
</tr> |
|||
<tr> |
|||
<td width=50%>--execute <i>filename</i></td> |
|||
<td width=45%>execute the script in fileName then exit |
|||
</td> |
|||
</tr> |
|||
<tr> |
|||
<td width=50%>--loadPackage <i>package-ID</i></td> |
|||
<td width=45%>preload a compiled smalltalk class library (package) |
|||
</td> |
|||
</tr> |
|||
<tr> |
|||
<td width=50%>--help</td> |
|||
<td width=45%>show all other command line options |
|||
</td> |
|||
</tr> |
|||
</table> |
</table> |
Version vom 4. Juli 2023, 09:52 Uhr
A short, one page summary of what beginners need to know about Smalltalk/X (ST/X) syntax.
Non standard ST/X extensions are marked with (*).
A list of most useful messages is found "List of Useful Selectors".
Inhaltsverzeichnis
Syntax[Bearbeiten]
Comments[Bearbeiten]
Regular comment | " this is a comment " |
EOL-Comment (*) | "/ this is an End-of-Line comment |
Token-Comment (*) | "<<END
|
Literal Constants[Bearbeiten]
Integers | 12345 |
Large integers | 1234567890123456789012345... (arbitrary size) |
Integers with radix | 16rAFFE 0xFEED
* the 0x, 0b variants are extensions to standard Smalltalk |
Floats (IEEE double; roughly 17 decimals) |
12.456
|
Short floats (IEEE single; roughly 8 decimals) |
1.234f17
|
Long floats (IEEE quad; roughly 20 decimals) (*) |
1.234q17
|
Fractions |
(1/3)
|
ScaledDecimal |
123.456s2
|
Characters |
$a
|
Strings |
'hello' with C-escape sequences (*):
with embedded expressions (*):
internationalization (*):
regex (*):
|
Symbols |
#'hello' #foo (without quotes, if only alphaNumeric characters) |
Arrays |
#( el1 el2 ... elN )
|
Byte arrays |
#[ b1 b2 ... bN ]
|
Special number arrays (*) |
#XX( v1 v2 ... vN )
|
Immediate Inline Objects (*) |
#{ foo: fooValue . bar: barValue }
|
Blocks (aka Lambdas / Closures)[Bearbeiten]
Without argument | [ expr1 . expr2 ... exprN ]
|
One argument | [:arg |
|
Multiple arguments | [:a1 :a2 ... :aN |
|
Expressions[Bearbeiten]
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 (sending 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 Objects (*) |
{ foo: fooExpr . bar: barExpr }
|
Remaining Syntax[Bearbeiten]
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.
|
Return from method | ^ expression
returns from the enclosing method (also if inside a block-closure) |
Wellknown (Common) Messages[Bearbeiten]
Conditional Execution | boolExpr1 ifTrue:[ ... ] ifFalse:[ ... ]
variations without true part (ifFalse:), without false part (ifTrue:) and with the order reversed (ifFalse:ifTrue:) are available. |
While-Loop | [ boolExpr1 ] whileTrue:[ ... ]
notice the receiver being a block. |
For-Loop | start to:stop do:[:iterVar | ... ]
evaluates the lambda for each value in start..stop. |
Enumerating Collections | collection do:[:elementVar | ... ]
evaluates the 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) |
Starting a background thread | aBlock fork
evaluates the lambda in a separate thread. Alternatives are "forkNamed:" to give the thread a user friendly name. |
Wellknown Globals[Bearbeiten]
Logging and Messaging | Logger - redefinable logger (defaults to standard error)
|
Most Wellknown Classes[Bearbeiten]
Numbers[Bearbeiten]
</table≈>Collections[Bearbeiten]
Numbers | Number (abstract superclass)
|
Process Handling[Bearbeiten]
Collections | <A HREF="http://live.exept.de/ClassDoc/classDocOf:,Array">Array</A> (fixed size array)
|
Files & Streams[Bearbeiten]
Process Handling | Process (lightweight thread)OSProcess (heavyweight OS process)
|
Low Level Access[Bearbeiten]
Files & Streams | Filename (file naming, directory access, mime type)
|
Low Level Access | OperatingSystem (OS API calls)
|