{ } Literal array and code block delimiters

 


 { }
 Literal array and code block delimiters         (Special)
------------------------------------------------------------------------------
 Syntax

     { <exp list> }                 (literal array)
     { |<param list>| <exp list> }  (code block definition)

 Operands

     <exp list> is a list of expressions of any type.  If the item is a
     literal array definition, it can contain another literal array
     definition.

     <param list> is a list of variables to receive parameters passed to
     a code block from an invocation of the EVAL() function.  The parameter
     list is comma-separated and must be enclosed by vertical bars (||).
     Variables specified in this list are declared local to the code block
     and are visible only within the code block definition.

 Description

     Curly braces ({}) delimit references to literal arrays or code blocks.
     If the reference is a literal array, you can use them to create an array
     in either an assignment or a variable declaration statement.  If the
     reference is a variable declaration, the array can contain expressions
     of any kind as elements, unless STATIC is the declaration statement.  In
     this case, the literal array can only contain constant values.

 Examples

     .  This example uses literal arrays in declaration statements to
        create a variable and initialize it with an array reference:

        LOCAL aPerson := { "Name", "Address", DATE() }
        STATIC aNumList := { 1, 2, 3, 4, 5, 6, 7, 8 }

     .  This example creates a multidimensional literal array:

        aMulti := { {1, 2, 3}, {"A", "B", "C"} }

     .  This example uses curly braces to formulate a simple code
        block with a single parameter:

        LOCAL bSayBlock
        bSayBlock := { |x| QOUT(x) }
        EVAL(bSayBlock, 10)               // Result: 10

See Also: EVAL() LOCAL PRIVATE PUBLIC STATIC

[ ] Array element indicator

 


 [ ]
 Array element indicator                         (Special)
------------------------------------------------------------------------------
 Syntax

     <aArray>[<nSubscript>, ... ]
     <aArray>[<nSubscript1>][<nSubscript2>] ...

 Operands

     <aArray> is an expression that returns a reference to an array.
     This is generally a variable identifier or instance variable.

     <nSubscript> is a numeric expression that addresses an individual
     element in the specified array or subarray.  Each subscript corresponds
     to a dimension of the array.

 Description

     The subscript operator ([]) specifies a single array element.  The name
     of a previously declared array must precede the left bracket and the
     array element subscript must appear as a numeric expression within the
     brackets.  You can make array element references using Pascal or C-style
     syntax.

 Examples

     .  This example accesses each element in a two-dimensional array
        of known dimensions:

        LOCAL i, j
        FOR i := 1 TO 5
           FOR j := 1 TO 10
              ? aOne[i, j]
           NEXT
        NEXT

     .  These examples specify an <aArray> expression:

        LOCAL aArray := { 1, 2, 3, 4, 5 }
        //
        ? ArrayFunc()[2]                     // Result: 2
        ? { {1, 2}, {3, 4} }[1][2]           // Result: 2
        ? aArray[5]                          // Result: 5

        FUNCTION ArrayFunc
           STATIC aArray := { 1, 2 }
           RETURN aArray

     .  This example queries and assigns a static array encapsulated
        within a function definition:

        ? ArrayFunc()[1]                     // Result: 1
        ArrayFunc()[1] := 10
        ? ArrayFunc()[1]                     // Result: 10

        FUNCTION ArrayFunc
           STATIC aArray := { 1, 2 }
           RETURN aArray

See Also: ARRAY() LOCAL PRIVATE PUBLIC STATIC

@ Pass-by-reference

 


 @
 Pass-by-reference--unary                        (Special)
------------------------------------------------------------------------------
 Syntax

     @<idVar>

 Operands

     <idVar> is any valid Clipper variable identifier, other than a
     database field or an array element, to pass by reference.  Database
     fields and array elements can only be passed by value.

 Description

     The pass-by-reference operator (@) passes variables by reference to
     functions or procedures invoked with function-calling syntax.  It is a
     unary prefix operator whose operand may be any variable name.

     Passing a variable by reference means that a reference to the value of
     the argument is passed instead of a copy of the value.  The receiving
     parameter then refers to the same location in memory as the argument.
     If the called routine changes the value of the receiving parameter, it
     also changes the argument passed from the calling routine.

     Passing a variable by value means that the argument is evaluated and its
     value is copied to the receiving parameter.  Changes to a receiving
     parameter are local to the called routine and lost when the routine
     terminates.  The default method of passing arguments is by value for all
     data types including references to arrays and objects.

 Examples

     .  This example demonstrates the difference between passing a
        user-defined function argument by reference and by value:

        LOCAL nNum := 1                     // Initial values

        LOCAL aArr := { "a", "b", "c" }
        //
        CLS
        // Print initial values
        ? VALTYPE(nNum), nNum
        ? VALTYPE(aArr), aArr[1], aArr[2], aArr[3]
        //
        Udf1(nNum)                          // Pass by value (default)
        ? VALTYPE(nNum), nNum               // Result:  N, 1
        //
        Udf1(aArr[1])                       // Pass by value (default)
        ? VALTYPE(aArr), aArr[1],;
              aArr[2], aArr[3]              // Result:  A, "a" "b" "c"
        //
        Udf2(aArr)                          // Pass a reference to
        ? VALTYPE(aArr), aArr[1],;          // the array (default)
              aArr[2], aArr[3]              // A, "Oi!" "b" "c"
        //
        Udf1(@nNum)                         // Force pass by reference
        ? VALTYPE(nNum), nNum               // Result:  N, 1000
        //
        Udf3(@aArr)                         // Pass array by reference
        ? VALTYPE(aArr)                     // Result:  N
        //
        RETURN NIL

        FUNCTION Udf1(nParam)               // Receive as a local
        ? nParam                            // parameter
        nParam := 1000
        ? nParam
        RETURN NIL
        //
        FUNCTION Udf2( aParam )             // Receive as a local
        ? VALTYPE(aParam), aParam[1]        // parameter
        aParam[1] := "Oi!"
        ? aParam[1]
        RETURN NIL
        //
        FUNCTION Udf3(aParam)               // Receive as a local
        ? VALTYPE(aParam), aParam[1]        // parameter
        aParam := 1000
        ? aParam
        RETURN NIL

See Also: FUNCTION PROCEDURE

>= Greater than or equal

 


 >=
 Greater than or equal--binary                   (Relational)
------------------------------------------------------------------------------
 Syntax

     <exp1> >= <exp2>

 Type

     Character, date, logical, memo, numeric

 Operands

     <exp1> and <exp2> are expressions of any data type to be
     compared.

 Description

     The greater than or equal to operator (>=) is a binary operator that
     compares two values of the same data type and returns true (.T.) if
     <exp1> is greater than or equal to <exp2>.

     .  Character:  The comparison is based on the underlying ASCII
        code.  ASCII codes for alphabetic characters are ascending (e.g., the
        code for "A" is 65 and the code for "Z" is 90).

     .  Date: Dates are compared according to the underlying date
        value.

     .  Logical: True (.T.) is greater than false (.F.).

     .  Memo: Treated the same as character.

     .  Numeric: Compared based on magnitude.

 Examples

     .  These examples illustrate how the greater than or equal
        operator (>=) behaves with different data types:

        // Character
        ? "Z" >= "A"             // Result: .T.

        ? "AZ" >= "A"            // Result: .T.
        ? "A" >= "AZ"            // Result: .F.

        // Date
        ? CTOD("12/12/88") >= ;
           CTOD("12/11/88")      // Result: .T.

        // Logical
        ? .T. >= .F.             // Result: .T.

        // Numeric
        ? 2 >= 1                 // Result: .T.
        ? 1 >= 2                 // Result: .F.
        ? 2 >= 2                 // Result: .T.

See Also: $ < <= <> = (equality) == >

> Greater than

 


 >
 Greater than--binary                            (Relational)
------------------------------------------------------------------------------
 Syntax

     <exp1> > <exp2>

 Type

     Character, date, logical, memo, numeric

 Operands

     <exp1> and <exp2> are expressions of any type to be compared.

 Description

     The greater than (>) operator compares two values of the same data type
     and returns true (.T.) if <exp1> is greater than <exp2>.

     .  Character: The comparison is based on the underlying ASCII
        code.  ASCII codes for alphabetic characters are ascending (e.g., the
        code for "A" is 65 and the code for "Z" is 90).

     .  Date: Dates are compared according to the underlying date
        value.

     .  Logical: True (.T.) is greater than false (.F.).

     .  Memo: Treated the same as character.

     .  Numeric: Compared based on magnitude.

 Examples

     .  These examples illustrate how the greater than operator (>)
        behaves with different data types:

        // Character
        ? "Z" > "A"             // Result: .T.
        ? "AZ" > "A"            // Result: .F.
        ? "A" > "AZ"            // Result: .F.

        // Date

        ? CTOD("12/12/88") > ;
           CTOD("12/11/88")     // Result: .T.

        // Logical
        ? .T. > .F.             // Result: .T.

        // Numeric
        ? 2 > 1                 // Result: .T.
        ? 1 > 2                 // Result: .F.

See Also: $ < <= <> = (equality) == >=

 

== Exactly equal

 


 ==
 Exactly equal--binary                           (Relational)
------------------------------------------------------------------------------
 Syntax

     <exp1> == <exp2>

 Type

     All

 Operands

     <exp1> and <exp2> are expressions of the same data type to be
     compared.

 Description

     The exactly equal operator (==) is a binary operator that compares two
     values of the same data type for exact equality depending on the data
     type.  It returns true (.T.) if <exp1> is equal to <exp2> according to
     the following rules:

     .  Array:  Compares for identity.  If <exp1> and <exp2> are
        variable references to the same array, returns true (.T.); otherwise,
        returns
        false (.F.).

     .  Character:  Comparison is based on the underlying ASCII code.
        ASCII codes for alphabetic characters are ascending (e.g., the code
        for "A" is 65 and the code for "Z" is 90).  Unlike the relational
        equality operator (=) , true (.T.) is returned if <exp1> and <exp2>
        are exactly equal including trailing spaces; otherwise, the
        comparison returns false (.F.).  SET EXACT has no effect.

     .  Date:  Dates are compared according to the underlying date
        value; behaves the same as the relational equality operator (=).

     .  Logical:  True (.T.) is exactly equal to true (.T.), and false
        (.F.) is exactly equal to false (.F.).

     .  Memo:  Treated the same as character.

     .  NIL:  True (.T.) if compared to a NIL value; false (.F.) if
        compared to a value of any other data type.

     .  Numeric:  Compared based on magnitude; behaves the same as the
        relational equality operator (=).

     .  Object: Treated the same as array.

 Examples

     .  These examples illustrate how the == operator behaves with
        different data types:

        // Character
        ? "A" == "A"             // Result: .T.
        ? "Z" == "A"             // Result: .F.
        ? "A" == "A "            // Result: .F.
        ? "AA" == "A"            // Result: .F.

        // Array or object

        aOne := { 1, 2, 3 }
        aTwo := { 1, 2, 3 }
        aThree := aOne
        ? aOne == aTwo           // Result: .F.
        // values within the arrays are equal, but the arrays,
        // themselves, are separate and distinct
        ? aOne == aThree         // Result: .T.

See Also: $ < <= <> = (equality) > >=

= (equality) Equal

= (equality)
 Equal--binary                                   (Relational)
------------------------------------------------------------------------------
 Syntax

     <exp1> = <exp2>

 Type

     Character, date, logical, memo, NIL, numeric

 Operands

     <exp1> and <exp2> are expressions of the same data type to
     compare.

 Description

     The equal operator (= ) compares two values of the same data type and
     returns true (.T.) if <exp1> is equal to <exp2> according to the
     following rules:

     .  Character:  The comparison is based on the underlying ASCII
        code.  ASCII codes for alphabetic characters are ascending (e.g., the
        code for "A" is 65 and the code for "Z" is 90).

        When EXACT is OFF, two character strings are compared according to
        the following rules.  assume two character strings, cLeft and cRight,
        where the expression to test is (cLeft = cRight):

        -  If cRight is null, returns true (.T.).

        -  If LEN(cRight) is greater than LEN(cLeft), returns false
           (.F.).

        -  Compare all characters in cRight with cLeft.  If all
           characters in cRight equal cLeft, returns true (.T.); otherwise,
           returns false (.F.).

        With EXACT ON, two strings must match exactly except for trailing
        blanks.

     .  Date: Dates are compared according to the underlying date
        value.

     .  Logical: True (.T.) is equal to true (.T.) and false (.F.)
        equal to false (.F.).

     .  Memo: Treated the same as character.

     .  NIL: True (.T.) if compared to a NIL value; false (.F.) if
        compared to a value of any other data type.

     .  Numeric: Compared based on magnitude.

 Examples

     .  These examples illustrate how the equal operator (=) behaves
        with different data types:

        // Character
        SET EXACT ON
        ? "123" = "123  "        // Result: .T.
        ? " 123" = "123"         // Result: .F.
        SET EXACT OFF
        ? "123" = "12345"        // Result: .F.
        ? "12345" = "123"        // Result: .T.
        ? "123" = ""             // Result: .T.
        ? "" = "123"             // Result: .F.

        // Date
        ? CTOD("12/12/88") = ;
           CTOD("12/12/88")      // Result: .T.

        // Logical
        ? .T. = .T.              // Result: .T.
        ? .F. = .T.              // Result: .F.

        // NIL
        ? NIL = NIL              // Result: .T.
        ? NIL = 12               // Result: .F.
        ? NIL = CTOD("")         // Result: .F.

        // Numeric
        ? 2 = 1                  // Result: .F.
        ? 1 = 1                  // Result: .T.

See Also: $ < <= <> == > >=

= Compound assignment

 


 = (compound assign)
 Compound assignment--binary                     (Assignment)
------------------------------------------------------------------------------
 Syntax

     <idVar>  += <cString>         (concatenation)
     <idVar>  += <nNumber>         (addition)
     <idVar>  -= <cString>         (concatenation)
     <idVar>  -= <nNumber>         (subtraction)
     <idVar>  -= <dDate>           (subtraction)
     <idVar>  *= <nNumber>         (multiplication)
     <idVar>  /= <nNumber>         (division)
     <idVar>  %= <nNumber>         (modulus)
     <idVar>  ^= <nNumber>         (exponentiation)

 Type

     Character, date, memo, numeric

 Operands

     <idVar> is a variable identifier of any storage class, including a
     field variable.  The variable must be initialized to a value before
     performing the operation.

     If the reference to <idVar> is ambiguous (i.e., not declared at compile
     time and not explicitly qualified with an alias), <idVar> is assumed to
     be MEMVAR.  You can assign field variables by declaring the field
     variable name in a FIELD statement or referring to the field name
     prefaced by the FIELD-> alias or the name of the work area.

     <cString> is the character string used in the operation with
     <idVar>.

     <nNumber> is the numeric expression used in the operation with
     <idVar>.

     <dDate> is the date value used in the operation with <idVar>.

 Description

     In addition to the simple and inline assignment operators (= and :=),
     there are a series of compound assignment operators that perform an
     operation then assign a value.  They have the form:

     <idVar> <operator>= <exp>

     Each compound assignment expression is equivalent to the assignment
     expression:

     <idVar> := ( <idVar> <operator> <exp> )

     For each data type that supports an operator, the compound assignment
     operator performs the same operation before performing the assignment
     operation.  The  following table details all of the compound operators:

     Compound Operators
     ------------------------------------------------------------------------
     Operator     Defined as     Operations
     ------------------------------------------------------------------------
     a += b       a := (a + b)   concatenation, addition
     a -= b       a := (a - b)   concatenation, subtraction
     a *= b       a := (a * b)   multiplication
     a /= b       a := (a / b)   division
     a %= b       a := (a % b)   modulus
     a ^= b       a := (a ^ b)   exponentiation
     ------------------------------------------------------------------------

     Note:  The exponentiation operator (**) does not have a
     corresponding compound assignment operator.  The exponentiation compound
     assignment operator is ^=.

     Since the compound assignment operators are based on the inline
     assignment  operator (:=), the operation returns the result of its
     operation as the value of the expression.  This means you can use these
     operators within expressions just like the inline assignment operator
     (:=).

 Examples

     .  These examples use the compound addition and concatenation
        assignment operator:

        // Character (concatenation)
        LOCAL cString := "Hello"
        ? cString += " there"           // Result: "Hello there"

        // Date (addition)
        LOCAL dDate := CTOD("12/12/90")
        dDate += 12                     // Result: 12/24/90

        // Numeric (addition)
        LOCAL nValue := 10
        ? SQRT(nValue += 15)            // Result:  5.00
        ? nValue                        // Result: 25.00

     .  These examples use the compound subtraction and concatenation
        assignment operator:

        // Character (concatenation)
        LOCAL cString := "Hello   "
        ? cString -= "There"            // Result: HelloThere

        // Date (subtraction)
        LOCAL dDate := CTOD("12/24/90")
        dDate -= 12                     // Result: 12/12/90

        // Numeric (subtraction)
        LOCAL nValue := 10
        ? newValue := (nValue -= 5) ** 2       // Result: 25
        ? nValue                               // Result:  5

     .  This example uses the compound multiplication assignment
        operator:

        LOCAL nValue := 10
        ? newValue := (nValue *= 5) + 100      // Result: 150
        ? nValue                               // Result:  50

     .  This example uses the compound division assignment operator:

        LOCAL nValue := 10
        ? newValue := (nValue /= 5) + 100      // Result: 102.00
        ? nValue                               // Result:   2.00

     .  This example uses the compound modulus assignment operator:

     LOCAL nValue := 10
        ? newValue := (nValue %= 4) * 100      // Result: 200.00

        ? nValue                               // Result:   2.00

     .  This example uses the compound exponentiation assignment
        operator:

        LOCAL nValue := 10
        ? newValue := (nValue ^= 3) + 50       // Result: 1050.00
        ? nValue                               // Result: 1000.00

See Also: % * ** + ++ – — / :=

= Simple assign

 = (assign)
 Simple assign--binary                           (Assignment)
------------------------------------------------------------------------------
 Syntax

     <idVar> = <exp>

 Type

     All

 Operands

     <idVar> is a valid variable identifier of any storage class,
     including a field variable.  If <idVar> is not visible or does not
     exist, a private variable is created and assigned the result of <exp>.

     <exp> is the expression whose result is assigned to <idVar>.

 Description

     The simple assignment operator (=) assigns a value to a variable.  It is
     identical in operation to the STORE command that initializes a single
     variable and must be specified as a program statement.  The inline
     assignment operator (:=) is like the = operator except that you can
     specify it within expressions.  If you specify the simple assign
     operator (=) within an expression, it is interpreted as the equality (=)
     operator.

     Note:  You cannot initialize a specific variable using the simple
     assign operator (=) in a declaration statement.  Only the inline assign
     (:=) operator can be used for this purpose.

     If the reference to <idVar> is ambiguous (i.e., not declared at compile
     time and not explicitly qualified with an alias), <idVar> is always
     assumed to be MEMVAR.  At runtime, if no private or public variable
     exists with the specified name, a private variable is created.  To
     assign a field variable with the = operator, you must declare the field
     variable name in a FIELD statement or refer to the field name prefaced
     by the FIELD-> alias or the name of the work area.

 Examples

     .  These examples are valid simple assignment statements:

        nValue = 25
        nNewValue = SQRT(nValue) ** 5
        nOldValue = nValue

     .  In this example, the two lines are equivalent:

        FIELD->CustAge = 20
        REPLACE CustAge WITH 20

See Also: ++ — := = (compound) STORE*

 

!= # Not equal

 


 <> != #
 Not equal--binary                               (Relational)
------------------------------------------------------------------------------
 Syntax

     <exp1> <> <exp2>
     <exp1> != <exp2>
     <exp1> #  <exp2>

 Type

     Character, date, logical, memo, NIL, numeric

 Operands

     <exp1> and <exp2> are expressions of the same data type or NIL
     to be compared for inequality.

 Description

     The not equal ( <>) operator compares two values of the same data type
     and returns true (.T.) if <exp1> is not equal to <exp2> according to the
     following rules:

     .  Character:  The comparison is based on the underlying ASCII
        code and is the inverse of the equal operator (=).  This means that
        the comparison is sensitive to the current EXACT SETting.  See the
        examples below.

     .  Date:  Dates are compared according to the underlying date
        value.

     .  Logical:  False (.F.) is not equal to true (.T.).

     .  Memo:  Treated the same as character.

     .  NIL:  All values compared to NIL other than NIL return true
        (.T.).

     .  Numeric:  Compared based on magnitude.

 Examples

     .  These examples illustrate how the not equal operator (<>)
        behaves with different data types:

        // Character
        SET EXACT ON
        ? "123" <> "12345"         // Result: .T.
        ? "12345" <> "123"         // Result: .T.
        ? "123" <> ""              // Result: .T.
        ? "" <> "123"              // Result: .T.
        SET EXACT OFF
        ? "123" <> "12345"         // Result: .T.
        ? "12345" <> "123"         // Result: .F.
        ? "123" <> ""              // Result: .F.
        ? "" <> "123"              // Result: .T.

        // Date
        ? CTOD("12/12/88") <> ;
           CTOD("12/12/88")        // Result: .F.

        // Logical
        ? .T. <> .T.               // Result: .F.
        ? .T. <> .F.               // Result: .T.

        // NIL
        ? NIL <> NIL               // Result: .F.
        ? NIL <> 12                // Result: .T.
        ? NIL <> "hello"           // Result: .T.

        // Numeric
        ? 2 <> 1                   // Result: .T.
        ? 1 <> 1                   // Result: .F.

See Also: $ < <= = (equality) == > >=