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:11:06 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!lon1-news.nildram.net!195.8.68.195.MISMATCH!newspeer.clara.net!news.clara.net!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 strawman 1.2 Date: Thu, 15 Nov 2001 16:31:33 +0000 Organization: University of Brighton Message-ID: <3BF3EDE5.FE0ED701@brighton.ac.uk> References: <3BECA3B7.5020702@telepath.com> <3BF0247D.4500975E@san.rr.com> <5BXH7.22252$xS6.34813@www.newsranger.com> <3BF052D3.ECEF3FF2@san.rr.com> <3BF19FF8.7FE097EF@boeing.com> <3BF27410.C899A16B@brighton.ac.uk> 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 1005841849 3646 193.62.183.48 (15 Nov 2001 16:30:49 GMT) X-Complaints-To: news@bton.ac.uk NNTP-Posting-Date: 15 Nov 2001 16:30:49 GMT X-Mailer: Mozilla 4.7 [en-gb] (WinNT; U) X-Accept-Language: en Xref: archiver1.google.com comp.lang.ada:16579 Date: 2001-11-15T16:30:49+00:00 List-Id: Ted Dennison wrote: > > In article <3BF27410.C899A16B@brighton.ac.uk>, John English says... > >My vote also goes to First and Last. Apart from anything else, the > >names are then consistent with the corresponding array attributes, > >and consistency is a Good Thing IMHO. > > Are you saying First and List just for the "Position", or for that and for the > Push and Pop routines too? Hmm, Push_First and Push_Last? How about Insert_First, Insert_Last (which would be effectively a renaming of Insert(List,First(List),Item)). Gah. Which is more confusing: having Front(L) = Item(First(L)) or First(L) = Item(First(L))? Perhaps Front and Back are "a convenience too far", and should be dropped since they are easily constructed from simpler building blocks? I would have thought that bloating the API with extra functionality would be a bad idea unless there's a good reason to, such as the operations would be difficult for the user to implement (for some value of "difficult")... I don't think writing Item(First(I)) counts as "difficult", though. I'd personally prefer to stick to: &, Singleton (or To_List?), Size, First, Last, Next, Previous, Item, Insert, Remove, Modify, Sort, Stream_Read, Stream_Write. Iterator is nice too but instantiating the generic (and wrapping the operation in an approapriately-shaped procedure first) is probably more hassle than a while I <> Last(L) loop, IMHO... OTOH, Sort counts as "difficult" so should probably be kept. However, another one I might one would be Shuffle, which is about the same level of difficulty... maybe a generalisation such as Swap(Index,Index) might be a useful building block for algorithms of this sort. Also operations on sublists, specified by a range of Indexes to allow you to remove a sublist, insert a sublist, replace a sublist by another, and so on. You'd need Copy(List,From,To) and Cut(List,From,To) for this. e.g. Insert(List_1, Index_1, Copy(List_2,A,B)); or Insert(List_1, Index_1, Cut(List_2,A,B)); I also think that an Index needs to know which list it refers to, to avoid: I := First(L2); Insert(L1,I,X); -- L1 /= L2 The package in my book models an iterator as a pair of pointers (one to the list header, one to the element or null). (L,null) refers to the end of L (the position after the last element); (null,null) is a null iterator. Since it's a private type, the two pointers are always kept in synch by the iterator primitives. So Insert would need two parameters (List and Value) and Remove would need one: Insert(First(L),Item) instead of Insert(L,First(L),Item) or (worse) Insert(L,First(L2),Item). Phew. Sorry for the stream-of-consciousness ramble... hope it helps ;-) ----------------------------------------------------------------- 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 -----------------------------------------------------------------