06.06.2013 Views

Computer Programming with GNU Smalltalk - Free

Computer Programming with GNU Smalltalk - Free

Computer Programming with GNU Smalltalk - Free

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

setNumerator:setDenominator:<br />

Objects, Messages and Classes: Part I 31<br />

To set the numerator and the denominator of a fraction, we use setNumerator:setDenominator<br />

message:<br />

3/4 setNumerator: 5 setDenominator: 6<br />

5/6<br />

Note that, this time we didn't need to use parenthesis because this time we send a keyword message to<br />

the expression 3/4 and binary messages already have a precedence over keyword messages.<br />

Character<br />

Characters are the single symbols we use to represent data. For example; letters, special characters like<br />

%, and digits like 9 are all characters. They are individual objects in <strong>Smalltalk</strong>. Though, to tell <strong>Smalltalk</strong><br />

environment that we want to treat a symbol as a character, we have to put a $ (dollar sign) in front of it.<br />

For example:<br />

$a<br />

$%<br />

$9<br />

And we use the same methodology to represent dollar sign itself:<br />

$$<br />

We have a lot of methods to apply on characters, some of which are mentioned below.<br />

asLowercase<br />

If you have a letter to convert into lowercase then you can use asLowercase message:<br />

$D asLowercase<br />

$d<br />

asUppercase<br />

Uppercase counterpart of asLowercase is asUppercase.<br />

$d asUppercase<br />

$D<br />

isAlphaNumeric<br />

If you have a suspicion whether a symbol is alphanumeric, then you can use isAlphaNumeric<br />

message:<br />

$% isAlphaNumeric

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!