Previous | Table of Contents | Next |
Character objects make up the individual elements of strings and can be expressed using character literals. Character objects conform to the protocol <Character>:
Protocol <Character> | Conforms to: <magnitude> |
Messages: | |
asLowercase ^ <Character> | If the receiver is an uppercase letter, returns its lowercase equivalent |
asString ^ <string> | Creates a string object containing only the receiver |
asUppercase ^ <Character> | If the receiver is a lowercase letter, returns its uppercase equivalent |
codePoint ^ <integer> | Returns the encoding of the receiver in the implementation-dependent character set |
isAlphaNumeric ^ <boolean> | Tests whether receiver is either a letter or a digit |
isDigit ^ <boolean> | Tests whether the receiver is numeric character |
isLetter ^ <boolean> | Tests whether the receiver is an alphabetic character |
isLowercase ^ <boolean> | Tests whether the receiver is a lowercase letter |
isUppercase ^ <boolean> | Tests whether the receiver is an uppercase letter |
Character objects represent individual entries in an implementation-dependent character set. ASCII and Unicode are the character sets most commonly used by Smalltalk implementations. The elements of a character set are integers that are called code points. The message codePoint, when sent to a character object, returns the corresponds code point. A character object that corresponds to a particular code point can be accessed by sending the message codePoint: to the class object named Character:
Protocol <Character class> | Conforms to: <classDescription> |
Messages: | |
codePoint: <integer> ^ <Character> | Returns the character object corresponding to a code point |
Blocks were discussed in section 4.4. They are objects that represent Smalltalk code in a bound to a specific variable environment. The messages for all blocks are defined by <block>. The applicability of other messages depends on the number of arguments defined for the block:
Protocol <block> | Conforms to: <Object> |
Messages: | |
argumentCount ^ <integer> | Number of arguments required by the block |
valueWithArguments: <Array> ^ <Object> | Evaluates the block using the arguments |
Protocol <block0> | Conforms to: <block> |
Messages: | |
ensure: <block0> ^ <Object> | Evaluates the receiver, then the cleanup block |
ifCurtailed: <block0> ^ <Object> | Evaluates the receiver protected by a cleanup block |
on: <exceptionSelector> do: <block1> ^ <Object> | Evaluates the receiver in the context of an exception handler |
value ^ <Object> | Evaluates the receiver |
whileFalse | Repetitively evaluates the receiver until it returns true |
whileFalse: <block0> | Repetitively evaluates the receiver until it returns true; after each evaluation, except the last, evaluates the argument |
whileTrue | Repetitively evaluates the receiver until it returns false |
whileTrue: <block0> | Repetitively evaluates the receiver until it returns false; after each evaluation except the last, evaluate the argument |
Protocol <block1> | Conforms to: <block> |
Messages: | |
value: <Object> ^ <Object> | Evaluates the receiver |
Protocol <block2> | Conforms to: <block> |
Messages: | |
value: <Object> value: <Object> ^ <Object> | Evaluates the receiver |
Exception classes and exception object were discussed previously in the chapter. Exception classes conform to the protocol <exceptionSelector>, whereas their instances conform to <signaledException>. These protocols are not described here, but examples of their usage can be found section 4.6.
Standard Smalltalk supports four basic types of numeric objects: integers, fractions, floating-point objects (also called floats), and scaled decimal objects. One or more classes can be used to implement each type of number. All numeric classes conform to the protocol <number>. Generally, the arguments to numeric messages can be instances of any class of number. Thus, mixed-mode arithmetic expressions are supported. When an arithmetic message involves different classes of numbers, the result is usually a number object of the more general type. The generality of the numeric types, in descending order is
Previous | Table of Contents | Next |