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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

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

A slash character is used for division. <strong>GNU</strong> <strong>Smalltalk</strong> will give us a number in fraction or decimal<br />

representation whichever it decides is appropriate:<br />

\\<br />

50/4<br />

25/2<br />

0.5/5<br />

0.1<br />

Double backslash character is used for modulus operation:<br />

2<br />

0<br />

5 \\ 3<br />

3 \\ 3<br />

between:and:<br />

We can control whether a number is between other numbers or not by using between:and: selector.<br />

For example, to control if 3 is between 1 and 5:<br />

3 between: 1 and: 5<br />

true<br />

As you can see GST returned an object named true. This is an instance of Boolean class which is<br />

used for determining the accuracy of a logical statement. Then, how is logical inaccuracy represented?<br />

Let's look at the result of this code:<br />

3 between: 4 and: 6<br />

false<br />

As you can see it is represented by an object named false. We will see how to use this Boolean<br />

objects more detailed on Chapter 4, Controlling the Flow of Execution.<br />

abs<br />

We use abs message to get the absolute value of a negative number:<br />

3<br />

-3 abs

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

Saved successfully!

Ooh no, something went wrong!