11.03.2015 Views

Unicon Book

Unicon Book

Unicon Book

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

1.3. EXPRESSIONS AND TYPES 13<br />

• -t<br />

• -u<br />

turn on tracing<br />

produce a warning for undeclared variables<br />

These options can be specified in the Ui program under the Compile menu’s Compile<br />

Options command. Other options exist; consult your <strong>Unicon</strong> and Icon manual pages and<br />

platform-specific help files and release information for more details.<br />

1.3 Expressions and Types<br />

Each procedure in a <strong>Unicon</strong> program is a sequence of expressions. Expressions are instructions<br />

for obtaining values of some type, such as a number or a word; some expressions also<br />

cause side effects, such as sending data to a hardware device. Simple expressions just read<br />

or write a value stored in memory. More interesting expressions specify a computation that<br />

manipulates zero or more argument values to obtain result values by some combination of<br />

operators, procedures, or control structures.<br />

The simplest expressions are literals, such as 2 or "hello, world!". These expressions<br />

directly specify a value stored in memory. When the program runs, they do not do any<br />

computation, but rather evaluate to themselves. Literals are combined with other values to<br />

produce interesting results. Each literal has a corresponding type. This chapter focuses on<br />

the atomic types. Atomic types represent individual, immutable values. The atomic types<br />

in <strong>Unicon</strong> are integer and real (floating-point) numbers, string (a sequence of characters),<br />

and cset (a character set). Atomic types are distinguished by the fact that they have literal<br />

values, specified directly in the program code and represented as data in the compiled code.<br />

Values of other types such as lists are constructed during execution. Later chapters describe<br />

structure types that organize collections of values, and system types for interacting with<br />

the operating system via files, databases, windows, and network connections.<br />

After literals, references to variables are the next simplest form of expression. Variables<br />

are named memory locations that hold values for use in subsequent expressions. You refer<br />

to a variable by its name, which must start with a letter or underscore and may contain<br />

any number of letters, underscores, or numbers. Use names that make the meaning of the<br />

program clear. The values stored in variables are manipulated by using variable names in<br />

expressions like i+j. This expression results in a value that is the sum of the values in the<br />

variables i and j, just like you would expect.<br />

Some words may not be used as variable names because they have a special meaning<br />

in the language. These reserved words include procedure, end, while, and so on. Other<br />

special variables called keywords start with the ampersand character (&) and denote special<br />

values. For example, global variables are initialized to the null value represented by the<br />

keyword &null. Other keywords include &date, &time, and so on. Complete lists of reserved<br />

words and keywords are given in Appendix A.

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

Saved successfully!

Ooh no, something went wrong!