Rosetta Code task/Find unimplemented tasks

weird_numbers.adb:47:47: warning: value not in range of type “Ada.Containers.Vectors.Element_Type” from instance at line 11 [enabled by default]
weird_numbers.adb:47:47: warning: Constraint_Error will be raised at run time [enabled by default]
weird_numbers.adb:84:37: warning: value not in range of type “Ada.Containers.Vectors.Element_Type” from instance at line 11 [enabled by default]
weird_numbers.adb:84:37: warning: Constraint_Error will be raised at run time [enabled by default]

I suspected the earlier failure was because the compiler was checking the sum of Positive (the element type) and Natural (the 0 in line 47) and deciding it was invalid. Changing the element type to Natural removes that, but you’re still getting this warning and, presumably, the error?

I’m at a complete loss. I don’t see the warning, nor do I see why I should, and I certainly l don’t encounter the error.

What version of gnat are you running? My toolchain reports

tool #1 gnat:              gnat_native=13.2.2
tool #2 gprbuild:          gprbuild=22.0.1

tool #1 gnat: gnat_external=14.1.0
tool #2 gprbuild: gprbuild=24.0.1

i downloaded gnat 14.1.1 and it does indeed crash with the code on Rosetta Code, but not with the changes i made. can you update to 14.1.1 and see if that fixes your problem? i’ll also fix the entry in Rosetta Code.

Note, added later: Is this a bug? Please answer here.

@Ret_Build_Engineer is using my 14.1.0, which is built from the same source as Alire’s 14.1.1; I find this use of the patchlevel confusing. If it’s built from a tag 14.1.0-1 why not use that as the release ID?

Just added “Word Wheel” - should appear soon.

2 Likes

Regarding operators, given

A := B
     + C;

if only A := B is visible, I initially think that there’s a semicolon missing. I have to make an effort to make sure that’s not true. On the other hand, given

A := B +
     C;

it’s clear that the statement is incomplete, and I need make no effort, so the second form is easier to read and understand. For that reason, my Coding Standard requires the second form.

Regarding this specific case, punctuation, Ada is designed to read much like English text (presuming identifiers are Composed_Of_English_Words). Commas and semicolons are always attached to the thing that precedes them in English, and so should be attached to the thing that precedes them in Ada.

Regarding Strip_Character, as pointed out, C should be a character [so you’d write Index (S, C & "")], and the name Comma_At is poor, and should probably be C_At.

Once those changes are made, the function is simple, clear, and easy to understand. Changing that to avoid recursion would make it more complex and less clear, and so should only be done for a good reason. I have not seen a good reason for changing Strip_Character. (You should always be wary of those who worry about low-level “performance” for no reason.) It is by no means given that recursion will be slower than the overhead of avoiding it.

Thanks a lot JC, your quidelines are great! I see it’s almost like writing natural English which makes things easier to remember :slightly_smiling_face:

I guess this is a matter for potential big debates :slight_smile: I’ve made the exercise of changing the function to be non recursive and with Ada’s arrays it was easy and quite simple. I still think the recursive solution is more elegant though…

Thanks again.

Best regards,
Alexis.

Just added “Word Search” - that was a fun one!
I hope you like my note above the code :slight_smile:

1 Like

Have you measured them to see if there is a difference worth the effort of avoiding the recursion? If it doesn’t, then simplicity and clarity (“elegance”) should determine the choice.

No, I haven’t, but I’d like to try, for the sake of learnng. By the way, is there a way to measure memory usage in Ada? I think it could be interesting to compare that when processing very long strings, could be enlightening.

Best regards,
Alexis

Heh, heh, good one :slight_smile:

I just added an Ada solution to the “Word Ladder” task - mainly to prove that “rust” can go to “hell” :slight_smile:

2 Likes

Phew! I just added an Ada solution for the “Achilles numbers” task, my first own Rosetta code solution:

Lots of learning on the way there. Any comments, suggestions will be very welcome, as usual. Thank you!

1 Like

Hi;

That’s wonderful! :slight_smile: Unfortunately, I do not see it on the Rosetta Code web site :frowning:

Retired_Build_Engineer

1 Like

I just added “Anagram Generator” - as usual it will take a while to appear publicly.

It was rather more involved than I expected, but I did learn a few things along the way.

2 Likes

Great, another one down! Mine was visible this morning already.

Veni, vidi, vici

The Achilles Numbers works great; thanks for your contribution!

Retired_Build_Engineer

1 Like

Thank you for your Anagram Generator!

Works great!

Retired_Build_Engineer

2 Likes

Just added Brace Expansion.

2 Likes

Gentlemen, to continue with the prime number related tasks, I’ve added Ascending primes:

More interesting learning! Should take some time to show, as usual.

1 Like