Standard library & algorithms

Hello.

Is there a place for newcomers where they can go to browse Ada standard library documentation with links to implementation? In particular, I have trouble finding any info online about the algorithms/numerics libraries.

I found this: gcc/gcc/ada/libgnat at master · gcc-mirror/gcc · GitHub
but the way file the files are named suggests that this is not supposed to be browsed and anyway, it’s only the implementation so not something that can be read as quick reference and documentation by beginners like me. The problem is that my eyes are not accustomed to Ada so even if I have the code, there is a lot of stuff in the code that shouldn’t concern me, yet here I am so I’m clearly looking in the wrong place.

So is there a place that can be looked up conveniently when I want to check for facilities like iota, accumulate, filter, reduce, map and so on?

For reference, Rust has:

while C++ has:
https://en.cppreference.com/w/cpp/algorithm/reduce

Floyd

Annex A of the reference manual.

You can also use search.ada-lang.io to find and browse packages in the Alire index, which may have useful comments.

‘Map and ‘Reduce are attributes in Ada 2022, more info here: Ada 202x support in GNAT | The AdaCore Blog

2 Likes

Just as a note, the implementation will always vary with the compiler vendor. So to find a specific implementation you need to reference the vendors source code or docs.

In the Ada Programming wikibook, you have a page for each standard library unit, each one with, as a minimum, the specification, link to the reference manual, and links to two different open-source implementations. There are even cases where someone has contributed some explanations and examples!

https://en.wikibooks.org/wiki/Ada_Programming/Libraries/Ada

2 Likes

That’s a side effect of a past era in which filenames were limited to 8 characters, but those are indeed the implementations. A simpler way to inspect a particular body is, if you’re using GNAT Studio, to use the Help → GNAT Runtime menu that will take you to the spec you want, and then right-clicking anywhere choose Jump to implementation file.

Or, in any file you’re editing, Ctrl+click the name of the package you want to visit.

1 Like

I know it isn’t beginner friendly but if you ever need to find a specific package file name you can use the gnat krunch command with the length set to 8. You just supply the .ads to the command. As an example:

$ gnatkr Ada.Containers.Bounded_Vectors.ads 8
a-cobove.ads

It’s basically a GNAT thing (The Ada standard doesn’t dictate how a compiler names its standard library files).

Back when I was writing a zero footprint runtime, I thought I would be all awesome and use more descriptive names like ada-containers-bounded_vectors.ads. It compiled fine UNTIL I had to link to it in an application, then it couldn’t find the file. Krunching the name made everything work. So GNAT forced me to use the awful krunched names in my runtime. Made me sad.

I threw together this Python script a while ago to create symlinks to all of the gnat packages with usable filenames. It’s not very robust, but it works for me.

2 Likes

WOWWWW! I’ve been wanting such a tool! THANK YOU

Retired_Build_Engineer

1 Like