{ } 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: $ < <= <> == > >=