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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,842accb6a7d76669 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-11-11 13:27:02 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!dispose.news.demon.net!news.demon.co.uk!demon!pogner.demon.co.uk!zap!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: List container strawman 1.1 Date: 11 Nov 2001 21:03:52 +0000 Organization: Pushface Message-ID: References: <3BE301D1.4010106@telepath.com> <3BE7DA00.8020807@acm.org> <9sdojl$e6h$1@news.huji.ac.il> <3BEACA5A.9030100@acm.org> <20TG7.18929$xS6.30469@www.newsranger.com> <9sh49o$ohc$1@nh.pace.co.uk> NNTP-Posting-Host: localhost X-NNTP-Posting-Host: pogner.demon.co.uk:158.152.70.98 X-Trace: news.demon.co.uk 1005514002 nnrp-12:27444 NO-IDENT pogner.demon.co.uk:158.152.70.98 X-Complaints-To: abuse@demon.net NNTP-Posting-Date: 11 Nov 2001 21:04:10 GMT X-Newsreader: Gnus v5.7/Emacs 20.7 Xref: archiver1.google.com comp.lang.ada:16299 Date: 2001-11-11T21:04:10+00:00 List-Id: "Marin David Condic" writes: > I'm wondering if everyone is declaring it "Unacceptable" or perhaps > a little less strongly, it is merely being viewed as > "Undesirable". (That would describe my gut feeling on it.) I'd still > think that the BC's might be usable if some conditions were met. 1) > See if you can hide some of the complexity by making a simple-case > binding for the most common usages. It does rather go against the grain of the BCs, IMO, but I could add this (which does everything bar closed iteration). "Collection" is what everyone has been calling "List", BTW. Almost all the operations could in fact be omitted in this package, because they are inherited, though one would have to "use" it to get at them easily and I suspect pedagogically one would prefer to see the operations. Just treat it as implementation inheritance. ================================================================================ -- Copyright (C) 2001 Simon Wright. -- All Rights Reserved. -- -- This program is free software; you can redistribute it -- and/or modify it under the terms of the Ada Community -- License which comes with this Library. -- -- This program is distributed in the hope that it will be -- useful, but WITHOUT ANY WARRANTY; without even the implied -- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -- PURPOSE. See the Ada Community License for more details. -- You should have received a copy of the Ada Community -- License with this library, in the file named "Ada Community -- License" or "ACL". If not, contact the author of this library -- for a copy. -- -- $RCSfile: bc-simple_collections.ads,v $ -- $Revision: 1.1 $ -- $Date: 2001/11/11 20:48:36 $ -- $Author: simon $ with BC.Containers.Collections.Unbounded; with BC.Support.Standard_Storage; generic type Item is private; with function "=" (L, R : Item) return Boolean is <>; package BC.Simple_Collections is pragma Elaborate_Body; package Abstract_Containers is new BC.Containers (Item); package Abstract_Collections is new Abstract_Containers.Collections; package Collections is new Abstract_Collections.Unbounded (Storage => BC.Support.Standard_Storage.Pool); type Collection is new Collections.Collection with private; -- A collection denotes an indexed collection of items, drawn from -- some well-defined universe. A collection may contain duplicate -- items; a collection owns a copy of each item. ----------------------------- -- Collection operations -- ----------------------------- function Null_Collection return Collection; -- Return an empty Collection. function "=" (Left, Right : in Collection) return Boolean; procedure Clear (C : in out Collection); -- Empty the collection of all items. procedure Insert (C : in out Collection; Elem : Item); -- Add the item to the front of the collection. procedure Insert (C : in out Collection; Elem : Item; Before : Positive); -- Add the item before the given index item in the collection; if -- before is 1, the item is added to the front of the collection. procedure Append (C : in out Collection; Elem : Item); -- Add the item at the end of the collection. procedure Append (C : in out Collection; Elem : Item; After : Positive); -- Add the item after the given index item in the collection. procedure Remove (C : in out Collection; At_Index : Positive); -- Remove the item at the given index in the collection. procedure Replace (C : in out Collection; At_Index : Positive; Elem : Item); -- Replace the item at the given index with the given item. function Length (C : Collection) return Natural; -- Return the number of items in the collection. function Is_Empty (C : Collection) return Boolean; -- Return True if and only if there are no items in the -- collection. function First (C : Collection) return Item; -- Return a copy of the item at the front of the collection. function Last (C : Collection) return Item; -- Return a copy of the item at the end of the collection. function Item_At (C : Collection; At_Index : Positive) return Item; -- Return a copy of the item at the indicated position in the -- collection. function Location (C : Collection; Elem : Item) return Natural; -- Return the first index at which the item is found (0 if the -- item desn't exist in the collection). ----------------- -- Iteration -- ----------------- subtype Iterator is Abstract_Containers.Iterator'Class; function New_Iterator (For_The_Collection : Collection) return Iterator; -- Return a reset Iterator bound to the specific Collection. procedure Reset (It : in out Iterator); -- Reset the Iterator to the beginning. procedure Next (It : in out Iterator); -- Advance the Iterator to the next Item in the Container. function Is_Done (It : Iterator) return Boolean; -- Return True if there are no more Items in the Container. function Current_Item (It : Iterator) return Item; -- Return a copy of the current Item. private type Collection is new Collections.Collection with null record; function Null_Container return Collection; end BC.Simple_Collections; ================================================================================ > 2) Create a "Booch Components > for Idiots" text that shows cookie-cutter recepies for how to do the > simple cases (covers up for #1 if that's not feasable.) Has anyone had a chance to look at http://www.pushface.org/components/bc/case-study.html yet to see if I'm on anything like the right lines? > Or it might be possible to declare as part of the BC's++ that there > will be a couple of new packages that handle the simple cases while > keeping the rest of the BC's around for the more advanced user? My first reaction was that if anyone can get their heads round Maps they should be able to do a couple of measly instantiations :-)