Table of Contents

Utilities

Miscellaneous "utility" type routihes.


These are miscellaneous utility functions and procedures that can be used with many Euphoria projects.

  • func DIMArray(sequence Dimension, object InitValue)   Creates an array (sequence) with the dimensions specified.
  • const False   Defines the Euphoria FALSE value
  • func findAltKey( key, list )   Find alternate key in list.
  • func findKey( key, list )   Find key in list.
  • func iff (atom test, object ifTrue, object ifFalse)   Used to embed an 'if' test inside an expression.
  • func insertIndex( integer index, sequence list, object Data )    Inserts Data at position index in the sequence list
  • func removeIndex( integer index, sequence list )    Remove the element at position index from the sequence list
  • func removeItem( object item, sequence list)    Removes item from the list, if it is in the list.
  • func removeKey( object item, sequence list)    Removes keyed item from the list, if it is in the list.
  • func rotate_elements( sequence list, sequence index )    moves elements about in list according to the index set.
  • const True   Defines the Euphoria TRUE value


    Table of Contents

    [func]
    DIMArray
    (sequence Dimension, object InitValue)

    Creates an array (sequence) with the dimensions specified.

    Returns: SEQUENCE: An initialised array. However if it fails an INTEGER is returned.

    Category: Utilities

    The Dimension parameter is a list of lengths for each dimension. For a 3 dimension array you would use a list of 3 lengths. Each length must be an integer with a value greater than zero.
    The InitValue is the value to set for each element. It can be any Euphoria object.

    Note that if the function fails, it returns an integer.

    Example

        object Space3D
        Space3D = DIMArray( {3, 7, 4}, 0)
        if integer(Space3D) then
            ErrAbort(sprintf("All dimensions must be positive integers; dimension %d is not.", Space3D))
        end if
    

    --------------------------------------------------------------------------

    See Also: False, findAltKey, findKey, iff , insertIndex, removeIndex, removeItem, removeKey, rotate_elements, True



    Table of Contents

    [const]
    False

    Defines the Euphoria FALSE value

    Category: Utilities

    See Also: DIMArray, findAltKey, findKey, iff , insertIndex, removeIndex, removeItem, removeKey, rotate_elements, True



    Table of Contents

    [func]
    findAltKey
    ( key, list )

    Find alternate key in list.

    Returns: Index of sublist with matching key in a specific column.

    Category: Utilities

    Example:

          -- find a value from column 2 in a list
          integer at
          at = findAltKey( 2, name, nameList )
    

    See Also: DIMArray, False, findKey, iff , insertIndex, removeIndex, removeItem, removeKey, rotate_elements, True



    Table of Contents

    [func]
    findKey
    ( key, list )

    Find key in list.

    Returns: Index of sublist with matching key.

    Category: Utilities

    Example:

          -- find a value from a list
          integer at
          at = findKey( name, nameList )
    

    See Also: DIMArray, False, findAltKey, iff , insertIndex, removeIndex, removeItem, removeKey, rotate_elements, True



    Table of Contents

    [func]
    iff
    (atom test, object ifTrue, object ifFalse)

    Used to embed an 'if' test inside an expression.

    Returns: If test is true then ifTrue is returned otherwise ifFalse is returned.

    Category: Utilities

    Example

             msg = sprintf("%s: %s", {
                          iff(ErrType = 'E', "Fatal error", "Warning"),
                          errortext } )
    

    See Also: DIMArray, False, findAltKey, findKey, insertIndex, removeIndex, removeItem, removeKey, rotate_elements, True



    Table of Contents

    [func]
    insertIndex
    ( integer index, sequence list, object Data )

    Inserts Data at position index in the sequence list

    Returns: The list with the new element.

    Category: Utilities

    If index is zero or less, the Data is added to the front of the list and if index is passed the end of the list, Data is added to the end of the list.

    Example:

          -- Insert a new name into position 4 of the list
          nameList = insertIndex( 4, nameList, "Michael Palffy" )
    

    See Also: DIMArray, False, findAltKey, findKey, iff , removeIndex, removeItem, removeKey, rotate_elements, True



    Table of Contents

    [func]
    removeIndex
    ( integer index, sequence list )

    Remove the element at position index from the sequence list

    Returns: The list without the element.

    Category: Utilities

    If index is greater than the list length, the list is returned intact. If index is less than 1, it represents the end of the list PLUS the index. So an index of '-1' means the second-last element.

    Example:

          -- Remove the 4th element from the Name List
          nameList = removeIndex( 4, nameList )
          -- Remove the last element.
          nameList = removeIndex( 0, nameList )
    

    See Also: DIMArray, False, findAltKey, findKey, iff , insertIndex, removeItem, removeKey, rotate_elements, True



    Table of Contents

    [func]
    removeItem
    ( object item, sequence list)

    Removes item from the list, if it is in the list.

    Returns: The list without the item.

    Category: Utilities

    Example

         -- Remove the name 'fred' from the list.
         nameList = removeItem("fred", nameList)
    
    --------------------------------------------------------------------------

    See Also: DIMArray, False, findAltKey, findKey, iff , insertIndex, removeIndex, removeKey, rotate_elements, True



    Table of Contents

    [func]
    removeKey
    ( object item, sequence list)

    Removes keyed item from the list, if it is in the list.

    Returns: The list without the item.

    Category: Utilities

    The difference between this and removeItem is that in this function, list is a list of sequences and item is found if it matches the first element in the sequences.
    Example

         -- Remove the tracked resource.
         ResourceList = removeKey(hWnd, ResourceList)
         -- Add new tracked item.
         ResourceList = insertIndex(0, ResourceList, {hWnd, 0, TagData})
    

    --------------------------------------------------------------------------

    See Also: DIMArray, False, findAltKey, findKey, iff , insertIndex, removeIndex, removeItem, rotate_elements, True



    Table of Contents

    [func]
    rotate_elements
    ( sequence list, sequence index )

    moves elements about in list according to the index set.

    Returns: sequence: The updated list

    Category: Utilities

    For each element of list identified in the index set, is moved

    Example: -- Swap the 3rd and 4th element. theList = rotate_elements(theList, {3,4}) -- Move 2nd to 8th, 4th to 2nd, 6th to 4th, and 8th to 6th. theList = rotate_elements(theList, {2,4,6,8})

    See Also: DIMArray, False, findAltKey, findKey, iff , insertIndex, removeIndex, removeItem, removeKey, True



    Table of Contents

    [const]
    True

    Defines the Euphoria TRUE value

    Category: Utilities

    See Also: DIMArray, False, findAltKey, findKey, iff , insertIndex, removeIndex, removeItem, removeKey, rotate_elements