comp.lang.ada
 help / color / mirror / Atom feed
* I have no idea why this will not compile.
@ 2016-05-01  3:22 John Smith
  2016-05-01  4:07 ` Jeffrey R. Carter
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: John Smith @ 2016-05-01  3:22 UTC (permalink / raw)


This is the ADS file that I have:
http://pastebin.ca/3587453

And this is the error message that I get:
http://pastebin.ca/3587456

Ever since I've added the File_Type, I've gotten this error message.  Is it impossible for me to store this value in an instance of a record?


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: I have no idea why this will not compile.
  2016-05-01  3:22 I have no idea why this will not compile John Smith
@ 2016-05-01  4:07 ` Jeffrey R. Carter
  2016-05-01  6:47 ` Georg Bauhaus
  2016-05-01 10:10 ` mockturtle
  2 siblings, 0 replies; 9+ messages in thread
From: Jeffrey R. Carter @ 2016-05-01  4:07 UTC (permalink / raw)


On 04/30/2016 08:22 PM, John Smith wrote:
>
> Ever since I've added the File_Type, I've gotten this error message.  Is it impossible for me to store this value in an instance of a record?

Here's the important error msg:

"nonlimited tagged type cannot have limited components"

That ought to tell you everything you need to know about what's wrong.

-- 
Jeff Carter
"I fart in your general direction."
Monty Python & the Holy Grail
05


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: I have no idea why this will not compile.
  2016-05-01  3:22 I have no idea why this will not compile John Smith
  2016-05-01  4:07 ` Jeffrey R. Carter
@ 2016-05-01  6:47 ` Georg Bauhaus
  2016-05-01 21:52   ` John Smith
  2016-05-01 10:10 ` mockturtle
  2 siblings, 1 reply; 9+ messages in thread
From: Georg Bauhaus @ 2016-05-01  6:47 UTC (permalink / raw)


On 01.05.16 05:22, John Smith wrote:
> This is the ADS file that I have:
> http://pastebin.ca/3587453
>
> And this is the error message that I get:
> http://pastebin.ca/3587456
>
> Ever since I've added the File_Type, I've gotten this error message.  Is it impossible for me to store this value in an instance of a record?

The technical reason was already stated.

To solve, it's worth isolating the places in the program that will
actually be needing the File_Type component. I think the solution
will show it as a redundancy of the full type's definition.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: I have no idea why this will not compile.
  2016-05-01  3:22 I have no idea why this will not compile John Smith
  2016-05-01  4:07 ` Jeffrey R. Carter
  2016-05-01  6:47 ` Georg Bauhaus
@ 2016-05-01 10:10 ` mockturtle
  2016-05-01 20:55   ` John Smith
  2 siblings, 1 reply; 9+ messages in thread
From: mockturtle @ 2016-05-01 10:10 UTC (permalink / raw)


You already received two answers that help you to solve the problem.  However, depending on your knowledge of Ada, maybe a longer explanation could be useful.

"limited" in Ada is used to mark a type that cannot be copied.  For example, task types are limited (it does not make much sense copying a task), protected objects are limited (what means to copy them is doubtful).  In the case of File_Type I guess they are limited because the file has an "internal state" that could be bring to subtle errors if copied.  (BTW, also in C you never copy a FILE, but a pointer to FILE, never copying the underling structure).

In Ada is not permitted to use a limited type as a component of a *non limited* record, since this would allow you to avoid the original limited restriction (by copying the record you would copy also the limited component).  Because of this, Ada requires that you declare limited any record that has a limited component.

Solutions?  I can think about three solutions:

1.  Make the record limited
2. Use an access to the limited type
3. Move the limited component outside the record

I think that the best solution depends on your specfic case.

Riccardo

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: I have no idea why this will not compile.
  2016-05-01 10:10 ` mockturtle
@ 2016-05-01 20:55   ` John Smith
  2016-05-01 23:52     ` Jeffrey R. Carter
  2016-05-02  1:02     ` Jeremiah
  0 siblings, 2 replies; 9+ messages in thread
From: John Smith @ 2016-05-01 20:55 UTC (permalink / raw)


That's more helpful, thanks.  And no, I'm not very proficient in Ada, hence my 
confusion.  Based on what you suggested, option two makes the most sense.

Again, since I'm still learning, this is what I've come up with:
http://pastebin.ca/3588100

And now I'm getting the following error:
"full view of private extension must be an extension"

On Sunday, May 1, 2016 at 6:10:34 AM UTC-4, mockturtle wrote:
> You already received two answers that help you to solve the problem.  However, depending on your knowledge of Ada, maybe a longer explanation could be useful.
> 
> "limited" in Ada is used to mark a type that cannot be copied.  For example, task types are limited (it does not make much sense copying a task), protected objects are limited (what means to copy them is doubtful).  In the case of File_Type I guess they are limited because the file has an "internal state" that could be bring to subtle errors if copied.  (BTW, also in C you never copy a FILE, but a pointer to FILE, never copying the underling structure).
> 
> In Ada is not permitted to use a limited type as a component of a *non limited* record, since this would allow you to avoid the original limited restriction (by copying the record you would copy also the limited component).  Because of this, Ada requires that you declare limited any record that has a limited component.
> 
> Solutions?  I can think about three solutions:
> 
> 1.  Make the record limited
> 2. Use an access to the limited type
> 3. Move the limited component outside the record
> 
> I think that the best solution depends on your specfic case.
> 
> Riccardo


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: I have no idea why this will not compile.
  2016-05-01  6:47 ` Georg Bauhaus
@ 2016-05-01 21:52   ` John Smith
  2016-05-02  7:36     ` Georg Bauhaus
  0 siblings, 1 reply; 9+ messages in thread
From: John Smith @ 2016-05-01 21:52 UTC (permalink / raw)


On Sunday, May 1, 2016 at 2:47:31 AM UTC-4, Georg Bauhaus wrote:
> On 01.05.16 05:22, John Smith wrote:
> > This is the ADS file that I have:
> > http://pastebin.ca/3587453
> >
> > And this is the error message that I get:
> > http://pastebin.ca/3587456
> >
> > Ever since I've added the File_Type, I've gotten this error message.  Is it impossible for me to store this value in an instance of a record?
> 
> The technical reason was already stated.
> 
> To solve, it's worth isolating the places in the program that will
> actually be needing the File_Type component. I think the solution
> will show it as a redundancy of the full type's definition.

The hope was that I could keep everything inside of the object and open/close 
the file once (the closing would be done in the destructor.)  I'll need to read 
up on Ada pointers to better understand what I'm getting myself into.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: I have no idea why this will not compile.
  2016-05-01 20:55   ` John Smith
@ 2016-05-01 23:52     ` Jeffrey R. Carter
  2016-05-02  1:02     ` Jeremiah
  1 sibling, 0 replies; 9+ messages in thread
From: Jeffrey R. Carter @ 2016-05-01 23:52 UTC (permalink / raw)


On 05/01/2016 01:55 PM, John Smith wrote:
>
> And now I'm getting the following error:
> "full view of private extension must be an extension"

Again, that seems quite clear.

But using access types is almost certainly the wrong approach.

-- 
Jeff Carter
"Strange women lying in ponds distributing swords
is no basis for a system of government."
Monty Python & the Holy Grail
66


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: I have no idea why this will not compile.
  2016-05-01 20:55   ` John Smith
  2016-05-01 23:52     ` Jeffrey R. Carter
@ 2016-05-02  1:02     ` Jeremiah
  1 sibling, 0 replies; 9+ messages in thread
From: Jeremiah @ 2016-05-02  1:02 UTC (permalink / raw)


On Sunday, May 1, 2016 at 4:55:58 PM UTC-4, John Smith wrote:
> "full view of private extension must be an extension"
> 

Take a step back for a second and take some time to carefully read what the message says.  

You present two different views of the same type:

Public view: 
type Logger_State is new Ada.Finalization.Controlled with private;

Private view:
type Logger_State is record

Do those match?  Is the private view at the very minimum true for everything that is stated in the public view?

The public view says Logger state is a "new Ada.Finalization.Controlled" and "with private".  The private view says it is just a record.  Think about it like a language lawyer would.  Can you say without a doubt that the private view meets all the requirements that the public view promises?

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: I have no idea why this will not compile.
  2016-05-01 21:52   ` John Smith
@ 2016-05-02  7:36     ` Georg Bauhaus
  0 siblings, 0 replies; 9+ messages in thread
From: Georg Bauhaus @ 2016-05-02  7:36 UTC (permalink / raw)


On 01.05.16 23:52, John Smith wrote:

> The hope was that I could keep everything inside of the object and open/close
> the file once (the closing would be done in the destructor.)  I'll need to read
> up on Ada pointers to better understand what I'm getting myself into.

Just for completeness, the tie does not need to become manifest
as a component. It could be a call, or it could be a message sent
when the Logger_State object is initialized, or finalized.

When the program becomes multithreaded, a question will be whether
multiple loggers should write to multiple files, too. If they should
write to the same file, then this requirement together with a File_Type
component mean that proper serialization of calls needs to be added
to Logger_State in addition.



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2016-05-02  7:36 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-01  3:22 I have no idea why this will not compile John Smith
2016-05-01  4:07 ` Jeffrey R. Carter
2016-05-01  6:47 ` Georg Bauhaus
2016-05-01 21:52   ` John Smith
2016-05-02  7:36     ` Georg Bauhaus
2016-05-01 10:10 ` mockturtle
2016-05-01 20:55   ` John Smith
2016-05-01 23:52     ` Jeffrey R. Carter
2016-05-02  1:02     ` Jeremiah

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