comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Record operations (Algebraic Data Types and printing)
Date: Thu, 11 Oct 2018 10:36:40 +0200
Date: 2018-10-11T10:36:40+02:00	[thread overview]
Message-ID: <ppn22n$ml1$1@gioia.aioe.org> (raw)
In-Reply-To: 644dc84a-1e0c-4a1b-9672-38709acf1faa@googlegroups.com

On 2018-10-10 20:38, Shark8 wrote:
> On Wednesday, October 10, 2018 at 1:17:51 AM UTC-6, Dmitry A. Kazakov wrote:
>> On 2018-10-10 00:20, Randy Brukardt wrote:
>>> "Lucretia"  wrote in message
>>> news:fb2af9cb-5317-4f1c-867c-8876212d303b...
>>
>>>> Like what 'Read/'Write/'Input/'Output do, they call a defined subprogram in
>>>> the package. Surely, it's not that hard.
>>>
>>> What package? We're talking about (in part) the default representation for a
>>> type.
>>
>> What have T'Image and T'Value to do with the type representation?
> 
> Well, T'Value would need two things: (1) to read from the stream, and (2) produce the proper value of the type. This might require knowing the representation, such as a set of flags modeled by an "Array(1..8) of Boolean" [with Size => 8] being packed into a single byte.

Whatever way the implementation chooses. Full visibility of the type or 
some of its parts might be required or not required. The default 
implementation could respect visibility or ignore it.

>>> Stream attributes use a complex concept called "availability" to deal
>>> with limited types, and they don't worry about privacy breakage at all.
>>
>> Limited types should have no stream attributes at all. Same applied to
>> 'Image/'Value. Returning limited object was a language design bug. This
>> cannot be fixed but it can be contained.
> 
> I'm not sure about this. There's a good argument for it if you're (eg) modeling/interfacing into hardware... but there's argument against it if your purpose is merely controlling data. -- An example I could think of is some sort of keyed-index ownership-scheme where there's only one value of that particular type at a time, and some need for persistence across program runs. (Wherein the values are saved to disk in program-shutdown, and restored in program-start-up.)

The question is whether this behavior is safe to provide by default. The 
answer is no, most of the time it is unsafe and meaningless. The rest 
can be easily covered without using streaming attributes.

BTW, in practice they would not work anyway. I implemented what you 
described on several occasions. Each time I ended up with reading from 
the stream not the limited object but a handle to it instead. The 
handle's 'Read attribute read the object parts from the stream, 
allocated the new object, constructed it in place and then returned a 
handle to it.

Limited return+aggregates simply do not work when you have derived types 
and private parts.

>> Safe default is to generate publicly visible 'Image and 'Value
>> propagating Use_Error for all types with private components. The package
>> provider could override them in the public part with bodies renaming the
>> private default implementations of which have full visibility.
> 
> Or, we could just let the attributes [functionally] act as callbacks, albeit statically rather than dynamically assigned. Thus you could invoke T'Image for anything w/ the attribute and have a good compile/run (even if the default provided by the compiler is USE_ERROR)... then add in an implementation, use "For T'Image Use ..." or " with Image => ..." (perhaps in the private section) and compile/run it w/o having altered the public/visible interfacing.

Yes, this is how stream attributes were forced into the language. But 
the question was about what to do with default implementations without 
full visibility.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


  reply	other threads:[~2018-10-11  8:36 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-05 17:46 Record operations (Algebraic Data Types and printing) Henrik Härkönen
2018-10-05 17:58 ` AdaMagica
2018-10-05 18:11   ` Henrik Härkönen
2018-10-05 18:46     ` Niklas Holsti
2018-10-05 20:33       ` Henrik Härkönen
2018-10-06  5:38   ` J-P. Rosen
2018-10-06  7:08     ` Henrik Härkönen
2018-10-06 16:42       ` Lucretia
2018-10-08 23:08         ` Randy Brukardt
2018-10-09  1:12           ` Lucretia
2018-10-09 22:20             ` Randy Brukardt
2018-10-10  7:17               ` Dmitry A. Kazakov
2018-10-10 18:13                 ` G. B.
2018-10-10 18:36                   ` Dmitry A. Kazakov
2018-10-11 11:29                   ` Björn Lundin
2018-10-11 14:45                     ` Jacob Sparre Andersen
2018-10-11 18:34                       ` Björn Lundin
2018-10-12 19:08                     ` G. B.
2018-10-12 19:20                       ` Randy Brukardt
2018-10-11 21:32                   ` Randy Brukardt
2018-10-10 18:38                 ` Shark8
2018-10-11  8:36                   ` Dmitry A. Kazakov [this message]
2018-10-11 21:35                 ` Randy Brukardt
2018-10-12  7:14                   ` Dmitry A. Kazakov
2018-10-12 19:16                     ` Randy Brukardt
2018-10-06 16:18     ` Jeffrey R. Carter
2018-10-06 17:19       ` Dmitry A. Kazakov
2018-10-08 23:03   ` Randy Brukardt
2018-10-09  6:22     ` Henrik Härkönen
2018-10-09  7:32       ` Paul Rubin
2018-10-09  7:38         ` Henrik Härkönen
2018-10-09 22:25         ` Randy Brukardt
2018-10-05 18:32 ` Niklas Holsti
2018-10-05 18:43   ` Henrik Härkönen
2018-10-05 19:41   ` Simon Wright
2018-10-06  6:17     ` Henrik Härkönen
2018-10-06 16:04       ` Stephen Leake
2018-10-06 16:56         ` Simon Wright
2018-10-08  6:44           ` briot.emmanuel
2018-10-08 14:09             ` Simon Wright
2018-10-08 14:21               ` Bill Findlay
2018-10-08 14:42                 ` Simon Wright
2018-10-08 16:46                   ` Bill Findlay
replies disabled

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