Go to the first, previous, next, last section, table of contents.


4.1.2 Slices

  1. A slice denotes a one-dimensional array formed by a sequence of consecutive components of a one-dimensional array. A slice of a variable is a variable; a slice of a constant is a constant; a slice of a value is a value.

    Syntax

  2. slice ::= prefix(discrete_range)
    

    Name Resolution Rules

  3. The prefix of a slice shall resolve to denote a one-dimensional array (after any implicit dereference).
  4. The expected type for the discrete_range of a slice is the index type of the array type.

    Static Semantics

  5. A slice denotes a one-dimensional array formed by the sequence of consecutive components of the array denoted by the prefix, corresponding to the range of values of the index given by the discrete_range.
  6. The type of the slice is that of the prefix. Its bounds are those defined by the discrete_range.

    Dynamic Semantics

  7. For the evaluation of a slice, the prefix and the discrete_range are evaluated in an arbitrary order. If the slice is not a null slice (a slice where the discrete_range is a null range), then a check is made that the bounds of the discrete_range belong to the index range of the array denoted by the prefix. Constraint_Error is raised if this check fails.

    NOTES

  8. (2) A slice is not permitted as the prefix of an Access attribute_reference, even if the components or the array as a whole are aliased. See section 3.10.2 Operations of Access Types.
  9. (3) For a one-dimensional array A, the slice A(N .. N) denotes an array that has only one component; its type is the type of A. On the other hand, A(N) denotes a component of the array A and has the corresponding component type.

    Examples

  10. Examples of slices:
  11. Stars(1 .. 15)
    --  a slice of 15 characters        See section 3.6.3 String Types
    
    Page(10 .. 10 + Size)
    --  a slice of 1 + Size components  See section 3.6 Array Types
    
    Page(L)(A .. B)
    --  a slice of the array Page(L)    See section 3.6 Array Types
    
    Stars(1 .. 0)
    --  a null slice                    See section 3.6.3 String Types
    
    My_Schedule(Weekday)
    --  bounds given by subtype         See section 3.6.1 Index Constraints and Discrete Ranges, and See section 3.5.1 Enumeration Types
    
    Stars(5 .. 15)(K)
    --  same as Stars(K)                See section 3.6.3 String Types
    --  provided that K is in 5 .. 15
    


Go to the first, previous, next, last section, table of contents.