comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: article on acces types and dynamic serialization in Ada (2003)
Date: Thu, 22 Feb 2018 17:49:01 -0600
Date: 2018-02-22T17:49:01-06:00	[thread overview]
Message-ID: <p6nkte$tbk$1@franka.jacob-sparre.dk> (raw)
In-Reply-To: 5d8580c2-b43d-4b2c-8a46-3a6ed33967aa@googlegroups.com

"Mehdi Saada" <00120260a@gmail.com> wrote in message 
news:5d8580c2-b43d-4b2c-8a46-3a6ed33967aa@googlegroups.com...
...
>There might be numerous ways around this linked data issue but having a
>sane default implementation, as we already have defaults everywhere
>you can still override.

What default (read relatively cheap to read/write) implementation could 
possibly be sane?

As Dmitry points out, full serialization doesn't make sense for Ada -- for 
that matter, it doesn't make sense (as a default) for any language, since 
one has to deal with recursive data structures. Having P'Write go into an 
infinite loop is hardly sane!

To see this, imagine writing a doubly-linked list node with a serializing 
access definition:

                    type Node;
                    type Node_Ptr is access all Node;
                    type Node is record
                          Data : Natural;
                          Prev, Next : Node_Ptr;
                    end record;

For the Node_Ptrs to be written as anything useful, you'd have to dump the 
entire list -- but that then would be duplicative. One really has to write a 
custom solution for each such data structure --- there is no 
one-size-fits-most solution.

As to why it doesn't just raise Program_Error to 'Read/'Write an access 
value, I would say that it is because one can reliably test a read access 
value for null/not null. One then can use that information to determine 
whether or not do do more serialization. Doing that is a lot easier (for 
both the author and the compiler) than separating the record into separate 
components and having to deal with each individually.

OTOH, I once had an argument with Robert Dewar about this, he made the claim 
that one can't rely on that as "implementation-defined" doesn't necessarily 
mean "something trivially cheap". It's hard for me to imagine an 
implementation doing anything other than just dumping the access value 
binary, but argubly he was right. (In practice, I was right so far as I can 
tell.) But in that case, Ptr'Write should raise Program_Error because it can 
never have any useful portable meaning. (Too late now, though, there are 
lots of uses like mine out there.)

                                         Randy.



  parent reply	other threads:[~2018-02-22 23:49 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-21 23:57 article on acces types and dynamic serialization in Ada (2003) Mehdi Saada
2018-02-22  9:16 ` Dmitry A. Kazakov
2018-02-22 12:08   ` guyclaude.burger
2018-02-22 12:15 ` Mehdi Saada
2018-02-22 13:04   ` Dmitry A. Kazakov
2018-02-22 23:49   ` Randy Brukardt [this message]
2018-02-23  3:40     ` Shark8
2018-02-23  7:23       ` Jacob Sparre Andersen
2018-02-23  8:38         ` Dmitry A. Kazakov
2018-02-23 20:28           ` G. B.
2018-02-23 20:40             ` Dmitry A. Kazakov
2018-02-23 10:30 ` Mehdi Saada
2018-02-23 13:13   ` Dmitry A. Kazakov
replies disabled

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