Rosetta Code task/Find unimplemented tasks

Hi All;

Looks like Rosetta Code web site is up now.

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.

Thanks,
Retired_Build_Engineer

Hi Ret,

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.

Best regards,
Alexis.

Is this for the challenge of the task, or just for getting the information? In the latter case, you can simply consult the Category:Ada.

I just want to get the info programmatically; it’s too error-prone and a hassle to do it manually.

Added Record sound - Rosetta Code

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? :slight_smile:

Sure, more specifically the GNATCOM part of it.

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…

According to Rosetta Code/Rank languages by popularity/Full list - Rosetta Code, just with 12 new tasks in Ada we can overtake Delphi, Scala and Rust :slight_smile:

3 Likes

11 10 9, now that I’ve finally added Ulam Numbers. I’ll try to do another one tonight. and Upside-down numbers. and Walsh matrix.

That said, I don’t think it’s a good measure of popularity.

I know, and they know, according to the page, but it’s just for the challenge and for animating others to participate.

I will add later the FTP task. It served to find a memory management bug in my binding.

Hah! Definitely will try to get some uninplemented ones done asap! I’m currently working on fixing the Ada version of that same list :slight_smile: It’s quite broken, but should be done soon.

1 Like

I’ve just updated Rosetta Code/Rank languages by popularity - Rosetta Code
According to the list it generates, Ada has already passed Rust and Delphi :smiley:

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.

1. 1683 - Phix
2. 1676 - Wren
3. 1653 - Julia
4. 1623 - Raku
5. 1577 - Nim
6. 1553 - Go
7. 1548 - Perl
8. 1532 - Python
9. 1416 - J
10. 1349 - Java
11. 1333 - FreeBASIC
12. 1300 - C
13. 1282 - C++
14. 1239 - Ruby
15. 1209 - Mathematica
16. 1175 - Haskell
17. 1156 - REXX
18. 1152 - Kotlin
19. 1149 - Jq
20. 1102 - Racket
21. 1055 - Sidef
22. 1021 - ALGOL 68
23. 1017 - 11l
24. 1012 - Zkl
25. 1004 - Factor
26. 993 - D
27. 989 - C sharp
28. 987 - Tcl
29. 973 - Scala
30. 959 - Ada
31. 954 - Rust
32. 949 - Delphi
33. 947 - Lua
34. 868 - F Sharp
35. 867 - XPL0

Hmmm, I think it’s not producing tasks, but categories… so it wouldn’t be true. Anyway, on to the next one…

1 Like

It seems very good. Some comments that could be done:

   type A_Language_Count is
      record
         Count    : Integer := 0;

Why not Natural?

   overriding
   function "=" (L, R : A_Language_Count) return Boolean is

Being a non-tagged record, what is the intention of overriding here? I thought it would be rejected by the compiler, so maybe I learn something new…

                 and then Less_Case_Insensitive
                   (Left  => To_String (L.Language),
                    Right => To_String (R.Language)));

You can use Ada.Strings.Unbounded.Less_Case_Insensitive to avoid the conversion.

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


   Http_Source : constant AWS.Response.Data :=
                   AWS.Client.Get ("http://rosettacode.org/w/index.php?" &
                                   "title=Special:Categories&limit=5000"
                                   , Follow_Redirection => True);

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.

Already confirmed by Rosetta Code/Rank languages by popularity/Full list - Rosetta Code 957 tasks in Ada, so far.

Next stop, Tcl. With 26 tasks of difference, it will require more work this time.

4 Likes

Hi;

I tried the first version of Weird Numbers using ALR on my Mac.

I got an exception:

./ALR/weird_numbers/bin/weird_numbers terminated by unhandled exception
raised CONSTRAINT_ERROR : weird_numbers.adb:47 range check failed
Load address: 0x100fdc000
Call stack traceback locations:
0x100ff8a9c 0x100ff8e74 0x100ff8a4c 0x100ff9010 0x100ff1210 0x100ff6598 0x1010189f0

Seemed to compile fine…

Retired_Build_Engineer

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.

sed -n 12,13p src/weird_numbers.adb
(Index_Type => Natural, Element_Type => Positive);
subtype IntVec is IntVecs.Vector;

Wow, this is more than I expected :slight_smile: 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!

Bring it on!

Best regards,
Alexis.

Ok, @mgrojo, I’ve uploaded the changes to Rosetta.

Much better now, I hope.