From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: * X-Spam-Status: No, score=1.2 required=5.0 tests=BAYES_00,FROM_WORDY, INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,37d542b9779583be X-Google-Attributes: gid103376,public From: "Nick Roberts" Subject: Re: STL in Ada Date: 1999/02/12 Message-ID: <7a3qmk$e66$1@plug.news.pipex.net>#1/1 X-Deja-AN: 443944608 References: <36be1ed2.0@d2o41.telia.com> X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 Organization: UUNET WorldCom server (post doesn't reflect views of UUNET WorldCom) Newsgroups: comp.lang.ada Date: 1999-02-12T00:00:00+00:00 List-Id: It occurs to me that Ada already has, and has always had, a standard iteration mechanism of a kind: Sequential_IO. I suggest a scheme based on two ('signature'?) packages, one to provide a framework for container types ('stores'): generic type Element_Type(<>) is private; package Communal.Storage is type Store_Type is abstract tagged limited private; ... procedure Reset (Store: in out Store_Type) is abstract; ... end Communal.Storage; and one to provide a framework for iteration over values in a store: with IO_Exceptions; generic type Element_Type(<>) is private; type Element_Access is access all Element_Type; package Storage is new Communal.Storage(Element_Type); type Store_Type is new Storage.Store_Type with private; package Communal.Sequential_Access is type File_Type is abstract tagged limited private; type File_Mode is (In_File, Out_File, Append_File, Access_File); procedure Open (File: in out File_Type; Mode: in File_Mode; Store: in out Store_Type'Class) is abstract; procedure Close (File: in out File_Type) is abstract; procedure Reset (File: in out File_Type; Mode: in File_Mode) is abstract; procedure Read (File: in out File_Type; Item: out Element_Type) is abstract; procedure Write (File: in out File_Type; Item: in Element_Type) is abstract; procedure Next (File: in out File_Type; Pointer: out Element_Access) is abstract; function Is_Open (File: in File_Type) return Boolean is abstract; function Mode (File: in File_Type) return File_Mode is abstract; function Store (File: in File_Type) return Storage.Store_Type'Class is abstract; function End_Of_File (File: in File_Type) return Boolean is abstract; Status_Error: exception renames IO_Exceptions.Status_Error; Mode_Error: exception renames IO_Exceptions.Mode_Error; ... end Communal.Sequential_Access; Then, an implementation of a container type CT could be declared in a package such as this: with Communal.Storage, ...; generic type Element_Type[(<>)] is private; package [...]CT_Storage is package Element_Storage is new Communal.Storage(Element_Type); ... type CT is new Element_Storage.Store_Type with private; ... end [...]CT_Storage; and this type could provide 'iterator' facilities in the following form: with Communal.Sequential_Access, ...; package CT_Storage.Sequential_Access is type Element_Access is access all Element_Type; package Element_Sequential_Access is new Communal.Sequential_Access(Element_Type,Element_Access,Element_Storage,CT); type File_Type is new Element_Sequential_Access.File_Type with private; subtype File_Mode is Element_Sequential_Access.File_Mode; procedure Open (File: in out File_Type; Mode: in File_Mode; Store: in out CT'Class) is abstract; procedure Close (File: in out File_Type) is abstract; procedure Reset (File: in out File_Type; Mode: in File_Mode); procedure Read (File: in out File_Type; Item: out Element_Type); procedure Write (File: in out File_Type; Item: in Element_Type); procedure Next (File: in out File_Type; Pointer: out Element_Access); function End_Of_File (File: in File_Type) return Boolean; Status_Error: exception renames Element_Sequential_Access.Status_Error; Mode_Error: exception renames Element_Sequential_Access.Mode_Error; ... end CT_Storage.Sequential_Access; The idea of the 'Access_File' mode is to allow access-in-place to the contents of a container, rather than reading or writing copies (which may be less efficient). In this mode, the procedure 'Next' is successively called to obtain an access value to each element in the container. Calling 'Next' in any other mode, or 'Read' or 'Write' in this mode, causes 'Mode_Error' to be raised. ------------------------------------------- Nick Roberts "The Prophylactic Didactic" ------------------------------------------- NYGREN JONAS wrote in message <36be1ed2.0@d2o41.telia.com>... [What form should an Ada iterator facility take?]