31.07.2013 Views

RAPL 3 - Reference Guide. - Phoenix Goucher

RAPL 3 - Reference Guide. - Phoenix Goucher

RAPL 3 - Reference Guide. - Phoenix Goucher

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.

32 Data Types and Variables<br />

Named Constants<br />

It is frequently useful to be able to define a named constant in a program.<br />

<strong>RAPL</strong>-3 provides a const keyword for this purpose. The format of a constant<br />

definition is:<br />

const identifier = value<br />

Note that it is not necessary to specify a type for a const definition; the compiler<br />

is able to deduce what type you are referring to by looking at the specified value.<br />

Examples of const definitions are:<br />

const x = 123 ;; an integer constant<br />

const y = 10.3 ;; a floating point constant<br />

const z = “hello” ;; a string constant<br />

Only integer, floating point and string constants may be defined in this way. You<br />

may use a named constant anywhere it would be legal to use the actual constant<br />

itself. For example, if the following definitions are in your program, then this<br />

section of code:<br />

print(“hello”, 123, 10.3)<br />

is exactly the same as this section of code:<br />

print(z, x, y)<br />

Typically, named constants are used for setting configurable values in a program.<br />

For example, if a robot program rinses a dispense head some number of times in<br />

between operations, one might have a const definition like this at the top of the<br />

program:<br />

const NUMBER_OF_RINSES = 3<br />

This way the behaviour of the program can be changed by just changing the<br />

constant, and code that refers to this number can use NUMBER_OF_RINSES,<br />

which is much more obvious than just ‘3’.

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

Saved successfully!

Ooh no, something went wrong!