What kind of package declaration is this?

package https://url.uk.m.mimecastprotect.com/s/mfqZCKZXXu2v186rCva9xD?domain=geometry.io from MagicMoments from the “Programming in Ada 2022”. BTW: strange enough that a program in a book on programming doesn’t compile in the presented form. N.B.: In Ada, from this author. Probably this is left as an exercise to the reader.

It seems just a technical error in some part of the publishing process.

You can fix it, the package is Geometry.IO. Do this, for example:

wget https://www.cambridge.org/files/5617/1654/7225/MagicMoments.txt
sed -i 's%https://url.uk.m.mimecastprotect.com/s/mfqZCKZXXu2v186rCva9xD?domain=geometry.io%Geometry.IO%' MagicMoments.txt 
gnatchop MagicMoments.txt 
gprbuild magic_moments.adb

P.S. The error consists, probably, in some program that has processed the text and has converted Geometry.IO in a URL, simply because .io is a domain. I’ve seen the same happens here if you don’t quote it as code: Geometry.IO :smile:

1 Like

Geometry.IO that’s clear - the actual book says so. Still annoying enough. I’m probably the only one who has downloaded the code so far :sunglasses::crazy_face: Now you even have to reverse engineer code examples. You have to cut all that stuff apart anyway and put it into a neat shape - which, as I said, is incomprehensible to me in a programming book.

Well, not really… at least, it’s not a language limitation.
GNAT itself is limited, in its implementation, in that GNAT cannot have multiple compilation units in a single file.

Well, undoubtedly. I cut it into pieces:

build_list.adb
geometry-circles.adb
geometry-circles.ads
geometry-io.adb
geometry-io.ads
geometry-lists.adb
geometry-lists.ads
geometry-magic.adb
geometry-magic.ads
geometry-points.adb
geometry-points.ads
geometry-squares.adb
geometry-squares.ads
geometry-triangles.adb
geometry-triangles.ads
geometry.adb
geometry.ads
magic_moments.adb
tabulate_properties.adb

…with a little bit perl: perl -ne 'next if /^--/; print' src/magic_moments.adb > src/tabulate_properties.adb a.s.o.

The result runs flawless - as expected.

I expected runnable examples at least on the examples page of a book.

Somewhere in the book the author mentions that single listings are used to safe space.

But this “debate” leads to nowhere - and this forum is the wrong place. The community is not responsible for the layout etc. of the book.

If you’re using GNAT, you already have a tool from the toolchain to split source code in the way required by GNAT. As I showed you, It’s as simple as:

gnatchop MagicMoments.txt

With other compilers, they probably either have a similar tool, or accept the source text as a single file.

Programming in Ada 2022 by Barnes covers the Ada language as defined by ISO, it is not about a specific toolchain. If you’re using GNAT, a good complementary resource will be: Introduction to the GNAT Toolchain — learn.adacore.com

Edit: reference to gnatchop in that tutorial: GNAT Tools — learn.adacore.com

2 Likes

Precious hint - nice tool. Thanks.

I notified the author and he was somewhat horrified that the files had been altered after he sent them to the publisher. I presume he will get them fixed up shortly.

And yes, you will need to use “gnatchop” (or “gnatname”) whenever you want to use GNAT to compile an Ada source file with multiple compilation units. See Handling a file with multiple units

PTC’s ObjectAda and Green Hills’ AdaMulti don’t have such a requirement, though they don’t support as many of the newer language features as does GNAT.

2 Likes