Difference between revisions of "Lianja Operators"

From Lianjapedia
Jump to: navigation, search
Line 16: Line 16:
 
Lianja supports the use of the following arithmetic operators:
 
Lianja supports the use of the following arithmetic operators:
  
{| class="wikitable" width=100%
+
{| class="wikitable" width="100%"
!width=30%|Operator||Operation||Precedence
+
!width="30%"|Operator||Operation||Precedence
 
|-
 
|-
 
|()||Parentheses||1
 
|()||Parentheses||1
Line 37: Line 37:
 
When dealing with Date data types, the operators work as follows:  
 
When dealing with Date data types, the operators work as follows:  
  
{| class="wikitable" width=100%
+
{| class="wikitable" width="100%"
!width=30%|Operator||Operation
+
!width="30%"|Operator||Operation
 
|-
 
|-
|valign=top|&#043;||<expD> + <expN> returns a date plus the number of days specified in <expN>.
+
|valign="top"|&#043;||<expD> + <expN> returns a date plus the number of days specified in <expN>.
 
|-
 
|-
|valign=top|&#045;||Returns the interval between the two dates as a number of days.
+
|valign="top"|&#045;||Returns the interval between the two dates as a number of days.
 
|-
 
|-
 
|}
 
|}
Line 59: Line 59:
 
The following comparison operators are supported in Lianja:
 
The following comparison operators are supported in Lianja:
 
   
 
   
{| class="wikitable" width=100%
+
{| class="wikitable" width="100%"
!width=30%|Operator||Operation
+
!width="30%"|Operator||Operation
 
|-
 
|-
 
|=||Equal To
 
|=||Equal To
Line 86: Line 86:
 
The following ’wildcard’ characters can be used for == pattern matching:
 
The following ’wildcard’ characters can be used for == pattern matching:
  
{| class="wikitable" width=100%
+
{| class="wikitable" width="100%"
!width=30%|Character||Action
+
!width="30%"|Character||Action
 
|-
 
|-
 
|?||Matches any one character
 
|?||Matches any one character
Line 93: Line 93:
 
|%||Matches any one character
 
|%||Matches any one character
 
|-
 
|-
|valign=top|&#042;||Matches zero or more characters
+
|valign="top"|&#042;||Matches zero or more characters
 
|-
 
|-
 
|}
 
|}
Line 99: Line 99:
 
In SQL statements, the following wildcard characters are available:
 
In SQL statements, the following wildcard characters are available:
  
{| class="wikitable" width=100%
+
{| class="wikitable" width="100%"
!width=30%|Characters||Description
+
!width="30%"|Characters||Description
 
|-
 
|-
 
|_||Matches any one character
 
|_||Matches any one character
Line 127: Line 127:
 
Lianja supports the following logical operators:
 
Lianja supports the following logical operators:
  
{| class="wikitable" width=100%
+
{| class="wikitable" width="100%"
!width=30%|Operator||Operation
+
!width="30%"|Operator||Operation
 
|-
 
|-
 
|.AND. / AND||Logical AND
 
|.AND. / AND||Logical AND
Line 180: Line 180:
 
When dealing with string data types, the + and - operators perform the following concatenation operations:  
 
When dealing with string data types, the + and - operators perform the following concatenation operations:  
  
{| class="wikitable" width=100%
+
{| class="wikitable" width="100%"
!width=30%|Operator||Operation
+
!width="30%"|Operator||Operation
 
|-
 
|-
|valign=top|&#043;||Concatenate the right hand string to the end of the left hand string.
+
|valign="top"|&#043;||Concatenate the right hand string to the end of the left hand string.
 
|-
 
|-
|valign=top|&#045;||Concatenate the right hand string to the end of the left hand string after trimming the left hand string of trailing spaces.
+
|valign="top"|&#045;||Concatenate the right hand string to the end of the left hand string after trimming the left hand string of trailing spaces.
 
|-
 
|-
 
|}
 
|}
Line 200: Line 200:
 
The following string search operators are supported in Lianja:
 
The following string search operators are supported in Lianja:
  
{| class="wikitable" width=100%
+
{| class="wikitable" width="100%"
!width=30%|Operator||Operation
+
!width="30%"|Operator||Operation
 
|-
 
|-
 
|$||Substring is Contained In
 
|$||Substring is Contained In

Revision as of 09:24, 5 February 2013

Lianja Operators

Assignment Operators

Values are assigned to memory variables using the the equals = operator.

cVar1 = 'newer value'

Note that the store command can also be used to assign values and can operate on more than one memory variable in a single command.

store 'new value' to cVar1, cVar2

Arithmetic Operators

Lianja supports the use of the following arithmetic operators:

Operator Operation Precedence
() Parentheses 1
** ^ Exponentiation 2
* Multiplication 3
/ Division 3
% Modulus/Remainder 3
+ Addition 4
- Subtraction 4

When dealing with Date data types, the operators work as follows:

Operator Operation
+ <expD> + <expN> returns a date plus the number of days specified in <expN>.
- Returns the interval between the two dates as a number of days.

Example

? 2*3^2
        18
? 2*25%7
      1.00
? date() + 30 - date()
        30

Comparison Operators

The following comparison operators are supported in Lianja:

Operator Operation
= Equal To
== Exactly Equal To / Matches Pattern
<> Not Equal To
!= Not Equal To
# Not Equal To
> Greater Than
>= Greater Than or Equal To
< Less Than
<= Less Than or Equal To

The comparison operators are always evaluated from left to right.

The following ’wildcard’ characters can be used for == pattern matching:

Character Action
? Matches any one character
% Matches any one character
* Matches zero or more characters

In SQL statements, the following wildcard characters are available:

Characters Description
_ Matches any one character
% Matches zero or more characters

Example

cStr1 = [Welcome to Lianja]
? "Lianja" $ cStr1
.T.
 
cStr2 = [Welcome]
// Compares to the end of cStr2
? cStr1 = cStr2
.T.
 
// Compare contents & size
? cStr1 == cStr2
.F.

Logical Operators

Lianja supports the following logical operators:

Operator Operation
.AND. / AND Logical AND
.OR. / OR Logical OR
.NOT./ NOT Logical NOT
! Logical NOT
.XOR. / XOR Logical Exclusive OR

The logical operators are evaluated from left to right in the following order:

  1. Statements enclosed in parentheses
  2. NOT,!
  3. AND
  4. OR, XOR

Example

? .T. and .F. or .T.
.T.

Increment and Decrement Operators

The ++ operator is used to automatically increment a previously declared numeric memory variable by one. The ++ operator must be placed at the beginning of the command line.

Example

i=0
do while i <100
    ++ i
enddo

The -- operator is used to automatically decrement a previously declared numeric memory variable by one. The -- operator must be placed at the beginning of the command line.


Example

i=100
do while i > 0
    --i
enddo

String Concatenation Operator

When dealing with string data types, the + and - operators perform the following concatenation operations:

Operator Operation
+ Concatenate the right hand string to the end of the left hand string.
- Concatenate the right hand string to the end of the left hand string after trimming the left hand string of trailing spaces.

Example

? [Hello] + [ ] + [ World]
Hello World
? [Hello     ] - [ World]
Hello World

String Search Operators

The following string search operators are supported in Lianja:

Operator Operation
$ Substring is Contained In
| Contains Substring

String Substitution Operator

&<memvar> | (<exp>)

The & string substitution or 'Macro' operator substitutes the contents of the specified <memvar> or evaluated expression, (<exp>), into the command line. To use a macro in the middle of a word, it is necessary to end the variable name with a '.'. Any type of memory variable can be substituted as a macro; expressions must be enclosed in round brackets.

Example

subscript = 10
i10i = 5
? i&subscript.i
         5

Concatenation of Strings and Other Data Types

If set strict is off, non-string expressions are automatically converted as they are added to a string. If set strict is on, expressions must be converted manually using the etos() or other data conversion functions. By default, set strict is on.

Example

set strict off
echo "This string can add numerics and dates etc. " + 100.89 + " " + date()
 
set strict on
echo "This string can add numerics and dates etc. " + str(100.89,6,2) + " " + etos(date())