❌ About FreshRSS

Normal view

There are new articles available, click to refresh the page.
Today β€” 28 September 2023Ada Forum - Latest topics

Initializing a discriminated record

By: cantanima
28 September 2023 at 06:06

(If it matters, alr tells me that this is gnat_external=12.3.1; notice the pragma)

I was recently in a situation along these lines:

pragma Ada_2022;

   --  ...

   type Enum is (A, B, C);

   type Disc_Rec (Kind : Enum) is record
      case Kind is
         when A => Field : Natural;
         when others => null;
      end case;
   end record;

   --  ... in what follows, `Thing` is of type `constant Enum` and `Value` is of type 

         D : Disc_Rec := (
            case Thing is
               when A => Disc_Rec'(Kind => A, Field => Value),
               when B | C => Disc_Rec'(Kind => Thing)               --  LINE 37

gnat tells me:

test_enum.adb:37:48: error: no single variant is associated with all values of the subtype of discriminant value "Kind"

Column 47 lands on Thing.

I understand the message, but I’d have thought it clear that since Thing has the type B or C in line 37, Thing has all values of the subtype that matter in this branch. Indeed, if Disc_Rec does not have the case statement that defines Field, and I remove the assignment to Field in line 36, the compiler sings happily. So the problem doesn’t seem to be Thing so much as that the optional Field… which isn’t needed in this branch.

Is there a way to make something like this work? My current workaround handles the branches explicitly (when A => ... , when B => ..., when C => ...), but In a practical case, Kind could have a lot of variants.

3 posts - 3 participants

Read full topic

Before yesterdayAda Forum - Latest topics

AEiC 2024 - Ada-Europe conference - 1st Call for Contributions

26 September 2023 at 12:30

The 28th Ada-Europe International Conference on Reliable Software Technologies (AEiC 2024) will take place in Barcelona, Spain in the week of 11-14 June.

The conference schedule comprises a journal track, an industrial track, a work-in-progress track, a vendor exhibition, parallel tutorials, and satellite workshops.

Deadlines: 15 January 2024 for journal-track papers; 26 February 2024 for industrial-track and work-in-progress-track papers, tutorial and workshop proposals.

More information is available on the conference site, including an extensive list of topics; details on the call for contributions for the various tracks will follow shortly.


#AEiC2024 #AdaEurope #AdaProgramming

1 post - 1 participant

Read full topic

US Government is requesting information on adoption of memory safe programming languages

By: AJ-Ianozi
24 September 2023 at 22:02

Like the title says, the US Government is requesting information on adoption of memory safe programming languages and open-source software security.

They’re currently taking comments until October 9th. I think this is a good opportunity to help bring Ada back into the spotlight.


1 post - 1 participant

Read full topic

[Beginner] A question regarding reading from keyboard

By: Reed
6 September 2023 at 05:44

Hello, I am a beginner at Ada and programming in general. Currently,
I am practising by writing programs that perform operations on text I input via
the keyboard.
I have several questions about the best practices for doing so.

The code below is my learning attempt for different methods for reading:

with Ada.Text_IO; use Ada.Text_IO;
--This program will echo what the user types in.
procedure Main is
   input : Character;
   line_end : Boolean := False;

   Put_Line("Enter some characters.");
   Put_Line("Output is character by character.");
      exit when End_Of_Line;
   end loop;

   Put_Line("This uses strings.");
   Put_Line("Enter a sentence: ");
   Look_Ahead (Item        => input,
               End_Of_Line => line_end);
   if line_end then
      Put_Line ("Arr, end of the line matey");
      Put (input);
   end if;
      s : String := Get_Line;
end Main;

I noticed that the declaration for the String β€˜s’ would read a new line and end the program without myself being able to type any characters.

Question 1: Which part of the code is resulting in a new line being left to read for the Get_Line function? If I add the Skip_Line procedure just before the new line check, I dont have any issues.

Question 2: What is the best practice for reading in things from the keyboard?

I appreciate any hints. Thank you.

3 posts - 3 participants

Read full topic

Basic editing setup in Emacs - does anyone have this working?

By: slondr
4 September 2023 at 15:07

I’m getting back into Ada after a long time away. Emacs is my editor of choice, and it seems like ada-mode has some awesome features out of the box, but not syntax highlighting. By default, in Emacs 29.1, it attempts to defer to eglot for face support, but eglot does not provide face support. It seems that the pre-eglot method of facifying ada-mode buffers was with a bespoke parser called wisi, but when I try to compile that from the elpa source I get a generic β€œfailed to compile” error, even when running alr manually with the highest level of verbosity. ada-ts-mode exists, and highlights syntax correctly, but does not support auto-indentation so it makes for a remarkably poor DX in Emacs, where auto-indentation is the norm.

Does anyone have an Ada setup in Emacs with both syntax highlighting and auto-indentation working?

I see that in the latest release of ada-mode it supports setting the face-backend to other, but there isn’t any documentation that I can find of what to do next to plug in a highlighter of your choice, such as tree-sitter.

6 posts - 4 participants

Read full topic

GNAT-LLVM (for macOS)

26 August 2023 at 15:52

If you want to build a single source file, you can say llvm-gnatmake foo.adb and all will be well. The link is done using llvm-gcc -shared-libgcc.

If you try building with gprbuild (the equivalent of the above would be gprbuild --target=llvm --no-project foo.adb), gprbuild tries to do the link with clang -static-libgcc, which fails because clang doesn’t support that option.

The only way I’ve found round this is to use an actual project with

package Linker is
   for Driver use "g++";
end Linker;

but does anyone know a way of saying the same thing to gprbuild from the command line?

Why g++ I hear you ask? It looks to me as though gprbuild would normally use a C compiler, unless it detects the faintest whiff of C++, in which case it’ll use a C++ compiler, so as to be sure of getting the C++ libraries. It looks on the PATH for a C[++] compiler that’s compatible with the target, llvm, and the only one it finds is /usr/bin/clang[++].

2 posts - 1 participant

Read full topic

Learning resources

25 August 2023 at 12:38

Hi All,
I am interested in learning Ada. I am basically java developer working on web technologies-springboot etc. I saw there are couple of books on Ada but confused from where to start.
What i am looking for is

  1. IDE(i know GNAT studio community edition) and book to begin.
  2. Should i go for Ada-95 or Ada-2012?
    3)Are there any Ada courses(like on Udemy/Udacity etc) to begin with?

6 posts - 4 participants

Read full topic

Ada BFD 1.3.0 release

By: stcarrez
20 August 2023 at 14:45

Ada BFD is an Ada binding for the GNU Binutils BFD library. The new version provides an Alire crate and fixes compilation issues with recent GNU binutils. You’ll also find some (very basic) notes to setup, use the library by loading a program symbol table and finding the nearest source line associated to some program address.

1 post - 1 participant

Read full topic

Two SPARK questions

By: cantanima
17 August 2023 at 20:19

To help learn me some SPARK, I decided to try implementing the Euclidean Algorithm. With a generic type. Basically (simplified from what I actually have, which includes contracts):


   type Ring_Element is private;

   Zero : Ring_Element;

   with function "=" (Left, Right : Ring_Element) return Boolean is <>;
   with function Size (Value : Ring_Element) return Natural;
   with function "-" ( Left, Right : Ring_Element ) return Ring_Element is <>;
   with function "rem"
     (Dividend, Divisor : Ring_Element) return Ring_Element is <>;
package Euclidean is ...

And the body Euclidean:

    function Gcd ( A, B : Ring_Element ) return Ring_Element is

       M: Ring_Element := A;
       N: Ring_Element := B;


       while N /= Zero loop

             R : constant Ring_Element := M rem N;
             M := N;
             N := R;

       end loop;

    end Gcd;

The algorithm has several nice properties. One is a loop invariant that r divides a - b.

I’ve struggled with getting SPARK to accept a contract to that effect. My latest iteration has this:

   if R /= Zero then ( A rem R ) - ( B rem R ) = Zero

…but when I instantiate Ring_Element => Integer it reports

   euclidean.adb:26:41: medium: loop invariant might fail in first iteration, cannot prove (A rem R ) - ( B rem R ) = Zero, in instantiation at main.adb:32 (e.g. when A = -2 and B = 1 and M = 1 and R = 3)[#0]

That… makes no sense. It’s not possible for the algorithm to start with those inputs and end up with R = 3.

  1. Am I misreading the error report?
  2. How does SPARK come up with this value of R?
  3. Any advice on writing a contract for this condition? I’ve generally had trouble with guaranteeing arithmetic expressions like A + B and A - B; I understand why, but am not sure how to handle them. Using rem R was something I thought might help here, it did get me past the under/overflow, and it is also true.

10 posts - 3 participants

Read full topic

Using GNAT Studio with WSL 2

By: mbdj
11 August 2023 at 14:05

I would like to use Gnat Studio on Windows with a remote Alire project on WSL2 (Ubuntu) but I don’t know how to configure WSL as a remote server in Gnat Studio (servers settings in View/Remote menu)
And I don’t know how to run Gnat Studio on Windows with alire on Ubuntu (WSL) : ./alr edit but how to configure an editor on Windows ?
Is it possible ?
Indeed it’s possible with VSCode but I like using GNAT Studio

1 post - 1 participant

Read full topic

GNAT FSF 13 available in Alire [preview]

By: Fabien.C
10 August 2023 at 17:18

Hi all,

We finally have GNAT FSF 13 builds available in Alire, in a separate branch for now. To try it, add an index like so:

alr index "--add=git+https://github.com/alire-project/alire-index#gnat-fsf-13.1.0" --name=gnat_fsf_13 --before=community

Apologies for the delay, this release was particularly difficult to build for no good reasons (GitHub CI, time available, etc.). Also note that the compilers hosted on macOS x86_64 are missing, I will try to make them available ASAP.

1 post - 1 participant

Read full topic

SweetAda on NEORV32

By: SweetAda
9 August 2023 at 11:05

Hi all.

I’ve created a NEORV32 target platform in SweetAda (GitHub - gabriele-galeotti/SweetAda: Ada-language framework).

NEORV32 (GitHub - stnolting/neorv32: πŸ–₯️ A tiny, customizable and highly extensible MCU-class 32-bit RISC-V soft-core CPU and microcontroller-like SoC written in platform-independent VHDL.) is a RISC-V SoC implementation in VHDL, suited for FPGAs.

The setup is blatantly primitive and runs under simulation by means of GHDL, outputting a welcome message inside the simulated UART console. This setup is still WIP, I have to properly integrate the build
machinery with that of the NEORV32 environment.

So far I have no FPGA hardware (besides the time) ready to create a real implementation, so if someone is using NEORV32 on real hardware, and is willing to test, this will be very interesting. Just a OK/KO flag. The current setup needs only UART clocking parameters in the CTRL register, which I suppose it depends on the actual clock configuration. In the meantime I will try to develop things inside the simulated GHDL environment.

Best regards,

3 posts - 2 participants

Read full topic

Basic computer games: rewrite in Ada?

By: stcarrez
7 August 2023 at 08:12

If some of you have free time, want to exercise their Ada skills or learn Ada, it could be fun to provide Ada implementation for some of the 96 basic computer games. The current list of languages include a set of 10 languages. One requirement is that the language must be memory safe. They also speak about a general purpose scripting languages but this is not clear since rust, Java and Kotlin are listed.

17 posts - 5 participants

Read full topic

Announcing Ada binding to the wolfSSL library

3 August 2023 at 20:57

On the WolfSSL blog I saw the following announcement today:

Today we are happy to announce the availability of an Ada/SPARK binding that enables Ada applications to use post-quantum TLS 1.3 encryption through the wolfSSL embedded SSL/TLS library.

It opens the door to obtaining FIPS 140-3 and DO-178C certifications for Ada and Spark applications that use TLS for their encrypted communications and also makes them quantum-safe.

Check out the Ada/SPARK binding on GitHub here: https://github.com/wolfSSL/wolfssl/tree/master/wrapper/Ada

The Ada port is suitable for anything from IoT, embedded systems to Desktop and Cloud systems.

Contact us at [email protected], or call us at +1 425 245 8247 with any questions, comments, or suggestions.

URL to blog post:

1 post - 1 participant

Read full topic

Gnatdoc and generic package parameters

By: cantanima
26 July 2023 at 08:56

gnatdoc doesn’t seem to document generic parameters to a package. Does that sound right?

In case my meaning isn’t clear, the following specification should do the trick. Ask away if not.

-- @summary this commentary appears (as long as there's no space between it and "generic" keyword)
   type T is <>;
   -- commentary on T does not appear
   function "=" ( Left, Right: T ) return Boolean is <>;
   -- commentary on "=" does not appear
package P is
   -- commentary in here appears

7 posts - 3 participants

Read full topic