Expressions Cheat Sheet

Page Status: Beta
Jump to: navigation, search

Back to Quick Reference

Contents

[edit] Unary operators

- — Negation operator, returns the negation of the following numeric value. This only works on numeric values.

! — Logical negation operator

[edit] Examples

 

var int32 foo = -5;
var boolean truevalue = true;
var boolean falsevalue = !truevalue;

 

[edit] Multiplicative operators

* — Multiplication, returns the result of multiplying the two sides.
/ — Division, returns the result of dividing the first side by the second.
% — Modulus, returns the remainder from doing integer division

[edit] Examples

var int32 foo = 42;
var int32 bar = 24;
var int32 result;
result = foo * bar; // answer is 1008
result = foo / bar; // answer is 1
result = foo % bar; // answer is 18

[edit] Additive operators

+ — Addition (or concatenation, if either operand is a string)

- — Subtraction

[edit] Examples

var int32 foo = 42;
var int32 bar = 24;
var string three = '3';

var int32 result;

result = foo + bar;     // answer is 66
result = foo – bar;     // answer is 18

result = three + foo;   // answer is '342'
result = bar + three;   // answer is '243'

result = three + three; // answer is '33'

[edit] Relational and Equality operators

< — Less Than

<= — Less Than Or Equal

> — Greater Than

>= — Greater Than Or Equal

== — Equal To

!= — Not Equal To

isa — Tests to determine if a field or variable is a particular type. Note that the type name must be a string enclosed in quotes.

[edit] Examples

<p>var int32 foo = 42;
var int32 bar = 24;
var Biz baz = new Biz;
var boolean result;
result = foo < bar;
result = foo <= bar;
result = foo > bar;
result = foo >= bar;
result = foo == bar;
result = foo != bar;
result = baz isa "Biz"; // result is true
result = bas isa "NonBiz"; // result is false
result = foo isa "integer"; // result is always false because "integer" (int) is not a complex type</p>

[edit] Using isa with Primitives

When performing isa tests with primitives, you must use sometimes use alternate names according to the following chart

primitive name to use in isa expressions
Data  
boolean  
char  
date  
datetime  
decimal  
double  
float  
int  integer
int16  
int32  
int64  
long  
string string
uchar  
uint  
uint16  
uint32  
uint64  
ulong  

[edit] Conditional operators

? : — Ternary Conditional, operates like the ternary operator in c/c++

CAVEAT Currently, the inline "if" operator (condition?branch_if_true:branch_if_false) has higher precedence than the concatenation operator. For example, if you have an inline if set to an expression containing true?"true"+"=1":"false"+"=0", then it will evaluate to "true=1=0". The work around is to use parenthesis, for example: true ? ("true" + "=1") : ("false" + "=0")

[edit] Examples

var int32 first = 42;
var int32 second = 24;
var int32 result;
result = (first > second) ? first : second; // result is set to first

[edit] Logical Operators

&& — Logical AND

|| — Logical OR (||)

[edit] Examples

 

var boolean foo = true;
var boolean bar = false;
var boolean result;
result = foo && bar; // result is false
result = foo || bar; // result is true

 

[edit] Bitwise Operators

& — Bitwise AND

| — Bitwise OR

[edit] Examples

 

var int result;
var int test = 42;
result = test & 32; // [HEX: 0x2A & 0x20 = 0x20] [BINARY: 101010 & 100000 = 100000]
result = test | 21; // [HEX: 0x2A | 0x15 = 0x3F] [BINARY: 101010 & 010101 = 111111]

 

[edit] Constant Operators

null — The constant for a null object reference, similar to a NULL pointer in c/c++.

true — The constant for the boolean true value.

false — The constant for the boolean false value.

today — Returns the current date & time.

now — Returns the current date & time.

none — Indicates that a dateTime (type) is not set.

nonedate — Indicates that a date (type) is not set.

luid — Returns a locally unique identifier.

guid — Returns a globally unique identifier.

[edit] Examples

var Foo foo;
var boolean result;
var dateTime rightNow;
var date present;
var string identifier;
foo = null;
result = true;
result = false;
rightNow = today;
rightNow = now;
rightNow = none;
present = today;
present = now;
present = nonedate;
identifier = luid;
identifier = guid;

[edit] Special Characters

You can encode special characters using a backslash and letter combination.

\t — Tab

\n — Line break

\n\r — Carriage return

This special characters list is incomplete. If you need a code for a special character, you can get help in the Q & A Knowledgebase.

    Copyright © 2005 - 2008 Bungee Labs. All rights reserved.