comp.lang.ada
 help / color / mirror / Atom feed
* What does this code mean?
@ 2015-01-08  3:53 John Smith
  2015-01-08  4:37 ` Shark8
  2015-01-08 18:42 ` AdaMagica
  0 siblings, 2 replies; 7+ messages in thread
From: John Smith @ 2015-01-08  3:53 UTC (permalink / raw)


Hello,

I'm working through the wikibook Ada Programming [ https://upload.wikimedia.org/wikipedia/commons/8/8d/Ada_Programming.pdf ].  I came across this example on page 59:

==========================================================
with Ada ;

procedure Convert_Checked is
  type Short is range -128 .. +127;
  type Byte is mod 256;

  package T_IO renames Ada ;
  package I_IO is new Ada (Short);
  package M_IO is new Ada (Byte);

  A : Short := -1; 
  B : Byte;
begin
  B := Byte (A); -- range check will lead to Constraint_Error

  T_IO.Put("A = ");
  I_IO.Put(Item  => A,
           Width => 5,
           Base  => 10);
  T_IO.Put(", B = ");
  M_IO.Put(Item  => B,
           Width => 5,
           Base  => 10);
end Convert_Checked;
==========================================================

And when I compile it, I get this:

==========================================================
% gnatmake -g convert_checked.adb
gcc -c -g convert_checked.adb
convert_checked.adb:13:23: "Ada" is not the name of a generic package
convert_checked.adb:14:23: "Ada" is not the name of a generic package
convert_checked.adb:21:07: "Put" not declared in "Ada"
convert_checked.adb:22:03: "I_IO" is undefined
convert_checked.adb:25:07: "Put" not declared in "Ada"
convert_checked.adb:26:03: "M_IO" is undefined
gnatmake: "convert_checked.adb" compilation error
==========================================================

My question is why is this code written this way?  Is it just plain wrong or am I missing some concept that the author(s) tried to get across that I'm missing?


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

* Re: What does this code mean?
  2015-01-08  3:53 What does this code mean? John Smith
@ 2015-01-08  4:37 ` Shark8
  2015-01-08  9:13   ` Simon Wright
  2015-01-08 18:42 ` AdaMagica
  1 sibling, 1 reply; 7+ messages in thread
From: Shark8 @ 2015-01-08  4:37 UTC (permalink / raw)


On 07-Jan-15 20:53, John Smith wrote:
>
> My question is why is this code written this way?
>  Is it just plain wrong or am I missing some concept that the author(s)
> tried to get across that I'm missing?
>

I think it's wrong -- the "package I_IO is new Ada (Short);" is syntax 
for instantiating a generic package... noticing the space-comma, I think 
there might have been a transcription error -- it is likely this is what 
was meant:


    With Ada.Text_IO;
    procedure Convert_Checked is
       type Short is range -128 .. +127;
       type Byte is mod 256;

       package T_IO renames Ada.Text_IO;
       package I_IO is new Ada.Text_IO.Integer_IO (Short);
       package M_IO is new Ada.Text_IO.Modular_IO (Byte);

       A : Short := -1;
       B : Byte;
    begin
       B := Byte (A); -- range check will lead to Constraint_Error

       T_IO.Put("A = ");
       I_IO.Put(Item  => A,
                Width => 5,
                Base  => 10);
       T_IO.Put(", B = ");
       M_IO.Put(Item  => B,
                Width => 5,
                Base  => 10);
    end Convert_Checked;

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

* Re: What does this code mean?
  2015-01-08  4:37 ` Shark8
@ 2015-01-08  9:13   ` Simon Wright
  2015-01-08 16:44     ` Dirk Heinrichs
  0 siblings, 1 reply; 7+ messages in thread
From: Simon Wright @ 2015-01-08  9:13 UTC (permalink / raw)


Shark8 <OneWingedShark@gmail.com> writes:

> I think it's wrong -- the "package I_IO is new Ada (Short);" is syntax
> for instantiating a generic package... noticing the space-comma, I
> think there might have been a transcription error

Yes, see the online version at
http://wikibook-ada.sourceforge.net/html/convert_checked__adb.htm

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

* Re: What does this code mean?
  2015-01-08  9:13   ` Simon Wright
@ 2015-01-08 16:44     ` Dirk Heinrichs
  0 siblings, 0 replies; 7+ messages in thread
From: Dirk Heinrichs @ 2015-01-08 16:44 UTC (permalink / raw)


Simon Wright wrote:

> Shark8 <OneWingedShark@gmail.com> writes:
> 
>> I think it's wrong -- the "package I_IO is new Ada (Short);" is syntax
>> for instantiating a generic package... noticing the space-comma, I
>> think there might have been a transcription error
> 
> Yes, see the online version at
> http://wikibook-ada.sourceforge.net/html/convert_checked__adb.htm

Hmm, while this program is correct, it differs from the one in the wikibook 
itself: 
http://en.wikibooks.org/wiki/Ada_Programming/Type_System#Type_conversions

Bye...

	Dirk
-- 
Dirk Heinrichs <dirk.heinrichs@altum.de>
Tel: +49 (0)2471 209385 | Mobil: +49 (0)176 34473913
GPG Public Key CB614542 | Jabber: dirk.heinrichs@altum.de
Tox: heini@toxme.se
Sichere Internetkommunikation: http://www.retroshare.org
Privacy Handbuch: https://www.privacy-handbuch.de

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

* Re: What does this code mean?
  2015-01-08  3:53 What does this code mean? John Smith
  2015-01-08  4:37 ` Shark8
@ 2015-01-08 18:42 ` AdaMagica
  2015-01-08 18:45   ` AdaMagica
  1 sibling, 1 reply; 7+ messages in thread
From: AdaMagica @ 2015-01-08 18:42 UTC (permalink / raw)


This seems to be a systematic error. In chapter 13.2.1, you can find the same omission. Somehow everything after the word "Ada" has beend dropped, here ".Unchecked_Deallocation".

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

* Re: What does this code mean?
  2015-01-08 18:42 ` AdaMagica
@ 2015-01-08 18:45   ` AdaMagica
  2015-01-10 21:37     ` John Smith
  0 siblings, 1 reply; 7+ messages in thread
From: AdaMagica @ 2015-01-08 18:45 UTC (permalink / raw)


It seems any units for which there is no corresponding chapter in the book are omitted. (E.g. ".Unchecked_Deallocation" is printed in red.)

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

* Re: What does this code mean?
  2015-01-08 18:45   ` AdaMagica
@ 2015-01-10 21:37     ` John Smith
  0 siblings, 0 replies; 7+ messages in thread
From: John Smith @ 2015-01-10 21:37 UTC (permalink / raw)


Yes, I've noticed that.  Initially I thought that the book was poorly written, but now it seems that when it was turned into a PDF, the conversion process was faulty.

On Thursday, January 8, 2015 at 1:45:59 PM UTC-5, AdaMagica wrote:
> It seems any units for which there is no corresponding chapter in the book are omitted. (E.g. ".Unchecked_Deallocation" is printed in red.)

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

end of thread, other threads:[~2015-01-10 21:37 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-08  3:53 What does this code mean? John Smith
2015-01-08  4:37 ` Shark8
2015-01-08  9:13   ` Simon Wright
2015-01-08 16:44     ` Dirk Heinrichs
2015-01-08 18:42 ` AdaMagica
2015-01-08 18:45   ` AdaMagica
2015-01-10 21:37     ` John Smith

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