❌ About FreshRSS

Reading view

There are new articles available, click to refresh the page.

Where is Sparklib?

I wanted to try out some of the formal containers for SPARK, but I am having trouble finding the Sparklib mentioned in the Spark docs. My GNAT Studio doesn’t have a SPARK category under Help, as the SPARK manual mentions, and I usually do everything with ALR. I do see the SPARK Lemma libraries in my ALR cache of Gnatprove, but not the other libraries.

3 posts - 3 participants

Read full topic

New user restriction

Hi all,

I noticed that as a new user I cannot post more than three replies on the same topic. While I understand the rationale of this it makes it impossible for me to take part in the Advent of Code thread (at least not for more than three days). The proposed workaround in the popup to edit a previous reply doesn’t work as I don’t seem to be able to edit my older posts anymore.

What exactly are the criteria to be not considered as a new user anymore? And is there a way to remove this restriction from the Advent of Code thread (as I might not be the only one with this problem)?

4 posts - 2 participants

Read full topic

Object-oriented methods in Ada

Having written Java code for a few decades, there are some facets that I find to be a “must” (without having any good reason for it). One such thing is the way object-orientation makes use of methods. So, while I now try to learn myself Ada (have some PL/SQL experience), I find myself searching for method declaration.

As everyone who has coded Java knows, a method is written as a function within the class declaration. When the method is called, it is called as something that belongs to the class (or rather the object).

Ex. A Java class C may have a method m(x, y, …). And object o of class C can then use this method through the call:
o.m(x, y, …)

Having search (or skimmed) through both literature and the net, it is my understanding that the closet we get in Ada is to have a procedure or a function, with the first argument being of the containing type, declared in the type declaration, and then calling that proc/func by passing a variable of that type as the parameter (sorry if I mess this up, I know what I’m thinking, but putting it in writing is less clear). This would lead to a proc/func call similar to:

m(o, x, y, …)

Or have I missed something?

What is the “correct” object oriented way of writing the following in Ada?
public class Hello
{
public void SayHello()
{
System.out.println( “Hello World!”);
}
}

And similar upon use:
{
Hello greeting = new Hello();
greeting.SayHello();
}

Your help and patience are appreciated.

:slight_smile: Roald

15 posts - 10 participants

Read full topic

What is the purpose of "=" in Containers.Hashed_Sets?

Containers.Hashed_Sets is a generic package that reclaims Element_Type, Hash function, Equivalent_Elements function and "=" function.
Why there is two functions to specify equivalence/equality?

generic
   type Element_Type is private;
   with function Hash (Element : Element_Type) return Hash_Type;
   with function Equivalent_Elements (Left, Right : Element_Type)
                 return Boolean;
   with function "=" (Left, Right : Element_Type) return Boolean is <>;
package Ada.Containers.Hashed_Sets is

https://docs.adacore.com/live/wave/arm12/html/arm12/arm12-A-18-8.html

8 posts - 3 participants

Read full topic

2022 Day 9: Rope Bridge

I think the problem statement was intentionally difficult to parse this time. Those conditionals are a lot simpler than it makes them sound.

I kept the visited positions in a Hashed_Set and coming up with a good Hash function for a pair of Integers was new for me. I ended up making a lot of assumptions (Integer'Size = 32 and Hash_Type'Size = 64) and just shifted one of the integers left 32 bits. A cursory Google search turned up the Cantor Pairing function, but I wasn’t able to make this work with negative integers in a short amount of time. Clearly I need to do more reading.

Part 2 caught me off guard, I hadn’t anticipated I’d need to deal with more elements.

Note: I’m going to stop using the spoiler blur on the daily posts. If you’ve gotten this far, I assume you know that these posts contain spoilers.

13 posts - 8 participants

Read full topic

Ada.Containers.Hash_Type'Size

I’ve been playing with optimizations for an instance of Ada.Containers.Hashed_Sets for the Advent of Code Day 9 puzzle.

RM A.18.1 The Package Containers says:

type Hash_Type is mod implementation-defined;

With the Implementation advice:

Hash_Type'Modulus should be at least 2**32.

The annotated RM expands upon this:

This is not a requirement so that these types can be declared properly on machines with native sizes that are not 32 bits. For instance, a 24-bit target could use 2**24 for Hash_Type'Modulus.

In GNAT’s a-contai.ads, the definition is simply:

type Hash_Type is mod 2**32;

Would it make sense to use System.Max_Binary_Modulus instead, so that 64-bit systems can benefit from a larger hash space?

type Hash_Type is mod System.Max_Binary_Modulus;

If we want to retain the minimum 32-bit size, a conditional could be added:

type Hash_Type is mod (if System.Max_Binary_Modulus >= 32 then System.Max_Binary_Modulus else 32);

1 post - 1 participant

Read full topic

Aggregates as initial value of an array

Hello!
I’m stuck with this array construct.
Can’t find the syntax clue to initialize an array of records, with the particularity I aim to pass the array as an in out variable, without needing to pass en extra index (ID) info.

(for K_ID in Knot_ID => ^
Compile error: missing “,” at ^

even with -gnat2022 and -gnatX switches, or pragma Ada_2022;

   subtype Knot_ID is Integer range Head_Knot .. Tail_Knot;
   type Grid_Position is record 
      X : X_Dimension;
      Y : Y_Dimension; 
   end record;

   type Knot_record is record
      ID : Knot_ID;
      Pos : Grid_Position;
   end record;

   type Rope_array is array (Knot_ID'Range) of Knot_record;

(...)

   Rope_Positions, Previous_Rope_Positions : Rope_array := 
--    (others => (ID => Head_Knot, Pos => (0,0)));  --:FIXME:  ID => Knot_ID'Range
      (for K_ID in Knot_ID => (ID => K_ID => (ID => K_ID, Pos => (0,0))));

see Ada 2012/2012 Array Aggregates
see Overview of Ada 2022
Compiler is FSF gcc-gnat 12.2.0

William

3 posts - 2 participants

Read full topic

Various questions about Ada

I have a few Ada questions that I’ll just summarize in one post.

If I always have to completely rewrite a file, then it makes no difference whether I use Open or Create. Is that correct or did I miss something?

Currently I use Stream_IO to write files, the files contain different data types. Do other writing methods, such as Sequential_IO, produce smaller files that justify the extra effort to use them? Or are they practically all equally efficient?

I use Pure, Preelaborate and Elaborate_Body whenever possible. However, I have some files that don’t allow Pure/Preelaborate and since they don’t have a body, Elaborate_Body isn’t possible either. However, I would still like to know if there is a circular dependency. Are there any other options besides giving all files a body?

Is there a standard function that returns the number of elements in an enum subtype, or do I have to write it myself?

6 posts - 4 participants

Read full topic

2022 Day 13: Distress Signal

We’re past halfway! :grin: :dark_sunglasses: :grinning: :sunglasses: :fireworks: :sparkler: :partying_face:

(The downside is that the problems have suddenly stepped up in difficulty!)

For the second day in a row, writing a program that solves the example wasn’t enough. Twice I ran it and got solutions that were rejected as too large. I had to comb through some of the pairs that my program claimed were legitimate. In both cases, it was the case where I had to compare a number and a list. The instructions are to create a new list that includes the number, then compare the lists, but it seemed equivalent to me simply to compare the number with the first element of the list. This produced false positives. I haven’t quite figured out why, though.

Curiously, in part 2 I was able to make it work simply by spoiler

5 posts - 5 participants

Read full topic

❌