### Expressions

Expressions are the most important building stones of computer languages. In ChaosPro, almost anything you write is an expression. The simplest yet most accurate way to define an expression is “anything that has a value”.

The most basic forms of expressions are constants and variables. When you type `a = 5`

, you’re assigning ’5′ into `a`

. ’5′, obviously, has the value 5, or in other words ’5′ is an expression with the value of 5 (in this case, ’5′ is an integer constant).

After this assignment, you’d expect `a`

‘s value to be 5 as well, so if you wrote “b = a”, you’d expect it to behave just as if you wrote “b = 5″. In other words, a is an expression with the value of 5 as well. If everything works right, this is exactly what will happen.

Slightly more complex examples for expressions are functions. For instance, consider the following function:

real returnSomething(void) { return(5); }

Assuming you’re familiar with the concept of functions (if you’re not, take a look at the chapter about functions), you’d assume that typing “c = returnSomething()” is essentially just like writing “c = 5″, and you’re right. Functions are expressions with the value of their return value. Since “returnSomething()” returns 5, the value of the expression “returnSomething()” is 5. Usually functions don’t just return a static value but compute something.

Of course, values in ChaosPro don’t have to be integers, and very often they aren’t. ChaosPro supports several scalar datatypes: bool, int, real, complex and quaternion (scalar values are values that you can’t ‘break’ into smaller pieces, unlike arrays, for instance). Each of these scalar value types can be assigned into variables or returned from functions.

So far, users of any computer language shouldn’t feel any change. However, ChaosPro takes expressions much further, in the same way many other languages like C or Java do. ChaosPro’s language is an expression-oriented language, in the sense that almost everything is an expression. Consider the example we’ve already dealt with, “a = 5″. It’s easy to see that there are two values involved here, the value of the integer constant ’5′, and the value of “a” which is being updated to 5 as well. But the truth is that there’s one additional value involved here, and that’s the value of the assignment itself. The assignment itself evaluates to the assigned value, in this case 5. In practice, it means that “a = 5″, regardless of what it does, is an expression with the value 5. Thus, writing something like “b = (a = 5)” is like writing “a = 5; b = 5;” (a semicolon marks the end of a statement). Since assignments are parsed in a right to left order, you can also write “b = a = 5″.

A very common type of expressions are comparison expressions. These expressions evaluate to either 0 or 1, meaning FALSE or TRUE (respectively). ChaosPro supports > (bigger than), >= (bigger than or equal to), == (equal), != (not equal), < (smaller than)and <= (smaller than or equal to). These expressions are most commonly used inside conditional execution, such as if statements.