# LIST OF ALL SHARK EXPRESSIONS:

In SharkBase, expressions are formed from variables and constants using CONSTANTS, OPERATIONS, RELATIONS, and FUNCTIONS. This section includes the formal definitions and examples of the basic ingredients of expressions: CONSTANTS, OPERATIONS, and RELATIONS. FUNCTIONS are detailed in a separate section.

There are three types of expressions: numeric, string, and logical.

Numeric expressions are built up from numeric constants, numeric variables, and from functions that give results of numeric type; they are formed with the operations: +, -, *, /, and the parentheses: ( and ).

String expressions are formed from string constants, string variables, and from functions that give results of character type; they use the operation + and the parentheses: ( and ).

Logical expressions (also called conditions) are formed from logical constants, logical variables, functions that give results of logical type, and the results of relations; they use the logical operations: .AND., .OR., .NOT., and the parentheses: ( and ).

Examples:

In these examples, str1, str2 are string variables, num1, num2 are numeric variables, log1, log2 are logical variables:

String expressions:

str1 str1+str2 str1+TRIM(str2) str1+STR(num1+num2,10,2)+'Bach'

Numeric expressions:

num1 num1+5 (num1+5)/5 num1+(num2*VAL(str1)) LEN(str1)+LEN(TRIM(str2))+2

Conditions (logical expressions):

num1 < num2 num1+num2+LEN(str1) <> 15 .AND. .NOT. EOF (str1='Boston') .AND. (num1 <> LEN(str1)).AND.log1.AND.(.NOT.log2)

Variables are expressions which are used to represent changeable information. The values they contain can be easily changed by using Shark's many commands and functions.

A variable can stand for many different values; you can use the name of a variable in place of all the specific values you want or expect it to represent.

In Shark there are three main kinds of variables: fields, memory variables, and system variables.

FIELD VARIABLES MEMORY VARIABLES SYSTEM VARIABLES

#### CONSTANTS

There are three types of constants: numeric, logical, and string.

A numeric constant is a number (the minus sign is a part of it):

12.78 0.00064 -3.14

There are only two logical constants: T (true, also written as t, Y, and y) and F (false, also written as f, N, and n).

A string constant is a string in quotation marks:

"This is a character constant." 'This is another one, delimited with single quotation marks.' "Here's another one, enclosing a single quotation mark (apostrophe) within double quotes." "This is incorrect because the quotation marks do not match.'

#### OPERATIONS

There are three types of operations: numeric, logical, and string. Each works with constants and variables of that type, and yields a value of that type.

NUMERIC OPERATIONS:

The *numeric operations* are

+ addition - subtraction * multiplication / division 2+3.2 yields 5.2 10/4 yields 2.5

All numeric operations require two numbers to act on. - is also used to indicate that a number is negative: -2, -3.14. Instead of -QTY, write 0-QTY or -1*QTY. There are three logical operations:

.AND. .OR. .NOT.

.AND. and .OR. take two logical values and yield a logical value:

T.AND.T yields: T T.AND.F yields: F F.AND.T yields: F F.AND.F yields: F T.OR.T yields: T T.OR.F yields: T F.OR.T yields: T F.OR.F yields: F

.NOT. takes a logical value and yields a logical value (the opposite):

.NOT.T yields: F .NOT.F yields: T

STRING OPERATIONS:

There is only one string operation: + (concatenation, i.e. placing one string after another). Example:

'This is a'+' sentence.'

yields the value:

This is a sentence.

Note that one cannot mix numbers and strings:

2+'string'

will give a syntax error message (Error 1, See "Error Messages").

#### RELATIONS

A relation takes two numbers or two strings, compares them, and yields a logical value (true or false).

There are six relations that compare numbers or strings:

= equal < less than <= less than or equal to > greater than >= greater than or equal to <> not equal

For numbers, these have their usual meaning:

1<2 is true 2<1 is false 1.2<>5 is true 1.2>=1 is true

You should be careful when using = for numbers. Two numbers may be displayed as equal while, in fact, they differ in the third or fourth decimal place. Instead of

num1=num2

in many instances you could use

ABS(num1-num2) < 0.01

or

(PIC(num1-num2,'9999.99'))=0

For strings, string1=string2 is true if string2 is of the same length as string1, and the characters of string1 equal the corresponding characters of string2; if string2 has more characters, string1=string2 is always false.

However, the result of comparing strings of unequal length, in which all of string2 is exactly the same as the beginning of string1, is affected by the setting of the "EXACT" switch. If SET EXACT OFF, then such string1=string2 is true; with SET EXACT ON, it is false.

Examples:

SET EXACT OFF SET EXACT ON 'abc'='abc' true true 'abc '='abc' true false 'abc'='abc ' false false 'abc'='ab' true false 'ab'='abc' false false

To make sure that two strings are really equal, write

(string1=string2) .AND. (string2=string1)

or SET EXACT ON.

One way of remembering the above rule, is that string1=string2 if FIND with string2 finds string1.

Although this definition of string1=string2 may at first sight seem awkward, it may really be quite useful both in conversational Shark and in Shark programs. For instance, the condition to select all customers (field: CUST) whose name starts with P:

LEFT(cust,1)='P' (or less efficiently SUBSTR(cust,1,1)='P')

or

cust='P'

if SET EXACT OFF.

For strings, string1 < string2 means: in a dictionary, string1 would come before string2. Single characters are compared by their ASCII value, see the functions CHR( and RANK(. string1 is compared to string2 by comparing their first characters; if the first character of string1 is less than the first character of string2, then string1 < string2; if they are equal, then the second character of string1 is compared to the second character of string 2, and so on.

Examples:

'I am smaller' < 'I am bigger' is false 'David' < 'david' is true '122' > '17' is false '122' > '017' is true 'seven' > '7' is true

Note that in the ASCII sequence, all digits, 0 to 9, come before all upper-case letters, A to Z, which, in turn, come before all lower-case letters, a to z.

Note that strings and numbers cannot be mixed in these relations:

2 < '123'

gives a syntax error message (Error 1, see list of ERROR CODES).