* Re: Conceptual Ada Problems
1996-09-29 0:00 Conceptual Ada Problems Vasilios Tourloupis
@ 1996-09-29 0:00 ` Matthew Heaney
1996-09-29 0:00 ` Larry Kilgallen
1996-10-01 0:00 ` Dale Stanbrough
2 siblings, 0 replies; 5+ messages in thread
From: Matthew Heaney @ 1996-09-29 0:00 UTC (permalink / raw)
In article
<Pine.GSO.3.93.960929230049.29986A-100000@firefly.sd.monash.edu.au>,
Vasilios Tourloupis <vasilios@insect.sd.monash.edu.au> wrote:
>* Is there some way I would be able to access key fields
> of generic data types (records)?
I'm not sure what you mean: Can you be more specific?
>* Is there some way of storing/retrieving records in an Ada.Direct_IO
> file using key fields of records rather than their location in the file?
As far as I know, the only way to retrieve records using Direct_IO all by
itself is via the Index.
Of course, you could create another abstraction the does allow you to
retrieve records via a key field, that is implemented using Direct_IO. You
could keep the key-to-index map in a (smaller) seperate file, so that your
abstraction actually comprises 2 files. When you initialize the
abstraction, it could read into memory the key-to-index file, and during
lookups, use that info to determine the index position of the record in the
direct file.
>* I am not quite sure how to declare functions/procedures as formal
> parameters to a function/procedure.
If you're using Ada 83, then make the package or the subprogram generic:
generic
with procedure P (<args here>);
procedure Generic_Op (<its args here>);
or
generic
with procedure P (...);
package Generic_Ops is
To use it, you instantiate it:
procedure P (...) is ...
procedure Op is new Generic_Op (P);
If you're using Ada 95, then you can still do that, and in addition declare
subprogram pointers:
type P_Access is access procedure (...);
procedure Op (..., P : P_Access);
Then no instantiation is required:
procedure P (...) is ...
Op (... P'Access);
Give me an example of what you want to do.
>* Also, the Ada compiler complains about some subtype mark being
> required, in declaring an array comprising of generic linked lists.
> Any suggestions on how to overcome this are more than welcome, as
> I have been trying all day, to no avail!
Show me the code that doesn't compile, and then I'll be able to tell you why.
Make sure your array comprises an actual type: you don't get a type from a
generic package directly, only from its instantiation:
generic
type T is private;
package Lists is
type List is private;
...
type List_Array is (Positive range <>) of Lists.List; -- not legal Ada
Instantiate first:
package Integer_Lists is new Lists (Integer);
type Integer_List_Array is (Positive range <>) of Integer_Lists.List; -- OK
>Basically, what I am trying to implement is an hash table with the
>ability to save and load records to and from a direct IO file,
>respectively. Any other suggestions and/or pointers are more than
>welcome.
Again, maybe you want to store off the map (hash table) in another file.
Of course, if you are using Ada 95, then you could play around with
Streams_IO. It lets you do heterogeneous storage, so maybe you wouldn't
need 2 separate (homogeneous) file.
>Bill Tourloupis
Matt
--------------------------------------------------------------------
Matthew Heaney
Software Development Consultant
mheaney@ni.net
(818) 985-1271
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Conceptual Ada Problems
1996-09-29 0:00 Conceptual Ada Problems Vasilios Tourloupis
1996-09-29 0:00 ` Matthew Heaney
1996-09-29 0:00 ` Larry Kilgallen
@ 1996-10-01 0:00 ` Dale Stanbrough
2 siblings, 0 replies; 5+ messages in thread
From: Dale Stanbrough @ 1996-10-01 0:00 UTC (permalink / raw)
>I have a few questions regarding Ada, which hopefully someone
>will be able to answer:
>
>* Is there some way I would be able to access key fields
> of generic data types (records)?
I presume you mean accessing the fields of a record inside a generic.
Not directly (after all the generic may be instantiated with type
integer, which has no fields!). You can supply a function to access
components of a record for your.
>* Is there some way of storing/retrieving records in an Ada.Direct_IO
> file using key fields of records rather than their location in the file?
No, you have to build up an index yourself. you could save it to disc of
course, rather than building it up each time the program runs.
>* I am not quite sure how to declare functions/procedures as formal
> parameters to a function/procedure.
Declare the subprograms at the library level, and then do...
type func_ptr is access function (required profile) required return type
you can then take the 'access of a subprogram.
>* Also, the Ada compiler complains about some subtype mark being
> required, in declaring an array comprising of generic linked lists.
> Any suggestions on how to overcome this are more than welcome, as
> I have been trying all day, to no avail!
you can't have generic linked lists, only generic packages & subprograms.
you may have a diff. problem to this, but this is all i can make out
of your description.
Dale
^ permalink raw reply [flat|nested] 5+ messages in thread