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=-0.8 required=5.0 tests=BAYES_00,INVALID_DATE autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,ba049bdce87e95c1 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1994-09-23 08:30:43 PST Path: bga.com!news.sprintlink.net!howland.reston.ans.net!europa.eng.gtefsd.com!newsxfer.itd.umich.edu!zip.eecs.umich.edu!yeshua.marcam.com!news.kei.com!world!blanket.mitre.org!linus.mitre.org!linus!mbunix!eachus From: eachus@spectre.mitre.org (Robert I. Eachus) Newsgroups: comp.lang.ada Subject: Re: Newbie question about generic linked list tasks Date: 23 Sep 94 10:53:07 Organization: The Mitre Corp., Bedford, MA. Message-ID: References: NNTP-Posting-Host: spectre.mitre.org In-reply-to: farrell@coral.cs.jcu.edu.au's message of 22 Sep 94 12:33:10 GMT Date: 1994-09-23T10:53:07+00:00 List-Id: In article farrell@coral.cs.jcu.edu.au (John Farrell) writes: > I would like more concurrency than just semaphores gives you. Hmmm... The semaphores don't "grant" concurrency, they just allow constructs to remain consistant even if concurrency is present. In constructing a concurrent application, you have to decide which threads should be active, and which can be passive. Usually lists are treated as passive. But that is another topic. > Which is the important Booch book? I have Software Engineering > with Ada here, and it doesn't seem to say anything outstanding. I have it here too, and he has a companion book to the components, but the components are purchased from Grady as source files. > OK, I figured all this out by myself. But say I want to implement > list concatenation, how can I write an entry which takes an > argument of type List, so I could write: > A.Concat(B); > In my experience it's not even possible to write the type... See Norm's answer on this. But actually, if you make the task type a (limited) private type, then it is possible to declare the operation Concat(A,B) in a way that works. However, to implement it... > And what if I wanted to do a list traversal? I would have to > pass a procedure/function to operate on items as a generic, but I > don't believe I can pass them into an entry, so they would have to > be generic for the package. Then I only have one traversal > function for each instantiation of the package? ...you will need primitive (and hidden) entries to the task type to give you a handle into the list, and operations on it, say: entry Get_Handle(H: out Handle); entry Free_Handle(H: in out Handle); entry Next(H: in out Handle; I: out Item); entry At_End(H: in Handle; Done: out Boolean); (At_End is provided, but you would probably want to depend on Next raising an exception at the end of the list.) Now your list package can export a generic traversal operation which takes a generic formal procedure parameter. If you code it right, you can even have several traversals of the same list in progress at the same time. If you really want to do that, you might want two generic traversals, one which allows only read access to list elements, and one which provides read/write: generic with procedure Apply(I: in out Item); procedure Traverse(L: in out List); generic with procedure Look(I: in Item); procedure Walk(L: in out List); > What do you mean by completion? The full declaration which conforms to the private type declaration and completes it. > OK, that's nicer but I think there are still some ugly things. Thanks for > helping out with this, but my problems run deeper :-). Hope the above helps. It is possible to do what you want in Ada 83, but the private part of the package (and the body!) start getting messy. If you get too fancy, you end up writing the body of the task type as a finite state machine, with eight or nine accept statements or altenatives for each entry. (I know, I've done it, and multi-page task bodies are a bitch to test.) -- Robert I. Eachus with Standard_Disclaimer; use Standard_Disclaimer; function Message (Text: in Clever_Ideas) return Better_Ideas is...