From: Ted Dennison <dennison@telepath.com>
Subject: List container strawman 1.2
Date: Sat, 10 Nov 2001 03:51:15 GMT
Date: 2001-11-10T03:51:15+00:00 [thread overview]
Message-ID: <3BECA3B7.5020702@telepath.com> (raw)
I've attached a slightly updated version of the list container strawman.
This contains a few changes which I think there was consensus for, and
some oversight corrections. Specificly:
A version of Insert using a List rather than just a single element was
added.
A "Modify" routine was added.
The Done_Iterating constant was transmogrified into a Has_Item boolean
function.
Unary "+" changed to "Singleton". (I know the name is still
contravesial, but there does appear to be general agreement to not use "+".)
Added Pop functions.
Changed the name of the "Iterator" type to "Index", and
"Passive_Iterator" to "Iterator". I'm trying out this solution before
taking the more drastic step of making a safe active iterator. We don't
quite yet seem to have reached a consensus for making that drastic of a
change. However, it seems to me that the terminology I was using may
have been a bit of a stumbling block for some, so I'd like everyone to
think about it with the new name a bit and re-formulate your opinions.
As an "index" it makes sense that you would supply it along with its
List to routines, and that it isn't particularly safe, as that is how
array indexes work too.
--- code attached below ----
with Ada.Finalization;
with Ada.Streams;
-------------------------------------------------------------------------------
-- This file contains a proposal for a standard Ada list package.
--
-- version - Strawman 1.2
-------------------------------------------------------------------------------
generic
type Element is private;
package Containers.Lists.Unbounded is
-----------------------------------------------------------------------------
-- The list type. I know the name's a bit redundant, but it doesn't
look too
-- bad, and any fully-named use will have to have a different name
for the
-- package anyway.
-----------------------------------------------------------------------------
type List is private;
-----------------------------------------------------------------------------
-- List construction operations. The returned list will contain
*copies* of
-- all the elements in the source lists, so these routines could get
-- time-consuming. However, they should be useful for Lisp-like
processing.
--
-- Unary plus ("+") wasn't a big hit for the "Construct" routine, so
now I'm
-- floating "Singleton".
-----------------------------------------------------------------------------
function "&" (Left, Right : Element) return List;
function "&" (Left : Element; Right : List) return List;
function "&" (Left : List; Right : Element) return List;
function "&" (Left, Right : List) return List;
function Singleton (Initial_Element : Element) return List;
-----------------------------------------------------------------------------
-- "push" and "pop" operations. Pops on empty lists raise No_Item.
-----------------------------------------------------------------------------
No_Item : exception;
procedure Push_Front (Target : in out List; New_Element : in
Element);
procedure Pop_Front (Target : in out List; Old_Element : out
Element);
procedure Push_Back (Target : in out List; New_Element : in
Element);
procedure Pop_Back (Target : in out List; Old_Element : out
Element);
function Pop_Front (Source : List) return List;
function Pop_Back (Source : List) return List;
-----------------------------------------------------------------------------
-- Non-modifying query operations.
-----------------------------------------------------------------------------
function Is_Empty (Subject : List) return Boolean;
function Size (Subject : List) return Natural;
function Front (Subject : List) return Element;
function Back (Subject : List) return Element;
-----------------------------------------------------------------------------
-- Passive iterator. Operation will be applied on each element on
the list
-- Opertion can terminate this process early by setting Quit to True.
-----------------------------------------------------------------------------
generic
with procedure Operation (Target : in out Element; Quit : out
Boolean);
procedure Iterator (Target : in out List);
-----------------------------------------------------------------------------
-- List index routines. For an empty list, Has_Item(First) = False.
Item and
-- Remove raise No_Item if they are called when Has_Item(Location) =
False.
-- As written, a typical iteration idiom would look like:
--
-- i := My_Lists.First (My_List);
-- while My_Lists.Has_Item (i) loop
-- do stuff with My_Lists.Item(i);
-- i := My_Lists.Next (i);
-- end loop;
--
-- Another alternative using "Size" would be:
--
-- i := My_Lists.First (My_List);
-- for iteration_count in 1..My_Lists.Size (My_List) loop
-- do stuff with My_Lists.Item (i);
-- i := My_Lists.Next (i);
-- end loop;
--
-----------------------------------------------------------------------------
type Index is private;
function Has_Item (Location : Index) return Boolean;
function First (Subject : List) return Index;
function Last (Subject : List) return Index;
function Next (Location : Index) return Index;
function Previous (Location : Index) return Index;
function Item (Location : Index) return Element;
-- Ideally these routines would verify that Location was issued for
the Subject
-- list and is still valid, but that would be tough to enforce.
Better to call
-- such misuse a "bounded error", or somesuch.
-----------------------------------------------------------------------------
-- Remove the element at the given location, and advance Location to
the next
-- element.
-- If Done_Iterating then No_Item will be raised.
-- If Location=First, then Location will be set to the new First.
-- If Location=Last, then Location will be set to Done_Iterating.
-- otherwise, Location will be set to what Next was previously (the next
-- element after the removal).
-----------------------------------------------------------------------------
procedure Remove (Subject : in out List; Location : in out Index);
-----------------------------------------------------------------------------
-- Insert a copy of the given element (or list) at the given
location in the
-- list (in front of the element that is already there). Location will
-- continue to point to the same element.
-- If Done_Iterating, then the element will be put at the end of the
-- list. Otherwise, the element will be placed immediately before
the element
-- at Location. Location will continue to reference that element.
-----------------------------------------------------------------------------
procedure Insert (Subject : in out List; Location : in Index;
New_Item : in Element);
procedure Insert (Subject : in out List; Location : in Index;
New_Items : in List);
-----------------------------------------------------------------------------
-- Modify the element at the given location in the list. Location will
-- continue to point to the same element, but the value at that
location will
-- be changed to New_Value.
-- If Done_Iterating, then No_Item will be raised.
-----------------------------------------------------------------------------
procedure Modify (Subject : in out List; Location : in Index;
New_Value : in Element);
-----------------------------------------------------------------------------
-- Sorting routine.
-- To sort in increasing order, use the ">" routine for the
Reverse_Order
-- parameter. To sort in decreasing order, substitute your "<"
routine for
-- the Reverse_Order parameter. :-)
-----------------------------------------------------------------------------
generic
with function Reverse_Order (Left, Right : in Element) return
Boolean;
procedure Sort (Subject : in out List);
-----------------------------------------------------------------------------
-- Stream attributes.
-----------------------------------------------------------------------------
procedure Stream_Read
(Stream : access Ada.Streams.Root_Stream_Type'Class;
Item : out List);
procedure Stream_Write
(Stream : access Ada.Streams.Root_Stream_Type'Class;
Item : in List);
private
-- Placebo entries to make the compiler happy (so I know the syntax
above is correct)
type List is new Ada.Finalization.Controlled with null record;
for List'Read use Stream_Read;
type Index is new Boolean;
for List'Write use Stream_Write;
end Containers.Lists.Unbounded;
next reply other threads:[~2001-11-10 3:51 UTC|newest]
Thread overview: 189+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-11-10 3:51 Ted Dennison [this message]
2001-11-10 4:20 ` List container strawman 1.2 Jeffrey Carter
2001-11-10 4:59 ` Ted Dennison
2001-11-10 11:14 ` Florian Weimer
2001-11-10 16:24 ` Ted Dennison
2001-11-10 17:39 ` Florian Weimer
2001-11-10 18:31 ` Ted Dennison
2001-11-10 18:45 ` Jean-Marc Bourguet
2001-11-10 22:44 ` Ted Dennison
2001-11-11 3:59 ` Steven Deller
2001-11-11 11:29 ` Jean-Marc Bourguet
2001-11-11 17:42 ` Steven Deller
2001-11-11 12:36 ` Jean-Marc Bourguet
2001-11-10 22:07 ` Jeffrey Carter
2001-11-11 17:28 ` Jeffrey Carter
2001-11-10 14:51 ` Ehud Lamm
2001-11-10 16:08 ` Larry Kilgallen
2001-11-10 16:23 ` List container: Insert and Delete Nick Roberts
2001-11-10 17:13 ` Ted Dennison
2001-11-10 21:20 ` Nick Roberts
2001-11-10 22:15 ` Ehud Lamm
2001-11-10 22:48 ` Ted Dennison
2001-11-10 22:40 ` Jeffrey Carter
2001-11-11 4:00 ` Nick Roberts
2001-11-11 17:37 ` Jeffrey Carter
2001-11-11 19:29 ` Steven Deller
2001-11-12 0:20 ` Nick Roberts
2001-11-12 3:48 ` Steven Deller
2001-11-12 13:54 ` Nick Roberts
2001-11-12 15:21 ` Larry Kilgallen
2001-11-13 1:19 ` Nick Roberts
2001-11-12 17:27 ` Jeffrey Carter
2001-11-13 1:28 ` Nick Roberts
2001-11-13 1:37 ` Darren New
2001-11-13 15:58 ` John English
2001-11-13 17:53 ` Pascal Obry
2001-11-12 15:42 ` Marin David Condic
2001-11-12 5:23 ` Ted Dennison
2001-11-12 13:04 ` Nick Roberts
2001-11-12 16:36 ` Ted Dennison
2001-11-12 17:20 ` Jeffrey Carter
2001-11-12 18:55 ` Marin David Condic
2001-11-12 19:56 ` Larry Kilgallen
2001-11-12 20:36 ` Marin David Condic
2001-11-12 21:14 ` Darren New
2001-11-13 7:31 ` Simon Wright
2001-11-13 21:31 ` Marin David Condic
2001-11-14 4:43 ` Nick Roberts
2001-11-13 2:16 ` Jeffrey Carter
2001-11-13 14:18 ` Marin David Condic
2001-11-13 15:03 ` Ted Dennison
2001-11-13 15:28 ` Marin David Condic
2001-11-13 16:16 ` Jeffrey Carter
2001-11-13 19:59 ` Ted Dennison
2001-11-13 20:18 ` Marin David Condic
2001-11-13 21:26 ` Ted Dennison
2001-11-13 21:39 ` Marin David Condic
2001-11-13 22:16 ` Map container (was: List container: Insert and Delete) Ted Dennison
2001-11-14 15:07 ` Marin David Condic
2001-11-13 22:22 ` List container: Insert and Delete Jeffrey Carter
2001-11-13 17:46 ` Darren New
2001-11-13 19:25 ` Steven Deller
2001-11-13 19:40 ` Darren New
2001-11-13 20:53 ` Ted Dennison
2001-11-13 20:10 ` Ted Dennison
2001-11-13 21:31 ` Darren New
2001-11-13 22:37 ` Ted Dennison
2001-11-13 22:44 ` Ted Dennison
2001-11-13 23:00 ` Darren New
2001-11-14 14:31 ` Ted Dennison
2001-11-13 14:20 ` Steven Deller
2001-11-13 15:48 ` John English
2001-11-13 20:22 ` Ted Dennison
2001-11-14 12:59 ` John English
2001-11-14 14:55 ` Ted Dennison
2001-11-14 15:34 ` Marin David Condic
2001-11-15 16:35 ` John English
2001-11-14 16:41 ` Jeffrey Carter
2001-11-13 20:22 ` Ehud Lamm
2001-11-13 21:33 ` Simon Wright
2001-11-14 12:54 ` John English
2001-11-14 16:43 ` Ehud Lamm
2001-11-14 18:19 ` Marin David Condic
2001-11-15 4:29 ` List container: Sawdust woman 43 Jeffrey Carter
2001-11-15 15:25 ` Marin David Condic
2001-11-16 1:59 ` Jeffrey Carter
2001-11-15 20:30 ` List container: Insert and Delete Simon Wright
2001-11-15 17:01 ` John English
2001-11-19 17:40 ` Ted Dennison
2001-11-20 10:52 ` John English
2001-11-13 21:07 ` Ted Dennison
2001-11-12 17:18 ` Jeffrey Carter
2001-11-12 17:13 ` Jeffrey Carter
2001-11-11 23:34 ` Nick Roberts
2001-11-12 16:33 ` Jeffrey Carter
2001-11-12 17:28 ` Ted Dennison
2001-11-13 2:27 ` Jeffrey Carter
2001-11-13 14:21 ` Ted Dennison
2001-11-14 4:16 ` Nick Roberts
2001-11-14 15:03 ` Ted Dennison
2001-11-13 0:51 ` Nick Roberts
2001-11-12 16:51 ` Ted Dennison
2001-11-13 0:44 ` Nick Roberts
2001-11-13 14:18 ` Ted Dennison
2001-11-14 4:17 ` Nick Roberts
2001-11-10 16:12 ` List container strawman 1.2 Ted Dennison
2001-11-10 18:49 ` Jean-Marc Bourguet
2001-11-10 19:29 ` Ehud Lamm
2001-11-11 10:46 ` Jean-Marc Bourguet
2001-11-11 13:07 ` Larry Kilgallen
2001-11-10 19:07 ` Jacob Sparre Andersen
2001-11-10 22:53 ` Ted Dennison
2001-11-12 16:45 ` Jacob Sparre Andersen
2001-11-13 0:55 ` Nick Roberts
2001-11-13 15:11 ` Ted Dennison
2001-11-10 22:17 ` Jeffrey Carter
2001-11-11 22:04 ` Simon Wright
2001-11-12 16:53 ` Ted Dennison
2001-11-13 7:25 ` Simon Wright
2001-11-13 22:04 ` Ted Dennison
2001-11-10 17:43 ` Florian Weimer
2001-11-10 16:46 ` Ted Dennison
2001-11-10 18:50 ` Steven Deller
2001-11-12 9:25 ` Martin Dowie
2001-11-12 12:57 ` Nick Roberts
2001-11-12 15:32 ` Marin David Condic
2001-11-12 16:58 ` Martin Dowie
2001-11-12 18:44 ` Marin David Condic
2001-11-13 7:18 ` Simon Wright
2001-11-13 21:26 ` Marin David Condic
2001-11-15 23:53 ` martin.m.dowie
2001-11-12 17:35 ` Ted Dennison
2001-11-12 18:39 ` Martin Dowie
2001-11-12 19:58 ` Ted Dennison
2001-11-12 18:39 ` Steven Deller
2001-11-12 20:05 ` Ted Dennison
2001-11-13 19:12 ` Stephen Leake
2001-11-12 16:37 ` Jeffrey Carter
2001-11-12 18:50 ` Marin David Condic
2001-11-13 1:07 ` Nick Roberts
2001-11-13 15:13 ` Ted Dennison
2001-11-15 23:54 ` martin.m.dowie
2001-11-13 19:10 ` Stephen Leake
[not found] ` <3BF0247D.4500975E@san.rr.com>
2001-11-12 20:30 ` Ehud Lamm
2001-11-12 21:57 ` Ted Dennison
2001-11-12 22:53 ` Darren New
2001-11-12 22:55 ` Darren New
2001-11-13 15:54 ` Ted Dennison
2001-11-13 19:17 ` Stephen Leake
2001-11-13 22:37 ` Jeffrey Carter
2001-11-13 15:49 ` Ted Dennison
2001-11-13 16:38 ` Martin Dowie
2001-11-13 19:06 ` Ted Dennison
2001-11-13 19:43 ` Marin David Condic
2001-11-13 20:50 ` Ted Dennison
2001-11-13 21:08 ` Marin David Condic
2001-11-14 4:34 ` Nick Roberts
2001-11-14 14:58 ` Marin David Condic
2001-11-13 17:36 ` Darren New
2001-11-14 4:40 ` Nick Roberts
2001-11-13 22:34 ` Jeffrey Carter
2001-11-14 13:39 ` John English
2001-11-14 15:09 ` Ted Dennison
2001-11-14 16:04 ` Jeffrey Carter
2001-11-14 16:36 ` Ted Dennison
2001-11-15 16:31 ` John English
2001-11-19 17:59 ` Ted Dennison
2001-11-19 21:08 ` Stephen Leake
2001-11-20 10:43 ` John English
2001-11-21 19:40 ` ramatthews
2001-11-22 3:01 ` Nick Roberts
2001-11-22 9:28 ` John English
2001-11-24 3:52 ` Nick Roberts
2001-11-23 2:21 ` Ted Dennison
2001-11-24 0:27 ` John English
2001-11-27 20:04 ` Marin David Condic
2001-11-28 8:10 ` Thomas Wolf
2001-11-28 14:29 ` Marin David Condic
2001-11-28 17:34 ` Ted Dennison
2001-11-28 18:01 ` Marin David Condic
2001-11-28 18:53 ` Ted Dennison
2001-11-28 19:08 ` Overriding 'Class'Input (was: List container strawman 1.1) Ted Dennison
2001-11-28 19:19 ` Ted Dennison
2001-11-28 20:40 ` Marin David Condic
2001-11-28 21:21 ` Ted Dennison
2001-11-28 21:50 ` Marin David Condic
2001-11-29 5:12 ` Nick Roberts
2001-11-29 20:04 ` List container strawman 1.2 Thomas Wolf
2001-11-16 0:01 ` martin.m.dowie
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox