I have a simple query to those who are a bit more adept with Ada than I regarding Rosetta Code tasks in general.
There is no task currently that is the logical opposite of “Find unimplemented tasks”…why not create one called “Find implemented tasks”?
I’ve been trying to generate (manually, with some scripts) to “clone” various Rosetta Code Tasks for various languages (not just Ada). It would be nice to have a script that would generate all the tasks that have been completed in a specific language that I coulod query against to see that I have “cloned” that task for that language.
It seems to me to be a simple enough request; just to reverse the logic…but I did not see how to actually implement the idea.
The Find unimplemented tasks actually does that. It first gets all the tasks for the language given in the parameters, then gets all tasks and check which are not in the language. The API query is:
https://rosettacode.org/w/api.php?action=query&list=categorymembers&format=xml&cmlimit=500&cmtitle=Category:<put the language name here>
You could probably extract the code for your query from it.
By the way, there are some tasks that, through the template {{omit from|Ada}} are omitted from Ada. A review of that list should be done, because, for example, couldn’t one implement OLE automation in Ada using GNAVI? @zertovitch?
Hi all,
I’m now looking at the “Rosetta Code/Rank languages by popularity” task. It’s implemented but not working, so I’m giving it a go at fixing it too. Got it to get the page data, had to change the URL and add a Follow_Redirection => True because it’s returning a 301 now. I have doubts about the web scraping method. You can get 5000 categories with “&limit=5000”, which seems to be the absolute limit on the page, but then how do you get next ones? I’ve been going through Rosetta for a while and can’t find any information about this.
Thank you as always!
Edit: Well, there’s only about 12 categories after the first 5000, so it won’t make much of difference, but still…
Hah! Definitely will try to get some uninplemented ones done asap! I’m currently working on fixing the Ada version of that same list It’s quite broken, but should be done soon.
Ah! Would anyone be kind enough, if they have time, to give it a look and let me know if there’s anything there that’s not proper according to Ada best practices, please? Would love some feedback.
for I in Categories_To_Ignore'Range loop
declare
Category_At : constant Natural :=
Index (+To_Lower (L),
To_Lower (
To_String (Categories_To_Ignore (I))));
begin
if Category_At /= 0 then
return True;
end if;
end;
end loop;
Since I is not directly needed, you can use for Each_Category of Categories_To_Ignore loop
Follow a consistent style; in other places, your commas or ampersands are at the end of the broken line, not at the beginning.
function Strip_Character (S : String; C : String) return String is
Comma_At : constant Natural := Ada.Strings.Fixed.Index (S, C);
begin
if Comma_At = 0 then
return S;
else
return Strip_Character (S (S'First .. Comma_At - 1)
& S (Comma_At + 1 .. S'Last), C);
end if;
end Strip_Character;
If C is a single Character, use that type to indicate it. If you want it to be general for any string, use another name as Word, Pattern or Substring. Being recursive is probably not very performant. Instead, make a copy of the string, start to loop over the original and keep an index on the copy; when you skip a character, do not increment the index of the copy. Finally, return the slice using the copy and its index as last element. There are probably procedures in the standard library, that also do that. Also, respect the abstraction of the procedure, so do not use names as Comma_At, only because that is the specific current use of the procedure.
That’s really strange. I just copied & pasted it from Rosetta Code into a different folder. I ran it with gnat and it worked just fine. This is on Fedora Linux 40.
You’re talking about this line, right?
if Proper_Divisors (Value)'Reduce ("+", 0) > Value then
If so, what happens if you change the Element_Type of IntVecs to Natural? This would be on line 12.
Here’s the output of the compile after the change from Positive to Natural in line #12:
alr build
ⓘ Building weird_numbers=0.1.0-dev/weird_numbers.gpr…
Compile
[Ada] weird_numbers.adb
weird_numbers.adb:14:04: warning: use clause for private type “IntVec” defined at line 13 has no effect [-gnatwu]
weird_numbers.adb:26:07: warning: variable “Cofactors” is not referenced [-gnatwu]
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:57:80: (style) this line is too long [-gnatyM]
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]
Bind
[gprbind] weird_numbers.bexch
[Ada] weird_numbers.ali
Link
[link] weird_numbers.adb
✓ Build finished successfully in 7.04 seconds.
Wow, this is more than I expected Thanks a lot @mgrojo
To be honest, I added it because of this style message:
rank_languages_by_popularity.adb:30:4: (style) missing "overriding" indicator in body of "="
Is it an overzealous style check?
Is there a standard recommendation for placing these elements? I always struggle to find a good way to do this.
Yes, this bit is a bit dirty and I’d thought about the performance of using recursion, but, well… I’ll rewrite along with your other suggestions. Thanks again!