❌ About FreshRSS

Normal view

There are new articles available, click to refresh the page.
Before yesterdayAda Forum - Latest topics

[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;
begin

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

   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");
   else
      Put (input);
   end if;
   ------------------
   declare
      s : String := Get_Line;
   begin
      
      Put_Line(s);
   end;
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):

generic

   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;

    begin

       while N /= Zero loop

          declare
             R : constant Ring_Element := M rem N;
          begin
             M := N;
             N := R;
          end;

       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,
G

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:
https://www.wolfssl.com/announcing-ada-binding-to-the-wolfssl-library/

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)
generic
   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

Cashe: A Money library for Ada

By: AJ-Ianozi
23 July 2023 at 23:11

Introducing Cashe: a Money library written in Ada!

There’s quite a bit of examples in the readme, but I also gave full code examples for almost all of the functions in the API Documentation.

The purpose of Cashe is to give Money its own high-precision datatype taking advantage of Ada’s fixed type decimal system. This allows storing money, associated with a currency, at a defined precision with the choice of utilizing fuzzy or exact equality (see readme for more details).

It supports Ada-ISO Currencies as well as Custom-defined currencies, and even a working Currency Exchange.

While this is technically in pre-release, it’s passing all of my unit tests and I’m working on getting the version 1.0 out and into Alire soon.

1 post - 1 participant

Read full topic

[SOLVED] How do i add constraints/contracts to a generic parameter?

By: cantanima
21 July 2023 at 20:03

I’m trying to learn SPARK by implementing a Euclidean Ring package. (Don’t let the mathematics scare you; it’s not really relevant.) The package is generic, with several parameters that needs specification. Among these are a Size function, a Zero function, and a rem function.

If SPARK is to have any prayer at all of proving correctness, the rem function needs a constraint along these lines:

    generic

       -- a bunch of stuff omitted

       with function "rem" ( Dividend, Divisor : Ring_Element ) return Ring_Element
          is <>
              with
                 Pre => Divisor /= Zero,
                 Post => (
                             "rem"'Result /= Zero
                          or else Size ( "rem"'Result ) < Size ( Divisor )
                         )
       ;

…and the compiler chokes on the contracts:

euclidean.ads:39:13: incorrect placement of aspect "Pre"
euclidean.ads:40:13: incorrect placement of aspect "Post"

Originally I tried placing it before the is <> but that didn’t work, either.

So… where does one specify constraints for the parameters to a generic?

6 posts - 3 participants

Read full topic

❌
❌