Not super proud of my solution with this one⦠spoiler
5 posts - 5 participants
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
I wonder if a light runtime attribute might be handy for Alire search?
3 posts - 2 participants
Doesnβt look like Iβll get this one finished tonight, but Iβll create a topic here anyway. Looking forward to seeing everyoneβs solutions.
13 posts - 10 participants
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
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.
Roald
15 posts - 10 participants
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
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
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 least2**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
forHash_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
Iβm having fun building a visualization, so Iβve only finished part 1. Itβs not about the leaderboard, right?
6 posts - 6 participants
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
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
Spent a huge amount of time to understand why Ada.Integer_Text_IO.Get
is unable to read a value from 0:
string . As always I forgot about deprecated integer format, where #
could b replaced by :
. Isnβt time to get rid of this in 2022?
http://www.ada-auth.org/standards/rm12_w_tc1/html/RM-J-2.html
16 posts - 4 participants
Big-time spoilers that would have helped me finish a lot sooner. Most are available elsewhere; e.g., the subreddit.
11 posts - 4 participants
Weβre past halfway!
(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