Normal view

There are new articles available, click to refresh the page.
Before yesterdayNews from the Ada programming language world

object "Antal_rader" cannot be used before end of its declaration

OBS! My code is written with Swedish terms.

I have to code a VAT table but i have run in to some problems concerning Floats and the way that it rounds values. At first, I was using a while loop but that didn't work since it (after a while) got too affected by the float-issue.

I created a For-loop instead which in theory should work better. However. I'm having an issue with one of my variables.

The variable "Antal_Rader" is being declared before the For-loop but i still get the error code: "object "Antal_rader" cannot be used before end of its declaration"

Code:

with Ada.Text_IO;              use Ada.Text_IO;
with Ada.Float_Text_IO;        use Ada.Float_Text_IO;

procedure Momstabellen is
   Forsta_Pris : Float;
   Sista_Pris : Float;
   Steglangd : Float;
   Momsprocent : Float;
   Moms : Float;
   Antal_Rader : Float;
   Nuvarande_Rad : Float;
   
   
begin
   -- 1. Ta emot alla variabler för momstabellen:
   Put("Första pris: ");
   Get(Forsta_Pris);
   while Forsta_Pris < 0.0 loop
      Put("Felaktigt värde!");
      New_Line;
      Put("Första pris: ");
      Get(Forsta_Pris);
    end loop;
   
   Put("Sista pris: ");
   Get(Sista_Pris);
   while Sista_Pris < Forsta_Pris loop
      Put("Felaktigt värde!");
      New_Line;
      Put("Sista pris: ");
      Get(Sista_Pris);
   end loop;
   
   Put("Steg: ");
   Get(Steglangd);
   while Steglangd < 0.0 loop
      Put("Felaktigt värde!");
      New_Line;
      Put("Steg: ");
      Get(Steglangd);
   end loop;
   
   Put("Momsprocent: ");
   Get(Momsprocent);
   while Momsprocent < 0.0 or Momsprocent > 100.0 loop
      Put("Felaktigt värde!");
      New_Line;
      Put("Momsprocent: ");
      Get(Momsprocent);
   end loop;
   New_Line;

-- 2. Skapa en layout för momstabellen:
   Put("============ Momstabell ============");
   New_Line;
   Put("Pris utan moms  Moms   Pris med moms");
   New_Line;

Issue lies here:

   

   Antal_Rader := (Sista_Pris - Forsta_Pris)/Steglangd;
   
   for I in 0 .. Antal_Rader loop
      
      Nuvarande_Rad := Antal_Rader * Steglangd + Forsta_Pris;   
      Moms := Nuvarande_Rad/100.0 * Momsprocent;
      
      Put(Nuvarande_Rad, Fore=> 6, Aft => 2, Exp => 0);
      Put(Moms, Fore => 8, Aft => 2, Exp => 0);
      Put(Nuvarande_Rad + Moms, Fore => 9, Aft => 2, Exp => 0);
     
   end loop;
    
     
end Momstabellen;

I have tried changing the first line of the For-loop and also tried changing the position of "Antal_Rader" but nothing has worked.

I am quite new to this so i can't think of many more things to do.

[ANN] GNAT Studio 24.0 for macOS Ventura.

Hello,

Here is a very preliminary version of GNAT Studio 24.0wa as a stand alone app for macOS 13:

https://sourceforge.net/projects/gnuada/files/GNAT_GPL%20Mac%20OS%20X/2023-ventura

See readme for details.

Limitation: Ada Language Server has some latencies and doesn't respond when parsing source code with more 1000 lines. It may be due to some compilation options I missed.

There could be some other limitations that you might meet.

Feel free to report them on MacAda list (http://hermes.gwu.edu/archives/gnat-osx.html).

Any help will be really appreciated to fix these limitations.

Enjoy, Pascal.

submitted by /u/Blady-com
[link] [comments]

[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

Ada task gets stuck on running

I have been facing on a problem about Ada task without getting know what it is root cause and consequenrly, without getting it solved. This is the first time I get this problem working with Ada task.

I have a package "pkg1" which it has a task that runs on loop periodically. One of the actions of this task is to call to a protected object that is on package "pkg2" in order to get some data. These data are updated by another task of other package "pkg3". Next action of the task of package "pkg1" just after previous one (calling to a protected object) is to call a procedure "proc1" that it is on package "pkg1" that calls to a procedure "proc2" that is on package "pkg4". Task of package "pkg1" gets stuck on the calling of procedure "proc2" of package "pkg4". It doesn't end calling to "proc2" of package "pkg4". Even more, it doesn't run any action of that procedure "proc2". Rest of tasks continúe running, but task of package "pkg1" gets stuck at that point.

It would be very much appreciatef if someone could give any idea about what causes it and how to solve it. Thank you in advance

submitted by /u/VaroDev
[link] [comments]

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

LEA: first steps as a "smart editor"

2 September 2023 at 19:53

Note for subscribers: if you are interested in my Ada programming articles only, you can use this RSS feed link.


Spot the "tool tip" on the following screenshot...

Click to enlarge

Translation: cross-references and source code navigation in LEA are becoming a reality since this evening!

 


Some Web links:

LEA

Web site: http://l-e-a.sf.net/
Sources, site #1: https://sf.net/p/l-e-a/code/HEAD/tree/
Sources, site #2: https://github.com/zertovitch/lea
Alire Crate: Alire - LEA


Since LEA embeds the HAC compiler, here are a few links about HAC as well:

HAC

Web site: https://hacadacompiler.sourceforge.io/
Sources, site #1: https://sf.net/p/hacadacompiler/code/HEAD/tree/
Sources, site #2: https://github.com/zertovitch/hac
Alire Crate: Alire - HAC

Ada Alire GNATColl_Postgres Installation failed

I am trying to get gnatcoll_postgres into C:\GNColl_Postgresql using Alire on Windows 10. But the process failed while installing mingw-w64-x86_64-postgresql.

The errors message are as follows:

error: mingw-w64-x86_64-mpc: signature from "David Macek <[email protected]>" is unknown trust
:: File /var/cache/pacman/pkg/mingw-w64-x86_64-mpc-1.2.1-1-any.pkg.tar.zst is corrupted (invalid or corrupted package (PGP signature)).
Do you want to delete it? [Y/n]
error: mingw-w64-x86_64-bzip2: signature from "David Macek <[email protected]>" is unknown trust
:: File /var/cache/pacman/pkg/mingw-w64-x86_64-bzip2-1.0.8-2-any.pkg.tar.zst is corrupted (invalid or corrupted package (PGP signature)).
Do you want to delete it? [Y/n]
error: mingw-w64-x86_64-termcap: signature from "David Macek <[email protected]>" is unknown trust
:: File /var/cache/pacman/pkg/mingw-w64-x86_64-termcap-1.3.1-6-any.pkg.tar.zst is corrupted (invalid or corrupted package (PGP signature)).
Do you want to delete it? [Y/n]
error: failed to commit transaction (invalid or corrupted package)
Errors occurred, no packages were upgraded.
ERROR: Deployment of system package from platform software manager: mingw-w64-x86_64-postgresql to C:\GNColl_Postgresql\gnatcoll_postgres_23.0.0_adf8e40f\alire\cache\dependencies\postgresql_15.1.0_system failed

Any idea on how to resolve this issue. Thanks in advance. Regards. Angelo.

September 2023 What Are You Working On?

Welcome to the monthly r/ada What Are You Working On? post.

Share here what you've worked on during the last month. Anything goes: concepts, change logs, articles, videos, code, commercial products, etc, so long as it's related to Ada. From snippets to theses, from text to video, feel free to let us know what you've done or have ongoing.

Please stay on topic of course--items not related to the Ada programming language will be deleted on sight!

Previous "What Are You Working On" Posts

submitted by /u/marc-kd
[link] [comments]

How to rename standard library functions

I am unsuccessfully trying to rename Put_Line() as print().

I get this is silly, but it's just for my ease. Is this possible?

My code so far:

with Ada.Text_IO;

use Ada.Text_IO;

procedure Hello is

function print renames Put_Line;

begin

print("Hello, test world!");

New_Line;

print("I am an Ada program with package use.");

end Hello;

submitted by /u/SachemAgogic
[link] [comments]

find image tags with alt attribute without double quotes and replace with empty double quotes

<img src="first.jpg" alt="first" width="500" height="600" />
<img src="second.jpg" alt width="500" height="600" />
<img src="third.jpg" alt="third" width="500" height="600" />
<img src="fourth.jpg" alt width="500" height="600" />
<img src="fifth.jpg" alt="" width="500" height="600" />

find image tags with alt attribute without double quotes and replace with empty double quotes for ADA accessibility, I need to jquery to find second and fourth img tags replace with alt="" just like fifth. This is sample html markup, a page can have this instances 10 or 20 instances, all these should be replaced with alt=""

I tried this below didn't work

$(function() {
  $("img").each(function() {
    if (this.alt) {
      console.log(this.alt);
    } else {
      $(this).attr('alt', "");
    }
  });
});
❌
❌