Difference between revisions of "Lianja Operators"

From Lianjapedia
Jump to: navigation, search
(Assignment Operators)
 
(String Substitution Operator)
 
(20 intermediate revisions by 3 users not shown)
Line 1: Line 1:
==Recital Operators==
+
==Lianja Operators==
 
===Assignment Operators===
 
===Assignment Operators===
 
Values are assigned to memory variables using the the equals = operator.
 
Values are assigned to memory variables using the the equals = operator.
Line 5: Line 5:
 
<code lang="recital">
 
<code lang="recital">
 
cVar1 = 'newer value'
 
cVar1 = 'newer value'
 +
</code>
 +
 +
The following assignment operator is also supported for Numeric and Character data types:
 +
 +
{| class="wikitable" width="100%"
 +
!width="30%"|Operator||Operation
 +
|-
 +
|valign="top"|+=||Adds value to existing memory variable.
 +
|-
 +
|}
 +
 +
<code lang="recital">
 +
nVar1 = 10
 +
nVar1 += 10  // 10 + 10 = 20
 +
cVar1 = "Hello "
 +
cVar1 += "World" // "Hello " + "World" = "Hello World"
 +
</code>
 +
 +
The following assignment operators are also supported for Numeric data types:
 +
 +
{| class="wikitable" width="100%"
 +
!width="30%"|Operator||Operation
 +
|-
 +
|valign="top"|-=||Subtracts value from existing memory variable.
 +
|-
 +
|valign="top"|*/||Assigns existing memory variable multiplied by value.
 +
|-
 +
|valign="top"|/=||Assigns existing memory variable divided by value.
 +
|-
 +
|valign="top"|%=||Assigns the remainder after dividing existing memory variable by value.
 +
|-
 +
|}
 +
 +
<code lang="recital">
 +
nVar1 = 20
 +
nVar1 -= 10  // 20 - 10 = 10
 +
nVar1 *= 10  // 10 * 10 = 100
 +
nVar1 /= 10  // 100 / 10 = 10
 +
nVar1 %= 3  // 10 % 3 = 1
 
</code>
 
</code>
  
Line 14: Line 53:
  
 
===Arithmetic Operators===
 
===Arithmetic Operators===
Recital supports the use of the following arithmetic operators:
+
Lianja supports the use of the following arithmetic operators:
  
{| class="wikitable"
+
{| class="wikitable" width="100%"
!Operator||Operation||Precedence
+
!width="30%"|Operator||Operation||Precedence
 
|-
 
|-
 
|()||Parentheses||1
 
|()||Parentheses||1
Line 37: Line 76:
 
When dealing with Date data types, the operators work as follows:  
 
When dealing with Date data types, the operators work as follows:  
  
{| class="wikitable"
+
{| class="wikitable" width="100%"
!Operator||Operation
+
!width="30%"|Operator||Operation
 
|-
 
|-
|&#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>.
 
|-
 
|-
|&#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 57: Line 96:
  
 
===Comparison Operators===
 
===Comparison Operators===
The following comparison operators are supported in Recital:
+
The following comparison operators are supported in Lianja:
 
   
 
   
{| class="wikitable"
+
{| class="wikitable" width="100%"
!Operator||Operation
+
!width="30%"|Operator||Operation
 
|-
 
|-
 
|=||Equal To
 
|=||Equal To
Line 86: Line 125:
 
The following ’wildcard’ characters can be used for == pattern matching:
 
The following ’wildcard’ characters can be used for == pattern matching:
  
{| class="wikitable"
+
{| class="wikitable" width="100%"
!Character||Action
+
!width="30%"|Character||Action
 +
|-
 +
|_||Matches any one character
 
|-
 
|-
 
|?||Matches any one character
 
|?||Matches any one character
 
|-
 
|-
|%||Matches any one character
+
|%||Matches zero or more characters
 
|-
 
|-
|&#042;||Matches zero or more characters
+
|valign="top"|&#042;||Matches zero or more characters
 
|-
 
|-
 
|}
 
|}
Line 99: Line 140:
 
In SQL statements, the following wildcard characters are available:
 
In SQL statements, the following wildcard characters are available:
  
{| class="wikitable"
+
{| class="wikitable" width="100%"
!Characters||Description
+
!width="30%"|Characters||Description
 
|-
 
|-
 
|_||Matches any one character
 
|_||Matches any one character
Line 107: Line 148:
 
|-
 
|-
 
|}
 
|}
 
Note: For FoxPro compatibility reasons, wildcard pattern matching is not available when [[SET COMPATIBLE|set compatible]] is set to FOXPRO/FOXBASE/FOXPLUS/VFP.
 
  
 
'''Example'''
 
'''Example'''
 
<code lang="recital">
 
<code lang="recital">
cStr1 = [Welcome to Recital]
+
cStr1 = [Welcome to Lianja]
? "Recital" $ cStr1
+
? "Lianja" $ cStr1
 
.T.
 
.T.
  
Line 127: Line 166:
  
 
===Logical Operators===
 
===Logical Operators===
Recital supports the following logical operators:
+
Lianja supports the following logical operators:
  
{| class="wikitable"
+
{| class="wikitable" width="100%"
!Operator||Operation
+
!width="30%"|Operator||Operation
 
|-
 
|-
 
|.AND. / AND||Logical AND
 
|.AND. / AND||Logical AND
Line 143: Line 182:
 
|-
 
|-
 
|}
 
|}
 
If [[SET OPTLOG|set optlog]] or the environment variable [[DB_OPTLOG]] are enabled, statements containing Logical Operators are automatically optimized in the following way:
 
 
If the Left Hand Side (LHS) of an AND statement is false, then the Right Hand Side (RHS) is parsed, but not evaluated.
 
 
If the LHS of an OR statement is TRUE, then the RHS is parsed, but not evaluated.
 
 
The above optimizations can be disabled, causing all entries with the statement to be evaluated, if [[DB_OPTLOG]] and [[SET OPTLOG|set optlog]] are disabled.
 
  
 
The logical operators are evaluated from left to right in the following order:
 
The logical operators are evaluated from left to right in the following order:
Line 158: Line 189:
 
# AND
 
# AND
 
# OR, XOR
 
# OR, XOR
 
  
 
'''Example'''
 
'''Example'''
Line 191: Line 221:
 
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"
+
{| class="wikitable" width="100%"
!Operator||Operation
+
!width="30%"|Operator||Operation
 
|-
 
|-
|&#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.
 
|-
 
|-
|&#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 209: Line 239:
  
 
===String Search Operators===
 
===String Search Operators===
The following string search operators are supported in Recital:
+
The following string search operators are supported in Lianja:
  
{| class="wikitable"
+
{| class="wikitable" width="100%"
!Operator||Operation
+
!width="30%"|Operator||Operation
 
|-
 
|-
 
|$||Substring is Contained In
 
|$||Substring is Contained In
Line 233: Line 263:
 
</code>
 
</code>
  
===Execution Operator===
+
[[&]] macro substitution is also supported in the [[Command Window]], [[Console Workspace]] and [[Console Tab]] in the App Inspector from v4.1.
The [[!]] execution operator provides the facility for running operating system commands or external programs from within the systemThe [[!!]] operator works in the same way, but any output is displayed at the current screen location rather than the top of the screen.
+
 
 +
===Concatenation of Strings and Other Data Types===
 +
If [[SET STRCONVERT|set strconvert is on]], non-string expressions are automatically converted as they are added to a stringIf [[SET STRCONVERT|set strconvert is off]], expressions must be converted manually using the [[ETOS()|etos()]] or other data conversion functions.  By default, [[SET STRCONVERT|set strconvert is off]].
  
 
'''Example'''
 
'''Example'''
 
<code lang="recital">
 
<code lang="recital">
! ps -ef
+
set strconvert on
!! ps -ef
+
echo "This string can add numerics and dates etc. " + 100.89 + " " + date()
 +
 
 +
set strconvert off
 +
echo "This string can add numerics and dates etc. " + str(100.89,6,2) + " " + etos(date())
 
</code>
 
</code>
  
===Concatenation of Strings and Other Data Types===
+
===NEW Operator===
If [[SET STRICT|set strict is off]], non-string expressions are automatically converted as they are added to a stringIf [[SET STRICT|set strict is on]], expressions must be converted manually using the [[ETOS()|etos()]] or other [[:Category:Expressions and Type Conversion|data conversion functions]].  By default, [[SET STRICT|set strict is on]].
+
The [[NEW Operator]] is used to create a new object based on a class.  [[CREATEOBJECT()]] and [[NEWOBJECT()]] can also be used to create objects.
 
+
  
 
'''Example'''
 
'''Example'''
 
<code lang="recital">
 
<code lang="recital">
set strict off
+
define class product as custom
echo "This string can add numerics and dates etc. " + 100.89 + " " + date()
+
productname = "Lianja App Builder"
 +
version = "3.4"
 +
proc init(arg1)
 +
? etos(arg1)
 +
endproc
 +
proc getver
 +
? this.version
 +
endproc
 +
enddefine
  
set strict on
+
oProduct = new product("Hello World")
echo "This string can add numerics and dates etc. " + str(100.89,6,2) + " " + etos(date())
+
oProduct.getver()
 +
? oProduct.productname
 +
 
 +
Hello World
 +
3.4
 +
Lianja App Builder
 
</code>
 
</code>
 +
[[Category:Lianja Scripting Essentials]]

Latest revision as of 05:55, 6 April 2018

Lianja Operators

Assignment Operators

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

cVar1 = 'newer value'

The following assignment operator is also supported for Numeric and Character data types:

Operator Operation
+= Adds value to existing memory variable.
nVar1 = 10
nVar1 += 10  // 10 + 10 = 20
cVar1 = "Hello "
cVar1 += "World" // "Hello " + "World" = "Hello World"

The following assignment operators are also supported for Numeric data types:

Operator Operation
-= Subtracts value from existing memory variable.
*/ Assigns existing memory variable multiplied by value.
/= Assigns existing memory variable divided by value.
%= Assigns the remainder after dividing existing memory variable by value.
nVar1 = 20
nVar1 -= 10  // 20 - 10 = 10
nVar1 *= 10  // 10 * 10 = 100
nVar1 /= 10  // 100 / 10 = 10
nVar1 %= 3   // 10 % 3 = 1

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
* 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

& macro substitution is also supported in the Command Window, Console Workspace and Console Tab in the App Inspector from v4.1.

Concatenation of Strings and Other Data Types

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

Example

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

NEW Operator

The NEW Operator is used to create a new object based on a class. CREATEOBJECT() and NEWOBJECT() can also be used to create objects.

Example

define class product as custom
	productname = "Lianja App Builder"
	version = "3.4"
	proc init(arg1)
		? etos(arg1)
	endproc
	proc getver
		? this.version
	endproc
enddefine
 
oProduct = new product("Hello World")
oProduct.getver()
? oProduct.productname
 
Hello World
3.4
Lianja App Builder