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,a644fa9cd1a3869a X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-11-15 09:41:07 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!canoe.uoregon.edu!logbridge.uoregon.edu!server3.netnews.ja.net!newshost.central.susx.ac.uk!news.bton.ac.uk!not-for-mail From: John English Newsgroups: comp.lang.ada Subject: Re: List container: Insert and Delete Date: Thu, 15 Nov 2001 17:01:29 +0000 Organization: University of Brighton Message-ID: <3BF3F4E9.7E32361B@brighton.ac.uk> References: <9sn4qm$13g29j$2@ID-25716.news.dfncis.de> <3BF140D9.611DE43@brighton.ac.uk> <9srvmk$1la$1@news.huji.ac.il> <3BF2699A.731DC436@brighton.ac.uk> <9su77k$c83$1@news.huji.ac.il> NNTP-Posting-Host: pcje.it.bton.ac.uk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: saturn.bton.ac.uk 1005843645 4117 193.62.183.48 (15 Nov 2001 17:00:45 GMT) X-Complaints-To: news@bton.ac.uk NNTP-Posting-Date: 15 Nov 2001 17:00:45 GMT X-Mailer: Mozilla 4.7 [en-gb] (WinNT; U) X-Accept-Language: en Xref: archiver1.google.com comp.lang.ada:16582 Date: 2001-11-15T17:00:45+00:00 List-Id: Ehud Lamm wrote: > But I guess you made some design decisions which resulted in something > different from the BC (either the -83 or -95 version). Yes, I was influenced by the STL. So I had this: type Item_Type is private; -- supplied as a generic parameter type List_Type is new Limited_Controlled with private; -- a pain; means library-level instantiations. No easy -- solution to this... type List_Iterator is private; -- an iterator is like an STL iterator; it's represented -- internally as a pointer to the list header and a pointer -- to a node within that same list. For a list L = (A,B,C), -- the possible values are (L,A) = the position before A, -- (L,B) and (L,C) similarly, and (L,null) is the position -- after C. The initial value is (null,null) meaning an -- uninitialised iterator value (raises List_Error if used). function Size (List : List_Type) return Natural; -- length of the list function First (List : List_Type) return List_Iterator; function Last (List : List_Type) return List_Iterator; function Succ (Iterator : List_Iterator) return List_Iterator; function Pred (Iterator : List_Iterator) return List_Iterator; -- names chosen to match attributes of an enumeration. -- Iterators are immutable; these functions all produce -- a brand new iterator value each time they're used. function Value (Iterator : List_Iterator) return Item_Type; -- get the value that an iterator refers to (or raise -- List_Error) procedure Insert (Iterator : in List_Iterator; Item : in Item_Type); procedure Delete (Iterator : in List_Iterator); -- modify the list. The iterator given to Delete will be -- invalid afterwards; maybe it should be "in out", and -- explicitly nulled by the procedure. List_Error : exception; -- raised if iterators are invalid Now: "&" is missing, Singleton = Insert(First(L)) where L is an empty list; Push_Front(L,X) = Insert(First(L),X), Push_Back(L,X) = Insert(Last(L),X), Pop_Front(L,X) = X := Value(First(X)); Delete(First(X)); Pop_Back(L,X) = X := Value(Pred(Last(X))); Delete(Pred(Last(X)); Is_Empty(L) = (Size(L) = 0), Has_Item doesn't apply any more, and Ted's Iterator, Insert(List,Index,List), Modify and Sort aren't there but probably should be (see stream-of- consciousness ramble elsewhere in this thread). Missing from Ted's Strawman: Clear(L) = delete everything in the list, Cut(A,B) = remove everything between iterators A and B and return as a list (or raise List_Error if A and B refer to separate lists), and Copy(A,B) = copy a sublist. The use of Cut and Copy together with "&" and Insert(Iterator,List) would deal with all the sublist operations and operations on pairs of lists. Problems encountered: students don't like Delete(Pred(Last(L))), they always write Delete(Last(L)) and then get a List_Error. ----------------------------------------------------------------- John English | mailto:je@brighton.ac.uk Senior Lecturer | http://www.comp.it.bton.ac.uk/je Dept. of Computing | ** NON-PROFIT CD FOR CS STUDENTS ** University of Brighton | -- see http://burks.bton.ac.uk -----------------------------------------------------------------