Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Smalltalk
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Literals=== The following examples illustrate the most common objects which can be written as literal values in Smalltalk-80 methods. Numbers. The following list illustrates some of the possibilities. <syntaxhighlight lang="smalltalk"> 42 -42 123.45 1.2345e2 2r10010010 16rA000 </syntaxhighlight> The last two entries are a binary and a hexadecimal number, respectively. The number before the 'r' is the [[radix]] or base. The base does not have to be a power of two; for example 36rSMALLTALK is a valid number equal to 80738163270632 decimal. Characters are written by preceding them with a dollar sign: <syntaxhighlight lang="smalltalk">$A</syntaxhighlight> Strings are sequences of characters enclosed in single quotes: <syntaxhighlight lang="smalltalk">'Hello, world!'</syntaxhighlight> To include a quote in a string, escape it using a second quote: <syntaxhighlight lang="smalltalk">'I said, ''Hello, world!'' to them.'</syntaxhighlight> Double quotes do not need escaping, since single quotes delimit a string: <syntaxhighlight lang="smalltalk">'I said, "Hello, world!" to them.'</syntaxhighlight> Two equal strings (strings are equal if they contain all the same characters) can be different objects residing in different places in memory. In addition to strings, Smalltalk has a class of character sequence objects named Symbol. Symbols are guaranteed to be unique—there can be no two equal symbols which are different objects. Because of that, symbols are very cheap to compare and are often used for language artifacts such as message selectors (see below). Symbols are written as # followed by a [[string literal]]. For example: <syntaxhighlight lang="smalltalk">#'foo'</syntaxhighlight> If the sequence does not include whitespace or punctuation characters, this can also be written as: <syntaxhighlight lang="smalltalk">#foo</syntaxhighlight> Arrays: <syntaxhighlight lang="smalltalk">#(1 2 3 4)</syntaxhighlight> defines an array of four integers. <syntaxhighlight lang="smalltalk">#((1 2 3 4) [1 2 3 4] 'four' 4.0 #four)</syntaxhighlight> defines a seven element array whose first element is a literal array, second element a byte array, third element the string 'four', and so on. Many implementations support the following literal syntax for ByteArrays: <syntaxhighlight lang="smalltalk">#[1 2 3 4]</syntaxhighlight> defines a ByteArray of four integers. And last but not least, blocks ([[anonymous function]] literals) <syntaxhighlight lang="smalltalk">[... Some smalltalk code...]</syntaxhighlight> The following takes two arguments and compares any two objects which can understand "less than", for example, numbers, and strings<syntaxhighlight lang="smalltalk">[:a :b| a < b]</syntaxhighlight> Blocks are explained in detail further in the text. Many Smalltalk dialects implement additional syntaxes for other objects, but the ones above are the essentials supported by all.
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Smalltalk
(section)
Add topic