Difference between revisions of "Operator"

From Chilipedia
Jump to: navigation, search
(How It Works)
 
(One intermediate revision by the same user not shown)
Line 4: Line 4:
 
The expression <code>x + 4</code> does '''not''' increase the value stored in <code>x</code> by 4. What it does is load the value stored in x and find the sum of that value and 4. This operation results in a value, but does not have any effect. We can think of an operator as consuming the values to its right and left and emitting another value.
 
The expression <code>x + 4</code> does '''not''' increase the value stored in <code>x</code> by 4. What it does is load the value stored in x and find the sum of that value and 4. This operation results in a value, but does not have any effect. We can think of an operator as consuming the values to its right and left and emitting another value.
  
There are exceptions of course. Some operators have a side effect. For example, the assignment operator <code>=</code> has the side effect of setting the value of the operand to its left. Also, some operators (called '''unary''' operators) only take one operand (operators which take two operands are called <code>binary</code> operators).
+
There are exceptions of course. Some operators have a side effect. For example, the assignment operator <code>=</code> has the side effect of setting the value of the operand on its left. Also, some operators (called '''unary''' operators) only take one operand (operators which take two operands are called '''binary''' operators).
  
 
== List of Operators ==
 
== List of Operators ==

Latest revision as of 19:34, 6 August 2016

An operator consumes (NOM-NOM-NOM!) two (or sometimes one) operands (values) and poops out a result (value). It's just a fancy word for a simple calculation like adding or subtracting.

How It Works

The expression x + 4 does not increase the value stored in x by 4. What it does is load the value stored in x and find the sum of that value and 4. This operation results in a value, but does not have any effect. We can think of an operator as consuming the values to its right and left and emitting another value.

There are exceptions of course. Some operators have a side effect. For example, the assignment operator = has the side effect of setting the value of the operand on its left. Also, some operators (called unary operators) only take one operand (operators which take two operands are called binary operators).

List of Operators

+ and -

These guys add/subtract the values to their left and right and poop out the result. They don't have any side effect by themselves, so you have to use the result in some other operation (as a function parameter or as an operand for another operator).

Assignment Operator =

This guy sets the value of the thing to its left to the value on its right. Don't try and do something like 4 = x; it makes no goddam sense does it?