comp.lang.ada
 help / color / mirror / Atom feed
From: eachus@spectre.mitre.org (Robert I. Eachus)
Subject: Re: Newbie question about generic linked list tasks
Date: 23 Sep 94 10:53:07
Date: 1994-09-23T10:53:07+00:00	[thread overview]
Message-ID: <EACHUS.94Sep23105307@spectre.mitre.org> (raw)
In-Reply-To: farrell@coral.cs.jcu.edu.au's message of 22 Sep 94 12:33:10 GMT

In article <farrell.780237190@coral.cs.jcu.edu.au> 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...



  parent reply	other threads:[~1994-09-23 10:53 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <farrell.780154278@coral.cs.jcu.edu.au>
     [not found] ` <35qb51$ksu@rational.rational.com>
1994-09-22 17:55   ` Newbie question about generic linked list tasks Bob Kitzberger
     [not found] ` <EACHUS.94Sep21134917@spectre.mitre.org>
     [not found]   ` <farrell.780237190@coral.cs.jcu.edu.au>
1994-09-23 10:53     ` Robert I. Eachus [this message]
1994-09-26  5:52       ` John Farrell
1994-09-26  9:55         ` Robert I. Eachus
1994-09-27  5:37           ` John Farrell
1994-09-28 22:15             ` David Weller
     [not found] ` <35q08a$1e5u@watnews1.watson.ibm.com>
1994-09-26  6:25   ` John Farrell
1994-09-26  9:44     ` Robert I. Eachus
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox