home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / oper_sys / emerald / emrldsys.lha / Language / Compiler / Builtins / Vector.m < prev    next >
Encoding:
Text File  |  1990-08-16  |  2.2 KB  |  73 lines

  1. % @(#)Vector.m    1.2  10/5/87
  2. %
  3. export _VectorObject to "Builtins"
  4.  
  5. const _VectorObject == 
  6.   immutable object _VectorObject
  7.     export of
  8.     function of [ElementType : AbstractType] -> [result : NVT]
  9.       where
  10.     NVT ==    immutable type NVT
  11.           operation create [Integer] -> [NV]
  12.           function getSignature -> [Signature]
  13.         end NVT
  14.     NV ==    type NV
  15.           function  getElement [Integer] -> [ElementType]
  16.             % get the element indexed by index, failing if index 
  17.             % out of range.
  18.           operation setElement [Integer, ElementType]
  19.             % set the element, failing if index out of range
  20.           function  upperbound -> [Integer]
  21.             % return the highest valid index, ub.
  22.           function  lowerbound -> [Integer]
  23.             % return the lowest valid index, always 1.
  24.           function  getSlice [Integer, Integer] -> [NV]
  25.             % See implementation comment
  26.         end NV
  27.     ElementType *> type T end T
  28.       end where
  29.       result <- 
  30.     immutable object aNVT
  31.       export create, getSignature
  32.  
  33.       function getSignature -> [result : Signature]
  34.         result <- NV
  35.       end getSignature
  36.  
  37.       operation create[length : Integer] -> [result : NV]
  38.         result <-
  39.           object aNV
  40.         export getElement, setElement, upperbound, lowerbound,
  41.               getSlice
  42.  
  43.         function  getElement [index : Integer] -> [result : ElementType]
  44.           % get the element indexed by index, failing if index 
  45.           % out of range.
  46.           primitive 012 [result] <- [index]
  47.         end getElement
  48.         operation setElement [index : Integer, e : ElementType]
  49.           % set the element, failing if index out of range
  50.           primitive 112 [] <- [index, e]
  51.         end setElement
  52.         function  upperbound -> [r : Integer]
  53.           % return the highest valid index, ub.
  54.           primitive 212 [r] <- []
  55.         end upperbound
  56.         function  lowerbound -> [r : Integer]
  57.           % return the lowest valid index, always 1.
  58.           primitive 312 [r] <- []
  59.         end lowerbound
  60.         function  getSlice [i1 : Integer, length : Integer] -> [r : NV]
  61.           % return a new Vector, a, with lower bound 0, and 
  62.           % upper bound length-1, such that for 0 <= i < length:
  63.           %     self.getElement[i1+i] == a.getElement[i]
  64.           % fail if i1 or i1+length is out of range.
  65.           primitive 412 [r] <- [i1, length]
  66.         end getSlice
  67.           end aNV
  68.       end create
  69.     end aNVT
  70.     end of
  71.   end _VectorObject
  72.