❌ About FreshRSS

Reading view

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

How does one override an operation with classwide types?

I didn’t think it was possible, but some annotations in the annotated RM seem to indicate it is possible. I’m working with subpools and I want to create some of my own for non heap objects. The problem is that in GNAT they use heap allocation in the function Set_Pool_of_Subpool, which is a required call, so if it is possible to override this, then I would like to so I can have it avoid heap allocation.

For reference from System.Storage_Pools.Subpools:

type Subpool_Handle is access all Root_Subpool'Class;
   for Subpool_Handle'Storage_Size use 0;

function Pool_of_Subpool (Subpool : not null Subpool_Handle)
      return access Root_Storage_Pool_With_Subpools'Class;

procedure Set_Pool_of_Subpool (
      Subpool : in not null Subpool_Handle;
      To : in out Root_Storage_Pool_With_Subpools'Class)
         with Global => overriding in out Subpool;

And the RM annotation (Ada22 annotated RM 20.a/3):

Discussion: Pool_of_Subpool and Set_Pool_of_Subpool are provided by the Ada 
implementation and typically will not be overridden by the pool implementer. 

There is uses the phrasing “typically” which would imply that they could be overridden by an implementer for some cases.

The only way I could come up to override it was to create a derived type of the handle but then the compiler complains when I use “new” with the derived subpool handle type that the handle type isn’t the standard one, so I don’t think that is what the discussion point was referring to (as it would be pointless to override in this way).

To my knowledge you can’t override operations with classwide types. Anyone have any insight into this?

Subpools reference: Storage Subpools

1 post - 1 participant

Read full topic

Running RecordFlux

I’m writing a protocol parser and would like to use RecordFlux to generate a parser from a specification. I’ve been unable to get any recent version of RecordFlux working with the GNAT toolchain from Alire. The wheel on pypi expects a GNAT Studio install with gnatcoll in the path and compiling from source seems to require and even deeper tree of manually built dependencies.

I’m begging anyone at AdaCore to write an alire.toml file.

1 post - 1 participant

Read full topic

Access-to-variable designates constant when trying to pass a pointer to vector element

This question is a follow-up to How to get access to a record field .

The more complex (now) code involves binding a whole vector of records. Something along the lines below:

type Tag is record
  Field : String := "value";
end record;

type Tag_Access is access all Tag;

package Tags_Vectors is new Indefinite_Vectors
  (Index_Type   => Positive,
   Element_Type => Wheel_Tag);

procedure Bind_Tag (T : in out Tag_Access; Stmt : Gnade.Statement) is
begin
    Gnade.Bind_Text (Stmt, T.Field'Address, T.Field'Length);
end Bind_Tag;

procedure Insert_Tags is
  Stmt : Gnade.Statement;
  Tags : Tags_Vectors.Vector;
  --  Make necessary arrangements to populate the Stmt and Tags
  C : Tags_Vectors.Cursor := Tags.First;
begin
  while Tags_Vectors.Has_Element (C) loop
         Bind_Tag (Stmt, Tags_Vectors.Element (C)'Access);
         Tags_Vectors.Next (C);
  end loop;
  Gnade.Step (Db, Stmt);
end Insert_Tag;

I'm not sure what kind of thing Tags_Vector.Element (C) returns. Syntactically, at least, it seems Ada doesn't object to this having an access attribute. But, I don't understand the error (which side does it think is the variable and which side is the constant?) Why is it bad that access to variable designates a constant? (Is it trying to say that I might be changing the value of a constant? -- but I never wanted any of those things to be constants...)

How to get access to a record field

Some general context for my problem first.

I need to bind some arguments of a prepared statement using GNATCOLL SQLite bindings. These bindings expect C character pointer as an input (beside other things). This requirements creates two problems on Ada's end:

Problem 1

The variable pointed to by the "bound" pointer must not perish until the prepared statement is finalized (otherwise it will store a pointer to garbage). But, for queries that operate on the same type of record it would be desirable to extract the part of binding of arguments (which are obtained from the record fields) into a separate procedure. If such procedure returns before the statement is finalized the variables (on the stack of such procedure) will be deleted, and pointers now point to garbage.

Problem 2

I only know of three instances in Ada of creating pointers: new-ing, taking a pointer to a function / procedure and taking a pointer to a variable. Since the bindings want a pointer, I don't know how to extract such a pointer from a record unless I "manually unpack" it into a bunch of local variables. Needless to say this is ugly, repetitive and very prone to copy-and-paste error. This also leads to the lifetime issues (since variables "unpacked" in such a way will be deleted before the actual value they are used to capture still exists.)

Example

type Tag is record
  Field : String := "value";
end record;

type Tag_Access is access all Tag;

procedure Bind_Tag (T : Tag_Access; Stmt : Gnade.Statement) is
  --  This variable will vanish before the statement is executed
  Field : aliased constant String := T.Field;
begin
    Gnade.Bind_Text (Stmt, Field'Address, Field'Length);
end Bind_Tag;

procedure Insert_Tag (T : Tag) is
  --  Necessary connection initialization and building of prepared statement
  Tc : Tag := T;  --  Creating a useless variable only to please the compiler
  Ta : Tag_Access := Tc'Access;
begin
  Bind_Tag (Ta, Stmt);
  --  Here, bindings are dead, so we are executing garbage
  Gnade.Step (Db, Stmt);
end Insert_Tag;

If I may enter a plea

I suspect this may be helped by using objects (i.e. new-ing something). I haven't researched this approach because my first experience with Ada (I'm still learning) was very negative when contracting objects. Deallocation combined with absence of convenient object lifetime management (eg. equivalent of C++ RAII) makes using objects a very daunting task. I would like to stay away from this functionality as much as possible.


Edit

I found a way out of this particular conundrum: turns out SQlite can be instructed to make copies when binding strings. This isn't ideal, but at least I can get the strings into the database.

This doesn't mean that the question is solved though. I'd still like to know a more general way of dealing with record fields. Something that in eg. C would be accomplished by taking a pointer to the struct and then adding the size of the fields preceding the field of interest and adding that the the pointer.

Ada Tech stack

I am trying to learn Ada. I am not into Embedded domain. Mostly Java(Springboot/Mysql etc and now Golang). I would like to know Ada's usage in standard enterprise areas where Java/Golang is used. After referring multiple videos and Reddit posts, i know Ada's usage may not be as high as java/golang, but would like to know what typical tech stack is used for Ada?

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

2023 Day 25: Snowverload

Finally

:snowflake: :snowflake: :snowflake:

Day 25 strikes me as much harder than most Day 25’s, and I ain’t the only one. I mean, come on, 2020 was the year where you basically played a tribute to Zork. (Or maybe it was 2019, and 2020 was the relatively easy discrete log puzzle.)

But today’s puzzle? Part 1 alone should count as a two- or even three-part problem. I won’t even bother covering up the “spoilers”, as I bet revealing them won’t spoil much at all.

The moment I read the problem, I knew it was a graph theory problem. I don’t know much graph theory – I’m not that kind of mathematician; I did real math :wink: with nonlinear polynomials and stuff; see my solution to Day 24 or whatever – so I immediately went to look up stuff on graph connectivity, which I’d heard and read something. That led me to “min cuts”, a new idea to me, then to Karger’s algorithm, and that looked both appealing and tractable, so I said, “aha! let me implement this!”

:stopwatch: :hourglass: :rage:

Three hours and a boatload of annoyance later, I was still struggling to implement Karger’s algorithm. I think I was close, and I may yet get it working, but at this point it was time to spend time with my family, so I did.

When I came to look at it, a stroke of divine inspiration hit – ok, maybe not divine, but it is Christmas so what do I know – and I had the idea to generate a bunch of random paths through the graph and count the edges used. It stood to reason that the edges used most were the load-bearing ones that guaranteed connectivity.

:hourglass: :stopwatch: :face_with_symbols_over_mouth:

A couple of hours and some deep frustration later, I was still struggling to get that working, inasmuch as my top 3 hits consistently disagreed with the example’s 3 edges to remove. I finally surrendered to the temptation to peruse Reddit. Per Reddit, or at least the Reddit solutions I could be bothered to read, most people employ one of two approaches.

  1. Karger’s algorithm to find the min cut of graph.
  2. A Monte Carlo method that picks two random points a fair number of times, on each turn finds a shortest path (shortest seems to be important, which prompted me to switch from using DFS to BFS – the one time I start with DFS it turns out to be counterproductive!), and keeps a running tally of which edges are used most often. The 3 edges that show up most are, with extremely high probability, the edges you want.

Notice anything familiar? Me, too. I asked myself whether I should feel elated or depressed that most other people were taking one of these two approaches, too – elated that, hey, that’s what the experts were doing; depressed that, yeah, I can’t seem to cut it.

I downloadeded Conscious-Money-7663’s Python solution to use as a sanity check against my code. Its top 3 hits agree with the example’s counsel, so I guess something’s wrong with my code.

:hourglass_flowing_sand: :hourglass: :sob:

After an hour or two of fruitless searching for a bug, I said “What the heck” and tried my code on the input.

It worked.

:star2: :star_struck:

It ain’t pretty, but I’ll take the :star2:! From there it was spectacularly easy to finish the puzzle (very easy, same as every Day 25 I’ve done, which now covers 2018…2023).

At some point I’ll go back & try to figure out (a) why my Karger’s Algorithm doesn’t work, and (b) why my Monte Carlo method doesn’t work on the example. But for now I can go :pray: and :sleeping_bed: now, hope my wife doesn’t divorce me, my parents don’t disown me, and my kids haven’t uploaded too many videos complaining that I was spending Christmas trying to solve a stupid puzzle instead of… well, there wasn’t anything else to do, as far as I know, or I’d have done it. But I still got an evil :eye: or two today.

Merry Christmas, even if belated.

5 posts - 2 participants

Read full topic

2023 Day 24: Don't Tell Me The Odds

On Day 18 I wrote:

I don’t suppose he’ll ever supply a puzzle that relies on my old research topics…

Careful what you wish for!

If you’re as stuck on Part 2 as most people were (took roughly an hour for the first 100 people to solve it), take consolation in the fact that quite a few people posting solutions expressed their unhappiness with the puzzle. The most common technique was to reformulate the problem in a way that they then plug it into the Z3 theorem prover.

A few others took a more mathematical approach, sometimes making assumptions on the input. I’m a bit sick, so had trouble either following the explanations, or even looking at their code and making sense of it. I did translate one Python solution to Ada, and thought I’d call it a day after it gave me the right answer.

Unfortunately – or, depending on one’s point of view, fortunately – the discussion had given me another idea, based on the research I conducted in a previous life. The fancy name is “Groebner basis”, but essentially you’re looking at slightly non-linear polynomials. The trick is to make them linear, seeing everything as a nail, I used Groebner bases, but at least one person at Reddit used a different approach.

The only assumption this approach needs is that you can find at least three hailstones that intersect in the x, y plane. Part 1 has you count how often that happens, so that’s a good sign. Call them h_1, h_2, h_3. You’re looking for a position (x,y,z) and velocities dx, dy, dz along with times t_1, t_2, t_3 such that for each i

…and similarly for y and z. Rewrite them with everything on one side and you have nine equations in nine variables. Unfortunately, t_i and dx etc. are unknown, which makes the products t_i dx etc. nonlinear (a couple of Reddit commenters’ claims notwithstanding).

So a matrix won’t work… yet. To fix that, take 6 pairs of equations and multiply strategically in order to cancel the non-linear terms; this is an active research field in the general case, but here’s an example of how it works in this case:

let:

…and r_i is now linear in the variables x, y, dx, and dy. Similar work gives you linear equations for x, z, dx, dz and for y, z, dy, dz.

You need two of each of the three sets of variables: that gives you 6 linear equations in 6 variables, which is “easily” solved using a two-dimensional array in Ada. I write “easily” in scare quotes because I did have to swap rows at least once.

I’m reasonably sure that’s not what the puzzle master intended; I suspect it’s closer to the Python solution I translated. Oh, look: spoiler

PS: oh, this is also ironic. usually the 3-d puzzles inspire :fearful: in me.

5 posts - 3 participants

Read full topic

Trouble running Ada on VSCode M1 Mac

Hello everyone, I hope you are having a happy holiday.

The thing is, I have a problem understanding why I can't run Ada on VSCode, don't know if it's a compiler problem or something.

I have the gcc compiler that I downloaded for Objective-C and C++ in the past, this is what the terminal throw when I run --version

Apple clang version 15.0.0 (clang-1500.1.0.2.5) Target: arm64-apple-darwin23.1.0 Thread model: posix InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin 

Next, I followed the instruction of the GitHub page of Getting Started with Ada, but the follow errors are shown:

can't find a toolchain for the following configuration: language 'Ada', target 'aarch64-darwin', default runtime 

shown on .gpr

No project found in root directory. Please create a project file and add it to the configuration. 

shown on .adb

Tried to follow the simonjwright well written readMe, but can't figure what to do.

Thank you very much!

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

Overthinking “new”: Types vs Records

Hello,

When I declare a record in the heap I use:

declare type my_record is record: my_var : Integer; end record; type my_record_access_type is access my_record; record_1 : my_record_access_type; record_2 : my_record_access_type; begin record_1 := new my_record; record_1.my_var := 1; record_2 := record_1 record_2.my_var := 2; end 

So here’s what we did: - Declare a record with one variable, my_var of type integer. - Declare an access type that will point to the type, my_record. In my brain this is like saying “Declare an array filled with integers” except here we’re saying “declare an access type that is filled with the necessary information to access my_record(s)” - Declare two instances of this access type - Begin - Instantiate the first record we declared. Because we use “new”, it will do it on the heap. - set the variable in the record to 1; - make a reference of record_1 and save it in record_2. Since record_1 is an access type, record_2 is only a second name (alias) for record 1. - change the value of the variable in the record (the one and only record with two names) from 1 to 2. - end

Is that correct?

Secondly, I see multiple ways to make new types:

package types is type distance1 is new Float; type distance2 is range 0..100; — No new because range? type distance is Integer; — why no new here? end types 

Clearly the type creation “new” is different than the object creation new. However, the nuance of when to use “new” in type creation eludes me.

Would someone please provide some guidance?

I’m familiar and comfortable with C++ if using an analogy is helpful and appropriate.

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

2023 Day 23: A Long Walk

Took me a while to get around to this one, because Day 21 set me back one day. Day 22 was straightforward (more or less) and while I got Day 23, it took a good long while.

Part 1 is straightforward, I think.

For Part 2, spoiler That gives me the right answer, but it still takes too long (several minutes! with several million paths queued up!), so I went to look at Reddit commentary and there everyone is basically doing what I’m doing, but using spoiler instead.

I really have to brush up on the advantages of each, since I don’t quite understand why that approach takes them milliseconds, whereas my approach takes minutes.

Added in later: Found my answer spoiler

So, spoiler in the worst-case scenario is oldsymbol{O(b^d)} because that’s the worst-case size of the frontier.

So, the worst-case space complexity of spoiler is oldsymbol{O(bd)}.

Added in much later: I take that back. spoiler

4 posts - 2 participants

Read full topic

Bridge returned error 0! (19713)

Details

Type: HttpException
Code: 0
Message: cURL error Failed to connect to tomekw.com port 443 after 189 ms: Couldn't connect to server: 7 (https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://tomekw.com/feed.xml
File: lib/http.php
Line: 127

Trace

#0 index.php(11): RssBridge->main()
#1 lib/RssBridge.php(113): DisplayAction->execute()
#2 actions/DisplayAction.php(71): DisplayAction->createResponse()
#3 actions/DisplayAction.php(106): FilterBridge->collectData()
#4 bridges/FilterBridge.php(168): FeedExpander->collectExpandableDatas()
#5 lib/FeedExpander.php(88): getContents()
#6 lib/contents.php(67): CurlHttpClient->request()
#7 lib/http.php(127)

Context

Query: action=display&bridge=Filter&url=https://tomekw.com/feed.xml&filter=Ada&filter_type=permit&format=Atom
Version: 2023-09-24
OS: Linux
PHP: 8.2.7

Go back

Frenzie, ORelio

2023 Day 21: Step Counter

I’ve only finished Part 1 so far, but here are some thoughts on Part 2. While it’s not implemented yet, it should be the right track: when testing it by hand on a much smaller example, I come too close to the brute-force answer to make me think the mistakes are anything other than due to hand computation / numbers-slightly-off / etc.

Sorry if this seems far too long, too detailed, or too annoying with blurred spoilers-which-perhaps-aren’t, but if anyone sees an invalid assumption, I would be grateful!

  • Once the elf visits a plot, he cannot visit it again except on multiples of 2, on account of the limited number of directions available. That is, if he first visits the plot in row 5, column 12 on step 7, then he will only visit that plot on odd-numbered steps.
  • In my input, and I suspect in all inputs, the number of steps is 65 + x * 131, where x is a Very Large Number :tm:, 131 is the dimension of the square, and 65 is the number of steps it takes to get from the starting point, which is in the middle, to the end of the square.
  • Unlike the example – and this is a big deal!spoiler
  • As the elf explores, you get spoiler
  • You can thus consider separately squares spoiler
  • Rspoiler the number of squares visited in the cardinal directions, but they’re not all full: spoiler We’ll return to this speed bump in a moment.
  • In each column not in a cardinal direction (e.g., the column with squares G, E, and C; or, the column with just G and E), spoiler
  • So it’s relatively easy to count the number of full squares, spoiler That product gives the number of plots the elf can visit in all the full squares. spoiler
  • Likewise, it should be relatively easy to brute-force count the number of plots the elf visits in squares that aren’t full, because you know the shortest number of steps it takes to arrive there, and you can explore from that entrace position. Again, the fact that movement is limited to the cardinal directions helps you here: in a box to the northwest of A, for instance, the earliest entrance is in a southeast corner, so explore from there for the number of steps remaining.
  • Add the values in these last two steps and you should have the answer.

I suspect the reason my hand computation is wrong is that I’m slightly off on the next-to-last step. I’ll look at it more later…

5 posts - 2 participants

Read full topic

AEiC 2024 - Ada-Europe conference - grants for Open Access publication

Season’s greetings from the organizers of the 28th Ada-Europe International Conference on Reliable Software Technologies (AEiC 2024), to be held 11-14 June 2024, in Barcelona, Spain!

Accepted Journal Track papers will be published in the conference’s Special Issue of the Journal of Systems Architecture (JSA). Note that the Ada-Europe organization will waive the Open Access fees for the first four accepted papers, which do not already enjoy OA from other agreements with the Publisher.

www.ada-europe.org/conference2024/cfp.html#cfpjournal

#AEiC2024 #AdaEurope #AdaProgramming

1 post - 1 participant

Read full topic

AEiC 2024 - Ada-Europe conference - grants for Open Access publication

Season's greetings from the organizers of the 28th Ada-Europe International Conference on Reliable Software Technologies (AEiC 2024), to be held 11-14 June 2024, in Barcelona, Spain!

Accepted Journal Track papers will be published in the conference's Special Issue of the Journal of Systems Architecture (JSA). Note that the Ada-Europe organization will waive the Open Access fees for the first four accepted papers, which do not already enjoy OA from other agreements with the Publisher.

www.ada-europe.org/conference2024/cfp.html#cfpjournal

#AEiC2024 #AdaEurope #AdaProgramming

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

Record size from a lib differs from one executable to another

Hi,

I'm facing a problem that leaves me extremely perplexed (I can hardly believe what I'm seeing). I have a library that defines a record. This record will be used to instantiate a shared memory between different executables.

The first executable calls a function in this library which will create the shared memory. The other executables will communicate through it. Except that it doesn't work. After hours of debugging, I noticed that the size of my structure (aspect 'Size) is different between the first executable and the others: it's 4 times smaller!

Everything was recompiled and tested multiple times to make sure this was the case. In every executables, 'Size and 'Object_Size are the same. Printing the size of the record in the package initialization returns the correct value, the one used by every executables except the first one.

I think this will leave you really perplex too. Have you ever encounter a similar issue?

I believe there is a way to ask the gnat compiler (or gprbuild) for a file that gives the size given for each types, right? Which flag is it?

Thanks for your help.

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

2023 Day 20: Pulse Propagation

I usually look at the general leaderboard for each problem to get an impression of how difficult the “experts” find it. It surprises me that the general leaderboard for day 20 suggests that this has been the hardest problem so far: nearly 49 minutes for the first 100 participants to complete it! The only one that came close to this relative difficulty was day 10, with 36 minutes before the first 100 participants completed it.

Day 20 didn’t seem that complicated to me. So long as you read the problem carefully, and I do mean carefully, part 1 is possibly the most straightforward problem yet. The only thing that makes part 2 challenging is that the answer is a “ludicrous size” number, so you don’t want to wait around for it. But the technique to make it work has already been used with other problems: spoiler

1 post - 1 participant

Read full topic

2023 Day 19: Aplenty

Today’s puzzle is cute:

To start, each part is rated in each of four categories:

* `x`: E*x*tremely cool looking
* `m`: *M*usical (it makes a noise when you hit it)
* `a`: *A*erodynamic
* `s`: *S*hiny

Kind of embarrassed how I didn’t notice what the categories “spelled out” at first.

I solved it in a manner similar to Day 5: spoiler

Using the original example:

  • Start at in with intervals (1,4000),(1,4000),(1,4000),(1,4000).
  • The rule s < 1351 applies, so spoiler

…and so forth. When a group visits A, add the group’s number of intervals to the running total; when a group visits R, spoiler.

6 posts - 3 participants

Read full topic

Exceptional_Cases aspect

Hello,

I would like to use the Exceptional_Cases aspect described in this post. However, it seems that the latest version of GNATprove (13.2.1) available on Alire does not include the feature. Does anyone know if there is any community version of GNATprove that supports it?

Thank you,
Daniel

2 posts - 2 participants

Read full topic

❌