Difference between revisions of "Recital Operators"
Barrymavin (Talk | contribs) |
Barrymavin (Talk | contribs) (→Assignment Operators) |
||
(23 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
==Recital Operators== | ==Recital Operators== | ||
===Assignment Operators=== | ===Assignment Operators=== | ||
+ | Values are assigned to memory variables using the the equals = operator. | ||
+ | |||
+ | <code lang="recital"> | ||
+ | cVar1 = 'newer value' | ||
+ | </code> | ||
+ | |||
+ | Note that the [[STORE|store]] command can also be used to assign values and can operate on more than one memory variable in a single command. | ||
+ | |||
+ | <code lang="recital"> | ||
+ | store 'new value' to cVar1, cVar2 | ||
+ | </code> | ||
+ | |||
===Arithmetic Operators=== | ===Arithmetic Operators=== | ||
+ | Recital supports the use of the following arithmetic operators: | ||
+ | |||
+ | {| class="wikitable" | ||
+ | !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: | ||
+ | |||
+ | {| class="wikitable" | ||
+ | !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''' | ||
+ | <code lang="recital"> | ||
+ | ? 2*3^2 | ||
+ | 18 | ||
+ | ? 2*25%7 | ||
+ | 1.00 | ||
+ | ? date() + 30 - date() | ||
+ | 30 | ||
+ | </code> | ||
+ | |||
===Comparison Operators=== | ===Comparison Operators=== | ||
+ | The following comparison operators are supported in Recital: | ||
+ | |||
+ | {| class="wikitable" | ||
+ | !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: | ||
+ | |||
+ | {| class="wikitable" | ||
+ | !Character||Action | ||
+ | |- | ||
+ | |?||Matches any one character | ||
+ | |- | ||
+ | |%||Matches any one character | ||
+ | |- | ||
+ | |*||Matches zero or more characters | ||
+ | |- | ||
+ | |} | ||
+ | |||
+ | In SQL statements, the following wildcard characters are available: | ||
+ | |||
+ | {| class="wikitable" | ||
+ | !Characters||Description | ||
+ | |- | ||
+ | |_||Matches any one character | ||
+ | |- | ||
+ | |%||Matches zero or more characters | ||
+ | |- | ||
+ | |} | ||
+ | |||
+ | Note: For FoxPro compatibility reasons, wildcard pattern matching is not available when [[SET COMPATIBLE|set compatible]] is set to FOXPRO/FOXBASE/FOXPLUS/VFP. | ||
+ | |||
+ | '''Example''' | ||
+ | <code lang="recital"> | ||
+ | cStr1 = [Welcome to Recital] | ||
+ | ? "Recital" $ cStr1 | ||
+ | .T. | ||
+ | |||
+ | cStr2 = [Welcome] | ||
+ | // Compares to the end of cStr2 | ||
+ | ? cStr1 = cStr2 | ||
+ | .T. | ||
+ | |||
+ | // Compare contents & size | ||
+ | ? cStr1 == cStr2 | ||
+ | .F. | ||
+ | </code> | ||
+ | |||
+ | ===Logical Operators=== | ||
+ | Recital supports the following logical operators: | ||
+ | |||
+ | {| class="wikitable" | ||
+ | !Operator||Operation | ||
+ | |- | ||
+ | |.AND. / AND||Logical AND | ||
+ | |- | ||
+ | |.OR. / OR||Logical OR | ||
+ | |- | ||
+ | |.NOT./ NOT||Logical NOT | ||
+ | |- | ||
+ | |!||Logical NOT | ||
+ | |- | ||
+ | |.XOR. / XOR||Logical Exclusive OR | ||
+ | |- | ||
+ | |} | ||
+ | |||
+ | 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: | ||
+ | |||
+ | # Statements enclosed in parentheses | ||
+ | # NOT,! | ||
+ | # AND | ||
+ | # OR, XOR | ||
+ | |||
+ | |||
+ | '''Example''' | ||
+ | <code lang="recital"> | ||
+ | ? .T. and .F. or .T. | ||
+ | .T. | ||
+ | </code> | ||
+ | |||
===Increment and Decrement Operators=== | ===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''' | ||
+ | <code lang="recital"> | ||
+ | i=0 | ||
+ | do while i <100 | ||
+ | ++ i | ||
+ | enddo | ||
+ | </code> | ||
+ | |||
+ | 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''' | ||
+ | <code lang="recital"> | ||
+ | i=100 | ||
+ | do while i > 0 | ||
+ | --i | ||
+ | enddo | ||
+ | </code> | ||
+ | |||
===String Concatenation Operator=== | ===String Concatenation Operator=== | ||
− | ===String Search | + | When dealing with string data types, the + and - operators perform the following concatenation operations: |
+ | |||
+ | {| class="wikitable" | ||
+ | !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''' | ||
+ | <code lang="recital"> | ||
+ | ? [Hello] + [ ] + [ World] | ||
+ | Hello World | ||
+ | ? [Hello ] - [ World] | ||
+ | Hello World | ||
+ | </code> | ||
+ | |||
+ | ===String Search Operators=== | ||
+ | The following string search operators are supported in Recital: | ||
+ | |||
+ | {| class="wikitable" | ||
+ | !Operator||Operation | ||
+ | |- | ||
+ | |$||Substring is Contained In | ||
+ | |- | ||
+ | ||||Contains Substring | ||
+ | |- | ||
+ | |} | ||
+ | |||
===String Substitution Operator=== | ===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''' | ||
+ | <code lang="recital"> | ||
+ | subscript = 10 | ||
+ | i10i = 5 | ||
+ | ? i&subscript.i | ||
+ | 5 | ||
+ | </code> | ||
+ | |||
===Execution Operator=== | ===Execution Operator=== | ||
+ | The [[!]] execution operator provides the facility for running operating system commands or external programs from within the system. The [[!!]] operator works in the same way, but any output is displayed at the current screen location rather than the top of the screen. | ||
+ | |||
+ | '''Example''' | ||
+ | <code lang="recital"> | ||
+ | ! ps -ef | ||
+ | !! ps -ef | ||
+ | </code> | ||
+ | |||
===Concatenation of Strings and Other Data Types=== | ===Concatenation of Strings and Other Data Types=== | ||
− | = | + | If [[SET STRICT|set strict is off]], non-string expressions are automatically converted as they are added to a string. If [[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]]. |
+ | |||
+ | |||
+ | '''Example''' | ||
+ | <code lang="recital"> | ||
+ | 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()) | ||
+ | </code> |
Latest revision as of 00:24, 3 December 2009
Contents
- 1 Recital Operators
- 1.1 Assignment Operators
- 1.2 Arithmetic Operators
- 1.3 Comparison Operators
- 1.4 Logical Operators
- 1.5 Increment and Decrement Operators
- 1.6 String Concatenation Operator
- 1.7 String Search Operators
- 1.8 String Substitution Operator
- 1.9 Execution Operator
- 1.10 Concatenation of Strings and Other Data Types
Recital 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
Recital 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 Recital:
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 |
Note: For FoxPro compatibility reasons, wildcard pattern matching is not available when set compatible is set to FOXPRO/FOXBASE/FOXPLUS/VFP.
Example
cStr1 = [Welcome to Recital] ? "Recital" $ cStr1 .T. cStr2 = [Welcome] // Compares to the end of cStr2 ? cStr1 = cStr2 .T. // Compare contents & size ? cStr1 == cStr2 .F.
Logical Operators
Recital 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 |
If 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 are disabled.
The logical operators are evaluated from left to right in the following order:
- Statements enclosed in parentheses
- NOT,!
- AND
- 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 Recital:
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
Execution Operator
The ! execution operator provides the facility for running operating system commands or external programs from within the system. The !! operator works in the same way, but any output is displayed at the current screen location rather than the top of the screen.
Example
! ps -ef !! ps -ef
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())