Rosetta Code/Rank languages by popularity: Difference between revisions

m (→‎{{header|REXX}}: changed the spelling of some translations in the REXX section header.)
(472 intermediate revisions by 23 users not shown)
Line 1:
{{task|Text processing}}[[Category:Networking and Web Interaction]][[Category:Sorting]][[Category:Rosetta Code related]]
[[Category:Sorting]]
Sort most popular programming languages based in number of members in Rosetta Code categories.
[[Category:Rosetta Code related]]
 
{{task|Text processing}}
Sample output on 3 December 2017:
 
;Task:
<pre>
Sort the most popular computer programming languages based in number of members in Rosetta Code categories.
rank: 1 (961 entries) Racket
 
rank: 2 (958 entries) Python
Sample output on 02 August 2022 at 09:50 +02
rank: 3 (925 entries) Perl 6
rank<pre>Rank: 41 (9181,565 entries) TclPhix
rankRank: 52 (8831,558 entries) JWren
rankRank: 63 (8741,531 entries) CJulia
rankRank: 74 (8681,507 entries) KotlinRaku
rankRank: 85 (8571,500 entries) ZklGo
rankRank: 96 (8451,466 entries) RubyPerl
rankRank: 10 7 (8281,409 entries) GoPython
Rank: 8 (1,402 entries) Nim
Rank: 9 (1,254 entries) J
Rank: 10 (1,211 entries) C
...</pre>
 
 
'''Notes'''
;Notes:
*Each language typically demonstrates 1 or 2 methods of accessing the data: with web scraping (via http://www.rosettacode.org/mw/index.php?title=Special:Categories&limit=5000), and/or with the API method (examples below for [[Rosetta Code/Rank languages by popularity#AWK|Awk]], [[Rosetta Code/Rank languages by popularity#Perl|Perl]], [[Rosetta Code/Rank languages by popularity#Ruby|Ruby]], [[Rosetta Code/Rank languages by popularity#Tcl|Tcl]], etc). The scraping and API solutions can be separate subsections, see the [[Rosetta Code/Rank languages by popularity#Tcl|Tcl example]].
* &nbsp; Each language typically demonstrates one or two methods of accessing the data:
*Filtering wrong results is optional. You can check against [[Special:MostLinkedCategories]] (if using web scraping)
:::* &nbsp; with web scraping &nbsp; (via http://www.rosettacode.org/mw/index.php?title=Special:Categories&limit=5000)
*A complete ranked listing of all &nbsp; '''651''' &nbsp; languages (from the REXX example) is included here &nbsp; ──► &nbsp; [[RC_POP.OUT]]. <br><br>
:::* &nbsp; with the API method &nbsp; (examples below for [[Rosetta Code/Rank languages by popularity#AWK|Awk]], [[Rosetta Code/Rank languages by popularity#Perl|Perl]], [[Rosetta Code/Rank languages by popularity#Ruby|Ruby]], [[Rosetta Code/Rank languages by popularity#Tcl|Tcl]], etc).
* &nbsp; The scraping and API solutions can be separate subsections, see the [[Rosetta Code/Rank languages by popularity#Tcl|Tcl example]].
* &nbsp; Filtering wrong results is optional. &nbsp; You can check against [[Special:MostLinkedCategories]] (if using web scraping)
::If you use the API, and do elect to filter, you may check your results against [[Rosetta_Code/Rank_languages_by_popularity/Full_list|this complete, accurate, sortable, wikitable listing]] of all '''{{PAGESINCAT:Programming Languages}}''' [[:Category:Programming Languages|programming languages]], updated periodically, ''typically weekly''.
* &nbsp; A complete ranked listing of all &nbsp; '''813''' &nbsp; languages (from the REXX example) is included here &nbsp; ──► &nbsp; [[RC_POP.OUT|output from the REXX program]].
<br><br>
 
=={{header|Ada}}==
{{libheader|AWS}}
<langsyntaxhighlight lang="ada">with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
Line 113 ⟶ 123:
Counts.Reverse_Iterate (Display'Access);
end Test;
</syntaxhighlight>
</lang>
 
=={{header|ALGOL 68}}==
Line 125 ⟶ 135:
{{incorrect|ALGOL 68| <br> ---among others, Tcl (the top dog) is missing. <br>}}
 
<langsyntaxhighlight lang="algol68">PROC good page = (REF STRING page) BOOL:
IF grep in string("^HTTP/[0-9.]* 200", page, NIL, NIL) = 0
THEN TRUE
Line 248 ⟶ 258:
printf(($g(-0)". "g(-0)" - "gl$,i,stats[i]))
OD
FI</langsyntaxhighlight>
{{out|Sample output}}
<pre>
Line 264 ⟶ 274:
 
===ALGOL 68:using the API===
<langsyntaxhighlight lang="algol68">
CHAR line feed = REPR 10, carriage return = REPR 13;
STRING crlf = carriage return + line feed;
Line 421 ⟶ 431:
lasttied := tied
FI
OD</langsyntaxhighlight>
{{out|Sample output top 10}}
<pre>
Line 441 ⟶ 451:
 
=={{header|AutoHotkey}}==
<langsyntaxhighlight lang="autohotkey">MembsUrl = http://rosettacode.org/mw/index.php?title=Special:Categories&limit=5000
ValidUrl = http://rosettacode.org/wiki/Category:Programming_Languages
WebRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
Line 526 ⟶ 536:
GuiClose:
ExitApp
return</langsyntaxhighlight>
 
=={{header|AWK}}==
Line 533 ⟶ 543:
This is the third solution. The [http://rosettacode.org/mw/index.php?title=Rosetta_Code/Rank_languages_by_popularity&oldid=102962#AWK first solution] used web scraping with an external program '''ns''' for networking. The [http://rosettacode.org/mw/index.php?title=Rosetta_Code/Rank_languages_by_popularity&oldid=204081 second solution] used the Rosetta Code API instead of web scraping, but continued use of '''ns''' which for unknown reasons didn't work correctly. This solution uses native gawk networking to connect to the API at 500 items per request ("gmcontinue").
 
<langsyntaxhighlight lang="awk">function join(array, start, end, sep, result, i) {
result = array[start]
for (i = start + 1; i <= end; i++)
Line 616 ⟶ 626:
print ++i ". " language " - " G[language]
 
}</langsyntaxhighlight>
{{out|Output from 26 May 2015}}
<pre>1. Tcl - 867
Line 636 ⟶ 646:
{{works with|BBC BASIC for Windows}}
Note that language names differing only in their case are merged.
<langsyntaxhighlight lang="bbcbasic"> INSTALL @lib$+"SORTLIB"
SortUp% = FN_sortinit(0,0) : REM Ascending
SortDown% = FN_sortinit(1,0) : REM Descending
Line 725 ⟶ 735:
UNTIL H%=0
SYS "CompareString", 0, NORM_IGNORECASE, S$, -1, a$(B%), -1 TO C%
IF C% = 2 THEN = B% ELSE = -1</langsyntaxhighlight>
'''Output:'''
<pre>
Line 765 ⟶ 775:
 
=={{header|Bracmat}}==
<langsyntaxhighlight lang="bracmat"> ( get-page
= url type
. !arg:(?url.?type)
Line 855 ⟶ 865:
)
)
& ;</langsyntaxhighlight>
Output:
<pre> 1. 816 - Tcl
Line 906 ⟶ 916:
{{improve|C|This solution uses an external program '''wget''' for networking, but it could use '''Library: libcurl''' (see [[Web scraping#C]]) for example. Also this solution scrapes Special:Categories &limit 5000 which will break if the HTML style changes or the number of languages exceeds 5000. It could use the MediWiki API to get the language names and pages in a single call, in blocks of 500 until complete with no upper limit. See the Awk example. If you make an API-based version please retain the web-scrapping version in its own sub-section (following the lead of [[Rosetta_Code/Rank_languages_by_popularity#Tcl|TCL on this page]]). }}
 
Ghetto parser<langsyntaxhighlight lang="c">#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Line 982 ⟶ 992:
 
return 0;
}</langsyntaxhighlight>
{{out}}
<pre> 563 Tcl
Line 1,002 ⟶ 1,012:
Usage: rank [number]<br>
Outputs the first [number] languages in the list, default to 10. Use -1 to display all the languages.
<syntaxhighlight lang="c">
<lang c>
#include <stdio.h>
#include <stdlib.h>
Line 1,150 ⟶ 1,160:
} while (sorted!=1);
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,166 ⟶ 1,176:
 
=={{header|C sharp|C#}}==
Sorting only programming languages.<br>
Note that this does not distinguish between tasks and non-task categories, so the counts can exceed the total number of tasks.<br>
<lang csharp>using System;
Note this may need to set the Security Protocol type to Tls12 - see the section Problem running the C# entry in [[Talk:Rosetta_Code/Count_examples]]
<syntaxhighlight lang="csharp">
using System;
using System.Collections;
using System.Collections.Generic;
Line 1,178 ⟶ 1,191:
static void Main(string[] args)
{
string get1get2 = new WebClient().DownloadString("http://www.rosettacode.org/w/apiindex.php?action=query&list=categorymembers&cmtitle=Category:Programming_Languages&cmlimit=500&format=json");
string get2 = new WebClient().DownloadString( +"http://www.rosettacode.org/w/index.php?title=Special:Categories&limit=5000");
);
 
ArrayList langs = new ArrayList();
Dictionary<string, int> qtdmbr = new Dictionary<string, int>();
 
string cmcontinue = "";
MatchCollection match1 = new Regex("\"title\":\"Category:(.+?)\"").Matches(get1);
MatchCollection match2 = new Regex("title=\"Category:(.+?)\">.+?</a>[^(]*\\((\\d+) members\\)").Matches(get2);
 
do
foreach (Match lang in match1) langs.Add(lang.Groups[1].Value);
{
string get1 = new WebClient().DownloadString("http://www.rosettacode.org/w/api.php?"
+"action=query&list=categorymembers"
+"&cmtitle=Category:Programming_Languages"
+"&cmlimit=500&format=json"
+cmcontinue
);
cmcontinue = "";
MatchCollection languageMatch = new Regex("\"title\":\"Category:(.+?)\"").Matches(get1);
MatchCollection cmcontinueMatch = new Regex("cmcontinue\":\"([a-z0-9A-Z|]*)\"").Matches(get1);
foreach (Match lang in languageMatch) langs.Add(lang.Groups[1].Value);
foreach (Match more in cmcontinueMatch) cmcontinue = "&cmcontinue=" + more.Groups[1].Value;
}
while( cmcontinue != "" );
 
MatchCollection match2 =
new Regex("title=\"Category:(.+?)\">.+?</a>[^(]*\\(([\\d,.]+) members\\)").Matches(get2);
 
foreach (Match match in match2)
Line 1,193 ⟶ 1,223:
if (langs.Contains(match.Groups[1].Value))
{
qtdmbr.Add(match.Groups[1].Value, Int32.Parse(match.Groups[2].Value));
.Replace(",",string.Empty)
.Replace(".",string.Empty)));
}
}
 
string[] test =
string[] test = qtdmbr.OrderByDescending(x => x.Value).Select(x => String.Format("{0,3} - {1}", x.Value, x.Key)).ToArray();
qtdmbr.OrderByDescending(x => x.Value).Select(x => String.Format("{0,4} {1}", x.Value, x.Key)).ToArray();
 
int count = 1;
Line 1,203 ⟶ 1,236:
foreach (string i in test)
{
Console.WriteLine("{0,34}.: {1}", count, i);
count++;
}
}
}
}</lang>
</syntaxhighlight>
{{out|Output (as of May 30, 2010)}}
{{out|Output (as of September 11, 2023)}}
1. 397 - Tcl
<pre>
2. 368 - Python
3. 3501: -1660 RubyPhix
4. 3332: -1653 JWren
5. 3323: -1617 CJulia
6. 3224: -1598 HaskellRaku
7. 3225: -1577 OCamlNim
8. 3026: -1548 PerlGo
7: 1537 Perl
9. 290 - Common Lisp
8: 1487 Python
10. 289 - AutoHotkey
9: 1376 J
10: 1287 C
. . .
</pre>
 
===Object-oriented solution===
<langsyntaxhighlight lang="csharp">using System;
using System.Net;
using System.Linq;
Line 1,275 ⟶ 1,312:
}
}
}</langsyntaxhighlight>
 
=={{header|C++}}==
{{libheader|Boost}}
using g++ under Linux with <tt>g++ -lboost_thread -lboost_system -lboost_regex</tt>:
<langsyntaxhighlight lang="cpp">#include <string>
#include <boost/regex.hpp>
#include <boost/asio.hpp>
Line 1,357 ⟶ 1,394:
}
return 0 ;
}</langsyntaxhighlight>
{{out|Sample output (just the "top ten")}}
1. 367 - Tcl
Line 1,372 ⟶ 1,409:
=={{header|Caché ObjectScript}}==
 
<langsyntaxhighlight lang="cos">Class Utils.Net.RosettaCode [ Abstract ]
{
 
Line 1,451 ⟶ 1,488:
}
 
}</langsyntaxhighlight>
{{out|Example}}
<pre>
Line 1,470 ⟶ 1,507:
=={{header|D}}==
With dmd you need compile like "<tt>dmd rosetta_popularity.d -L-lphobos2 -L-lcurl</tt>".
<langsyntaxhighlight lang="d">void main() {
import std.stdio, std.algorithm, std.conv, std.array, std.regex,
std.typecons, std.net.curl;
Line 1,489 ⟶ 1,526:
foreach (i, res; pairs.array.sort!q{a > b}.release)
writefln("%3d. %3d - %s", i + 1, res[]);
}</langsyntaxhighlight>
{{out|Sample output (top twenty as of 2013-01-24)}}
<pre> 1. 717 - Tcl
Line 1,511 ⟶ 1,548:
19. 462 - Unicon
20. 430 - AutoHotkey</pre>
=={{header|Delphi}}==
{{libheader| System.SysUtils}}
{{libheader| System.Classes}}
{{libheader| IdHttp}}
{{libheader| IdBaseComponent}}
{{libheader| IdComponent}}
{{libheader| IdIOHandler}}
{{libheader| IdIOHandlerSocket}}
{{libheader| IdIOHandlerStack}}
{{libheader| IdSSL}}
{{libheader| IdSSLOpenSSL}}
{{libheader| System.RegularExpressions}}
{{libheader| System.Generics.Collections}}
{{libheader| System.Generics.Defaults}}
For safe run, download dlls: libeay32.dll & ssleay32.dll, then put in executable path.
<syntaxhighlight lang="delphi">
program Rank_languages_by_popularity;
 
{$APPTYPE CONSOLE}
 
{$R *.res}
 
uses
System.SysUtils,
System.Classes,
IdHttp,
IdBaseComponent,
IdComponent,
IdIOHandler,
IdIOHandlerSocket,
IdIOHandlerStack,
IdSSL,
IdSSLOpenSSL,
System.RegularExpressions,
System.Generics.Collections,
System.Generics.Defaults;
 
const
AURL = 'https://www.rosettacode.org/mw/index.php?title=Special:Categories&limit=5000';
UserAgent =
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36';
 
type
TPair = record
Language: string;
Users: Integer;
constructor Create(lang, user: string);
end;
 
TPairs = TList<TPair>;
 
 
{ TPair }
 
constructor TPair.Create(lang, user: string);
begin
Language := lang;
Users := StrToIntDef(user, 0);
end;
 
function GetFullCode: string;
begin
with TIdHttp.create(nil) do
begin
HandleRedirects := True;
Request.UserAgent := UserAgent;
IOHandler := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
Result := Get(AURL);
IOHandler.Free;
Free;
end;
end;
 
function GetList(const Code: string): TPairs;
var
RegularExpression: TRegEx;
Match: TMatch;
language, users: string;
begin
Result := TPairs.Create;
 
RegularExpression.Create('>(?<LANG>[^<,;]*)<\/a>.. \((?<USERS>[,\d]*)');
Match := RegularExpression.Match(Code);
 
while Match.Success do
begin
users := Match.Groups.Item['USERS'].Value.Replace(',', '');
language := Match.Groups.Item['LANG'].Value;
 
Result.Add(TPair.Create(language, users));
Match := Match.NextMatch;
end;
end;
 
procedure Sort(List: TPairs);
begin
List.Sort(TComparer<TPair>.Construct(
function(const Left, Right: TPair): Integer
begin
result := Right.Users - Left.Users;
if result = 0 then
result := CompareText(Left.Language, Right.Language);
end));
end;
 
function SumUsers(List: TPairs): Cardinal;
var
p: TPair;
begin
Result := 0;
for p in List do
begin
Inc(Result, p.Users);
end;
end;
 
var
Data: TStringList;
Code, line: string;
List: TPairs;
i: Integer;
 
begin
Data := TStringList.Create;
Writeln('Downloading code...');
 
Code := GetFullCode;
data.Clear;
 
List := GetList(Code);
 
Sort(List);
 
Writeln('Total languages: ', List.Count);
Writeln('Total Users: ', SumUsers(List));
Writeln('Top 10:'#10);
 
for i := 0 to List.Count - 1 do
begin
line := Format('%5dth %5d %s', [i + 1, List[i].users, List[i].language]);
Data.Add(line);
if i < 10 then
Writeln(line);
end;
 
Data.SaveToFile('Rank.txt');
List.Free;
Data.Free;
 
Readln;
end.
 
</syntaxhighlight>
 
{{out|Output (as of Jul 27, 2020)}}
<pre>
Downloading code...
Total languages: 3267
Total Users: 96532
Top 10:
 
1th 1261 Go
2th 1228 Phix
3th 1221 Julia
4th 1210 Raku
5th 1148 Python
6th 1139 Perl
7th 1090 Kotlin
8th 1053 C
9th 1052 Java
10th 1051 Racket
</pre>
 
=={{header|Erlang}}==
<syntaxhighlight lang="erlang">
<lang Erlang>
-module( rank_languages_by_popularity ).
 
Line 1,574 ⟶ 1,783:
place_count_category_write( Count, #print_fold{place=Place, place_step=Place_step} ) ->
#print_fold{place=Place + Place_step, previous_count=Count}.
</syntaxhighlight>
</lang>
{{out|Sample output (top/last ten as of 2013-05-27)}}
<pre>
Line 1,601 ⟶ 1,810:
 
=={{header|F_Sharp|F#}}==
<langsyntaxhighlight lang="fsharp">open System
open System.Text.RegularExpressions
Line 1,653 ⟶ 1,862:
(seq { 1 .. 20 })
(entriesWithCount |> Seq.map (fun x -> sprintf "%3d - %s" (snd x) (fst x)))
0</langsyntaxhighlight>
Showing top 20 as of 2013-04-02
<pre>
Line 1,678 ⟶ 1,887:
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import (
Line 1,792 ⟶ 2,001:
fmt.Printf("%3d. %3d - %s\n", lastIdx, lang.int, lang.string)
}
}</langsyntaxhighlight>
{{out|Output on 11 Aug 2014}}
<pre>
Line 1,810 ⟶ 2,019:
 
=={{header|Groovy}}==
<langsyntaxhighlight lang="groovy">def html = new URL('http://rosettacode.org/mw/index.php?title=Special:Categories&limit=5000').getText([
connectTimeout:500,
readTimeout:15000,
Line 1,818 ⟶ 2,027:
count[language] = (members as int)
}
count.sort { v1, v2 -> v2.value <=> v1.value }.eachWithIndex { value, index -> println "${index + 1} $value" }</langsyntaxhighlight>
Output:
<pre>1 Tcl=766
Line 1,833 ⟶ 2,042:
===Haskell: Using the API===
 
<langsyntaxhighlight lang="haskell">{-# LANGUAGE OverloadedStrings #-}
 
import Data.Aeson
Line 1,934 ⟶ 2,143:
 
main :: IO ()
main = runQuery [] queryStr</langsyntaxhighlight>
{{out}}
(As of 2015-07-29.) Here we show only the top 30.
Line 1,972 ⟶ 2,181:
 
Scraping the languages and categories pages.
<langsyntaxhighlight lang="haskell">import Network.Browser
import Network.HTTP
import Network.URI
Line 2,006 ⟶ 2,215:
mapM_ printFmt $ zip [1..] $ sortBy (flip (comparing snd))
$ mapMaybe (toMaybe. (id &&& flip lookup catNmbs)) langs</langsyntaxhighlight>
{{out|First 20}}
<pre>*Main> mostPopLang
Line 2,031 ⟶ 2,240:
 
=={{header|HicEst}}==
<langsyntaxhighlight lang="hicest">CHARACTER cats*50000, catlist*50000, sortedCat*50000, sample*100
DIMENSION RankNr(1)
 
Line 2,063 ⟶ 2,272:
ENDDO
DLG(Text=sortedCat, Format=$CRLF)
END</langsyntaxhighlight>
<langsyntaxhighlight lang="hicest">2010-04-24 18:31
Top 10 entries (not all are languages)
1. 394 Tcl
Line 2,075 ⟶ 2,284:
8. 298 Perl
9. 288 WikiStubs
10. 281 Common Lisp</langsyntaxhighlight>
 
=={{header|Icon}} and {{header|Unicon}}==
Line 2,081 ⟶ 2,290:
The following solution only works in Unicon.
 
<langsyntaxhighlight lang="unicon">$define RCLANGS "http://rosettacode.org/mw/api.php?format=xml&action=query&generator=categorymembers&gcmtitle=Category:Programming%20Languages&gcmlimit=500&prop=categoryinfo"
$define RCUA "User-Agent: Unicon Rosetta 0.1"
$define RCXUA "X-Unicon: http://unicon.org/"
Line 2,129 ⟶ 2,338:
close(page)
return text
end</langsyntaxhighlight>
 
Abridged output (top 26 languages as of July 30, 2016):
Line 2,163 ⟶ 2,372:
</pre>
 
== {{header|J}} ==
{{works with|J|6.02 (32 bit only)}}
'''Solution''':<langsyntaxhighlight lang="j">require 'web/gethttp xml/sax/x2j regex'
 
x2jclass 'rcPopLang'
Line 2,182 ⟶ 2,391:
formatTab =: [: ;:^:_1: [: (20 A. (<'-') , |. , [: ('.' <"1@:,.~ ":) 1 + 1 i.@,~ 1{$)&.|: sortTab f.
 
rcPopLangs =: formatTab@:process_rcPopLang_@:gethttp</langsyntaxhighlight>
'''Example''':<langsyntaxhighlight lang="j"> 10 {. rcPopLangs 'http://www.rosettacode.org/w/index.php?title=Special:Categories&limit=2000'
1. 687 - Tcl
2. 646 - Python
Line 2,193 ⟶ 2,402:
8. 550 - D
9. 549 - Mathematica
10. 526 - Perl</langsyntaxhighlight>
'''Notes''': See some [[Talk:Sort most popular programming languages#J|notes on the J solution]].
 
== {{header|Java}} ==
Tested with Java 1.7. Uses the api.
<langsyntaxhighlight lang="java">import java.net.URL;
import java.net.URLConnection;
import java.io.*;
Line 2,328 ⟶ 2,537:
} // for lPos
} // main
} // GetRCLanguages</langsyntaxhighlight>
{{out}}
Top 10 languages as at 27th August 2015
Line 2,345 ⟶ 2,554:
</pre>
 
== {{header|jq}} ==
{{works with|jq|1.4}}
The following solution matches the languages listed on the Category:Programming_Languages page with the statistics given on the Special:Categories page, making an adjustment for the number of irrelevant subcategories.
 
jq 1.4 cannot retrieve documents over the web and has no support for regular expressions, but is intended to work seamlessly with other command line tools, so the following solution is presented in the form of a bash script that uses curl for retrieval, and grep and sed for screen scraping.
<langsyntaxhighlight lang="sh">#!/bin/bash
 
# produce lines of the form: [ "language", n ]
Line 2,394 ⟶ 2,603:
| reverse
| ranking[]
| "\(.[0]). \(.[1]) - \(.[2])" '</langsyntaxhighlight>
{{out}}
<langsyntaxhighlight lang="sh"># First ten and last ten lines as of May 27, 2015
$ pop.sh
1. 868 - Tcl
Line 2,418 ⟶ 2,627:
386. 1 - Algae
386. 1 - 80386 Assembly
386. 1 - 68000 Assembly</langsyntaxhighlight>
 
=={{header|Julia}}==
Uses the API for the language list and page scraping for the example counts for each language.
<syntaxhighlight lang="julia">""" Rosetta code task rosettacode.org/wiki/Rosetta_Code/Rank_languages_by_popularity """
 
using Dates
using DataFrames
using HTTP
using JSON3
 
""" Get listing of all tasks and draft tasks with authors and dates created, with the counts as popularity """
function rosetta_code_language_example_counts(verbose = false)
URL = "https://rosettacode.org/w/api.php?"
LANGPARAMS = ["action" => "query", "format" => "json", "formatversion" => "2", "generator" => "categorymembers",
"gcmtitle" => "Category:Programming_Languages", "gcmlimit" => "500", "rawcontinue" => "", "prop" => "title"]
queryparams = copy(LANGPARAMS)
df = empty!(DataFrame([[""], [0]], ["ProgrammingLanguage", "ExampleCount"]))
 
while true # get all the languages listed, with curid, eg rosettacode.org/w/index.php?curid=196 for C
resp = HTTP.get(URL * join(map(p -> p[1] * (p[2] == "" ? "" : ("=" * p[2])), queryparams), "&"))
json = JSON3.read(String(resp.body))
pages = json.query.pages
reg = r"The following \d+ pages are in this category, out of ([\d\,]+) total"
for p in pages
lang = replace(p.title, "Category:" => "")
langpage = String(HTTP.get("https://rosettacode.org/w/index.php?curid=" * string(p.pageid)).body)
if !((m = match(reg, langpage)) isa Nothing)
push!(df, [lang, parse(Int, replace(m.captures[1], "," => ""))])
verbose && println("Language: $lang, count: ", m.captures[1])
end
end
!haskey(json, "query-continue") && break # break if no more pages, else continue to next pages
queryparams = vcat(LANGPARAMS, "gcmcontinue" => json["query-continue"]["categorymembers"]["gcmcontinue"])
end
 
return sort!(df, :ExampleCount, rev = true)
end
 
println("Top 20 Programming Languages on Rosetta Code by Number of Examples, As of: ", now())
println(rosetta_code_language_example_counts()[begin:begin+19, :])
 
</syntaxhighlight>{{out}}
<pre>
Top 20 Programming Languages on Rosetta Code by Number of Examples, As of: 2022-09-05T14:59:56.316
20×2 DataFrame
Row │ ProgrammingLanguage ExampleCount
│ String Int64
─────┼───────────────────────────────────
1 │ Wren 1569
2 │ Phix 1569
3 │ Julia 1537
4 │ Raku 1517
5 │ Go 1496
6 │ Perl 1460
7 │ Python 1404
8 │ Nim 1402
9 │ J 1275
10 │ C 1210
11 │ Mathematica 1178
12 │ REXX 1149
13 │ Haskell 1139
14 │ Java 1136
15 │ Kotlin 1133
16 │ C++ 1120
17 │ Ruby 1103
18 │ Racket 1089
19 │ FreeBASIC 1069
20 │ Zkl 1011
</pre>
 
=={{header|Kotlin}}==
{{trans|Java}}
<langsyntaxhighlight lang="scala">import java.net.URL
import java.io.*
 
Line 2,502 ⟶ 2,780:
}
}
}</langsyntaxhighlight>
{{out}}
<pre> 1, 901, Racket
Line 2,514 ⟶ 2,792:
 
=={{header|Lasso}}==
<langsyntaxhighlight Lassolang="lasso"><pre><code>[
sys_listtraits !>> 'xml_tree_trait' ? include('xml_tree.lasso')
local(lang = array)
Line 2,538 ⟶ 2,816:
'. '+#l->second + ' - ' + #l->first+'\r'
^}
]</code></pre></langsyntaxhighlight>
 
{{out}}
Line 2,553 ⟶ 2,831:
...</pre>
 
=={{header|MathematicaM2000 Interpreter}}==
Based on BBC BASIC idea, and using M2000 Rinstr() and objects as Inventories, Document, and Microsoft.XMLHTTP for downloading (async use). Results also copy to Clipboard. We can use Msxml2.ServerXMLHTTP (code is the same, only name of object change).
<lang Mathematica>Languages = Flatten[Import["http://rosettacode.org/wiki/Category:Programming_Languages","Data"][[1,1]]];
 
Update: Numbers above 999 get a comma (,) so we have to drop this using Filter$()
 
<syntaxhighlight lang="m2000 interpreter">
Module RankLanguages {
Const Part1$="<a href="+""""+ "/wiki/Category", Part2$="member"
Const langHttp$="http://rosettacode.org/wiki/Category:Programming_Languages"
Const categoriesHttp$="http://www.rosettacode.org/mw/index.php?title=Special:Categories&limit=5000"
Def long m, i,j, tasks, counter, limit, T, t1
Def string LastLang$, job$
Document final$, languages$, categories$
httpGet$=lambda$ (url$, timeout=1000)->{
Declare htmldoc "Msxml2.ServerXMLHTTP"
With htmldoc , "readyState" as ready
Report "Download:"+url$
Method htmldoc "open","get", url$, True
Method htmldoc "send"
Profiler
While Ready<>4 {
Wait 20
Print Over format$("Wait: {0:3} sec", timecount/1000)
If timecount>timeout then Exit
}
If ready=4 Then With htmldoc, "responseText" as ready$ : =ready$
Declare htmldoc Nothing
print
}
languages$=httpGet$(langHttp$, 30000)
If Doc.Len(languages$)=0 then Error "File download failed (languages)"
Inventory Lang
m=Paragraph(languages$, 0)
If Forward(languages$,m) then {
While m {
job$=Paragraph$(languages$,(m))
If Instr(job$, part1$) Else Continue
i = Instr(job$, "</a>")
If i Else Continue ' same as If i=0 Then Continue
j = i
i=Rinstr(job$, ">", -i)
If i Else Continue
LastLang$=MID$(job$, i+1, j-i-1)
if Instr(job$, "Category:"+lastlang$) then Append lang, lastlang$:=0 : Print Over format$("Languages: {0}", len(lang))
}
}
Print
Document categories$=httpGet$(categoriesHttp$, 30000)
If Doc.Len(categories$)=0 then Error "File download failed (categories)"
limit=Doc.Par(categories$)
If limit<Len(Lang) then Error "Invalid data"
Refresh
set slow
m=Paragraph(categories$, 0)
counter=0
If Forward(categories$,m) then {
While m {
job$=Paragraph$(categories$,(m))
counter++
Print Over format$("{0:2:-6}%", counter/limit*100)
i=Instr(job$, part2$)
If i Else Continue
i=Rinstr(job$, "(", -i)
If i Else Continue
tasks=Val(Filter$(Mid$(job$, i+1),","))
If tasks Else Continue
i=Rinstr(job$, "<", -i)
If i Else Continue
j = i
i=Rinstr(job$, ">", -i)
If i Else Continue
LastLang$=MID$(job$, i+1, j-i-1)
If Exist(Lang, LastLang$) Then {
Return Lang, LastLang$:=Lang(LastLang$)+tasks
}
}
}
Print
\\ this type of inventory can get same keys
\\ also has stable sort
Report "Make Inventory list by Task"
Inventory queue ByTask
t1=Len(Lang)
T=Each(Lang)
While T {
Append ByTask, Eval(T):=Eval$(T!)
Print Over format$("Complete: {0} of {1}", T^+1, t1 )
}
Print
Report "Sort by task (stable sort, sort keys as numbers)"
Sort descending ByTask as number
Report "Make List"
T=Each(ByTask)
final$="Sample output on "+Date$(Today, 1033, "long date")+{:
}
While T {
final$=format$("rank:{0::-4}. {1:-5} entries - {2}", T^+1, Eval$(T!), Eval$(T))+{
}
}
Report "Copy to Clipboard"
clipboard final$
\\ present to console with 3/4 fill lines then stop for space bar or mouse click to continue
Report final$
}
RankLanguages
</syntaxhighlight>
 
{{out}}
<pre style="height:30ex;overflow:scroll">
Sample output on Saturday, June 22, 2019:
rank: 1. 1149 entries - Go
rank: 2. 1084 entries - Perl 6
rank: 3. 1061 entries - Python
rank: 4. 1045 entries - Kotlin
rank: 5. 1044 entries - Julia
rank: 6. 1033 entries - Phix
rank: 7. 1026 entries - Perl
rank: 8. 991 entries - Racket
rank: 9. 951 entries - C
rank: 10. 944 entries - J
rank: 11. 938 entries - Zkl
rank: 12. 930 entries - Tcl
rank: 13. 910 entries - REXX
rank: 14. 909 entries - Java
rank: 15. 883 entries - Ruby
rank: 16. 881 entries - D
rank: 17. 869 entries - Haskell
rank: 18. 814 entries - Sidef
rank: 19. 801 entries - Scala
rank: 20. 779 entries - C sharp
rank: 21. 775 entries - PicoLisp
rank: 22. 772 entries - C++
rank: 23. 748 entries - Mathematica
rank: 24. 678 entries - Common Lisp
rank: 25. 668 entries - Ada
rank: 26. 639 entries - JavaScript
rank: 27. 633 entries - Lua
rank: 28. 628 entries - AutoHotkey
rank: 29. 611 entries - Ring
rank: 30. 595 entries - Factor
rank: 31. 594 entries - Clojure
rank: 32. 590 entries - Unicon
rank: 33. 566 entries - ALGOL 68
rank: 34. 563 entries - Nim
rank: 35. 563 entries - PureBasic
rank: 36. 560 entries - BBC BASIC
rank: 37. 559 entries - Fortran
rank: 38. 556 entries - OCaml
rank: 39. 540 entries - PARI/GP
rank: 40. 538 entries - F Sharp
rank: 41. 532 entries - Icon
rank: 42. 517 entries - Elixir
rank: 43. 497 entries - FreeBASIC
rank: 44. 495 entries - Erlang
rank: 45. 485 entries - Rust
rank: 46. 473 entries - PowerShell
rank: 47. 462 entries - Jq
rank: 48. 456 entries - Pascal
rank: 49. 453 entries - AWK
rank: 50. 450 entries - Forth
rank: 51. 448 entries - Seed7
rank: 52. 435 entries - R
rank: 53. 414 entries - Groovy
rank: 54. 403 entries - PL/I
rank: 55. 401 entries - PHP
rank: 56. 383 entries - VBA
rank: 57. 361 entries - Scheme
rank: 58. 359 entries - MATLAB
rank: 59. 353 entries - Swift
rank: 60. 346 entries - M2000 Interpreter
rank: 61. 343 entries - Maple
rank: 62. 337 entries - Liberty BASIC
rank: 63. 314 entries - Run BASIC
rank: 64. 309 entries - Prolog
 
..........
rank: 685. 1 entries - Jacquard Loom
rank: 686. 1 entries - Kamailio Script
rank: 687. 1 entries - Lambda Prolog
rank: 688. 1 entries - LibreOffice Basic
rank: 689. 1 entries - MAPPER
rank: 690. 1 entries - MEL
rank: 691. 1 entries - MiniZinc
rank: 692. 1 entries - Mond
rank: 693. 1 entries - Monkey
rank: 694. 1 entries - NASL
rank: 695. 1 entries - Neat
rank: 696. 1 entries - NewtonScript
rank: 697. 1 entries - Nickle
rank: 698. 1 entries - Nix
rank: 699. 1 entries - Opa
rank: 700. 1 entries - Pare
rank: 701. 1 entries - Qore
rank: 702. 1 entries - Rapira
rank: 703. 1 entries - RPGIV
rank: 704. 1 entries - Setl4
rank: 705. 1 entries - Soar
rank: 706. 1 entries - SoneKing Assembly
rank: 707. 1 entries - Supernova
rank: 708. 1 entries - SuperTalk
rank: 709. 1 entries - Terra
rank: 710. 1 entries - TestML
rank: 711. 1 entries - WebAssembly
rank: 712. 1 entries - Wollok
rank: 713. 1 entries - Xanadu
rank: 714. 1 entries - Ya
rank: 715. 1 entries - МiniZinc
rank: 716. 0 entries - AngelScript
rank: 717. 0 entries - Binary Lambda Calculus
rank: 718. 0 entries - EhBASIC
rank: 719. 0 entries - Epigram
rank: 720. 0 entries - FLORA-2
rank: 721. 0 entries - Florid
rank: 722. 0 entries - Gerbil
rank: 723. 0 entries - LC2200 Assembly
rank: 724. 0 entries - Leon
rank: 725. 0 entries - Livecode
rank: 726. 0 entries - LLP
rank: 727. 0 entries - Loglan82
rank: 728. 0 entries - Lolli
rank: 729. 0 entries - Lygon
rank: 730. 0 entries - ObjectIcon
rank: 731. 0 entries - PL/B
rank: 732. 0 entries - Plan
rank: 733. 0 entries - Reduce
rank: 734. 0 entries - Rubylog
rank: 735. 0 entries - S BASIC
rank: 736. 0 entries - SimpleLang
rank: 737. 0 entries - Star
rank: 738. 0 entries - X10
rank: 739. 0 entries - XS
</pre >
 
=={{header|Maple}}==
<syntaxhighlight lang="maple">count_sizes := proc(arr_name,arr_pop,i,lst)
local index := i;
local language;
for language in lst do
language := language[1]:
arr_name(index) := txt["query"]["pages"][language]["title"][10..]:
if(assigned(txt["query"]["pages"][language]["categoryinfo"]["size"])) then
arr_pop(index) := txt["query"]["pages"][language]["categoryinfo"]["size"]:
else:
arr_pop(index) := 0:
end if:
index++:
end do:
return index:
end proc:
 
txt := JSON:-ParseFile("http://rosettacode.org/mw/api.php?action=query&generator=categorymembers&gcmtitle=Category:Programming%20Languages&gcmlimit=350&prop=categoryinfo&format=json"):
arr_name := Array():
arr_pop := Array():
i := count_sizes(arr_name, arr_pop, 1, [indices(txt["query"]["pages"])]):
while (assigned(txt["continue"]["gcmcontinue"])) do
continue := txt["continue"]["gcmcontinue"]:
txt := JSON:-ParseFile(cat("http://rosettacode.org/mw/api.php?action=query&generator=categorymembers&gcmtitle=Category:Programming%20Languages&gcmlimit=350&prop=categoryinfo&format=json", "&continue=", txt["continue"]["continue"], "&gcmcontinue=", txt["continue"]["gcmcontinue"])):
i:=count_sizes(arr_name,arr_pop,i,[indices(txt["query"]["pages"])]):
end do:
arr_name:= arr_name[sort(arr_pop,output=permutation)]:
arr_pop := sort(arr_pop, output=sorted):
i := i-1:
for x from i to 1 by -1 do
printf("rank %d %d examples %s\n", i-x+1, arr_pop[x], arr_name[x]):
end do:</syntaxhighlight>
{{Out|Output}}
<pre>#10:30 AM 10/05/2018
rank 1 1002 examples Kotlin
rank 2 977 examples Racket
rank 3 977 examples Python
rank 4 949 examples Perl 6
rank 5 918 examples Tcl
rank 6 898 examples C
rank 7 891 examples J
rank 8 879 examples Zkl
rank 9 870 examples Java
rank 10 860 examples D
...
rank 680 0 examples Epigram
rank 681 0 examples LLP
rank 682 0 examples Lolli
rank 683 0 examples Leon
rank 684 0 examples Florid
rank 685 0 examples Loglan82</pre>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<syntaxhighlight lang="mathematica">Languages = Flatten[Import["http://rosettacode.org/wiki/Category:Programming_Languages","Data"][[1,1]]];
Languages = Most@StringReplace[Languages, {" " -> "_", "+" -> "%2B"}];
b = {#, If[# === {}, 0, #[[1]]]&@( StringCases[Import["http://rosettacode.org/wiki/Category:"<>#,"Plaintext"],
"category, out of " ~~ x:NumberString ~~ " total" ->x])} &/@ Languages;
For[i = 1, i < Length@b , i++ , Print[i, ". ", #[[2]], " - ", #[[1]] ]&@ Part[Reverse@SortBy[b, Last], i]]</langsyntaxhighlight>
{{out|Output : As of 29 February 2012}}
<pre>
Line 2,574 ⟶ 3,143:
 
=={{header|Nim}}==
<langsyntaxhighlight lang="nim">import std/[Algorithm, httpclient, json, re, strutilsstrformat, algorithmstrutils]
 
const
langSiteLangSite = "http://www.rosettacode.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:Programming_Languages&cmlimit=500&format=json"
catSizeCatSite = "http://www.rosettacode.org/w/index.php?title=Special:Categories&limit=5000"
let regex = re"title=""Category:(.*?)"">.+?</a>.*\((.*) members\)"
 
vartype langs:Rank seq= tuple[lang: string], =count: @[int]
 
for l in parseJson(getContent(langSite))["query"]["categorymembers"]:
proc cmp(a, b: Rank): int =
langs.add(l["title"].str.split("Category:")[1])
result = cmp(b.count, a.count)
if result == 0: result = cmp(a.lang, b.lang)
 
proc add(langs: var seq[string]; fromJson: JsonNode) =
for entry in fromJson{"query", "categorymembers"}:
let title = entry["title"].getStr()
if title.startsWith("Category:"):
langs.add title[9..^1]
 
var client = newHttpClient()
var langs: seq[string]
var url = LangSite
while true:
let response = client.get(url)
if response.status != $Http200: break
let fromJson = response.body.parseJson()
langs.add fromJson
if "continue" notin fromJson: break
let cmcont = fromJson{"continue", "cmcontinue"}.getStr
let cont = fromJson{"continue", "continue"}.getStr
url = LangSite & fmt"&cmcontinue={cmcont}&continue={cont}"
 
var ranks: seq[tuple[lang: string, count: int]] = @[Rank]
for line in client.getContent(catSizeCatSite).findAll(regex):
let lang = line.replacef(regex, "$1")
if lang in langs:
let count = parseInt(line.replacef(regex, "$2").replace(",", "").strip())
ranks.add( (lang, count))
 
ranks.sort(proc (x, y): int = cmp[int](y.count, x.count))
for i, lrank in ranks:
echo align($(&"{i + 1), :3),} align($l{rank.count, 5), ":4} - ", l{rank.lang</lang>}"
</syntaxhighlight>
Output:
<pre> 1 8331626 - TclPhix
2 7811620 - RacketWren
3 7701587 - PythonJulia
4 7301574 - Perl 6Raku
5 7251533 - JGo
6 7121520 - CPerl
7 7081466 - RubyPython
8 6981430 - DNim
9 6741348 - GoJ
10 6561264 - PerlC
11 1198 - Ruby
12 1185 - Mathematica
13 1164 - Java
14 1160 - Haskell
15 1155 - C++
16 1153 - REXX
17 1136 - Kotlin
18 1131 - FreeBASIC
19 1100 - Racket
20 1027 - Jq
21 1014 - 11l
22 1012 - Zkl
23 1004 - Sidef
24 997 - Factor
25 987 - D
26 980 - Tcl
27 938 - Ada
28 926 - C sharp
29 923 - Scala
30 906 - ALGOL 68
31 896 - Rust
32 893 - Lua
33 849 - PicoLisp
34 843 - F Sharp
35 824 - AutoHotkey
36 818 - Ring
37 793 - Delphi
38 785 - JavaScript
39 778 - Arturo
40 776 - XPL0
...</pre>
 
=={{header|Objeck}}==
<langsyntaxhighlight lang="objeck">use HTTP;
use RegEx;
use XML;
Line 2,688 ⟶ 3,309:
};
}
}</langsyntaxhighlight>
 
<pre>1. 849 - Tcl
Line 2,704 ⟶ 3,325:
=={{header|ooRexx}}==
{{trans|REXX}}
<langsyntaxhighlight lang="oorexx">/* REXX ---------------------------------------------------------------
* Create a list of Rosetta Code languages showing the number of tasks
* This program's logic is basically that of the REXX program
Line 2,717 ⟶ 3,338:
* RC_LNG.txt list of languages alphabetically sorted
* RC_TRN.txt list language name translations (debug)
* 24.11.2013 Walter Pachl
*--------------------------------------------------------------------*/
test=1
Line 2,888 ⟶ 3,508:
If \l._ Then /* not a known language */
Iterate /* ignore */
if pos(',', mems)\==0 then
mems=changestr(",", mems, '') /* remove commas. */
If\datatype(mems,'W') Then /* not a number of members */
Iterate /* ignore */
Line 2,901 ⟶ 3,523:
* These two lines
* * Lotus 123 Macro Scripting
* </wiki/Category:Lotus_123_Macro_Scripting>‏‎�‎ (3 members)
* are returned as one line:
*-> * Lotus 123 Macro Scripting </wiki/Cate ... (3 members)
Line 3,035 ⟶ 3,657:
If ta<<tb Then res=-1
Else res=1
Return res</langsyntaxhighlight>
 
Output (the beginning):
Line 3,051 ⟶ 3,673:
</pre>
Note: If MC++ and µC++ are the same, they should/could be added together to get 501 languages.
 
=={{header|PascalABC.NET}}==
Using web scraping. May 2024.
<syntaxhighlight lang="delphi">
uses System.Net;
 
begin
ServicePointManager.SecurityProtocol := SecurityProtocolType(3072);
var wc := new WebClient;
wc.Encoding := Encoding.UTF8;
var s := wc.DownloadString('https://rosettacode.org/wiki/Special:Categories?limit=5000');
s.Matches('([^><]+)</a>.+\(([\d,]+) member')
.Select(x -> KV(x.Groups[1].Value,x.Groups[2].Value.Replace(',','').ToInteger))
.Where(x -> not x.Key.StartsWith('Pages'))
.OrderByDescending(pair -> pair.Value).Numerate.Take(10)
.PrintLines(x -> $'Rank: {x[0],3} ({x[1].Value} entries) {x[1].Key}')
end.
</syntaxhighlight>
{{out}}
<pre>
Rank: 1 (1682 entries) Phix
Rank: 2 (1675 entries) Wren
Rank: 3 (1652 entries) Julia
Rank: 4 (1622 entries) Raku
Rank: 5 (1577 entries) Nim
Rank: 6 (1552 entries) Go
Rank: 7 (1548 entries) Perl
Rank: 8 (1531 entries) Python
Rank: 9 (1416 entries) J
Rank: 10 (1343 entries) Java
</pre>
 
=={{header|Oz}}==
{{libheader|OzHttpClient}}
Using web scraping. Does not filter non-language categories.
<langsyntaxhighlight lang="oz">declare
[HTTPClient] = {Module.link ['x-ozlib://mesaros/net/HTTPClient.ozf']}
[Regex] = {Module.link ['x-oz://contrib/regex']}
Line 3,094 ⟶ 3,747:
do
{System.showInfo I#". "#Count#" - "#Cat}
end</langsyntaxhighlight>
{{out}}
<pre>
Line 3,111 ⟶ 3,764:
=={{header|Perl}}==
===By using the API===
<langsyntaxhighlight lang="perl">use 5.010;
use MediaWiki::API;
 
my $api =
MediaWiki::API->new( { api_url => 'http://rosettacode.org/mww/api.php' } );
 
my @languages;
Line 3,150 ⟶ 3,803:
$_->{'categoryinfo'}{'size'};
}
</syntaxhighlight>
</lang>
{{out}}
<pre> 1. Phix - 1576
2. Wren - 1569
3. Julia - 1540
4. Raku - 1520
5. Go - 1500
6. Perl - 1468
7. Python - 1422
8. Nim - 1403
9. J - 1278
10. C - 1213
...</pre>
 
=={{header|Perl 6Phix}}==
The distributed version also has an output_html option.
 
{{libheader|Phix/libcurl}}
===Perl 6: Using the API===
<!--<syntaxhighlight lang="phix">(phixonline)-->
 
<span style="color: #000080;font-style:italic;">-- demo\rosetta\Rank_Languages.exw</span>
<lang perl6>use HTTP::UserAgent;
<span style="color: #008080;">constant</span> <span style="color: #000000;">output_users</span> <span style="color: #0000FF;">=</span> <span style="color: #004600;">false</span><span style="color: #0000FF;">,</span>
use JSON::Tiny;
<span style="color: #000000;">limit</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">20</span><span style="color: #0000FF;">,</span> <span style="color: #000080;font-style:italic;">-- 0 to list all</span>
 
<span style="color: #000000;">languages</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"http://rosettacode.org/wiki/Category:Programming_Languages"</span><span style="color: #0000FF;">,</span>
.say for
<span style="color: #000000;">categories</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"http://www.rosettacode.org/mw/index.php?title=Special:Categories&limit=5000"</span>
mediawiki-query('http://rosettacode.org/mw', 'pages',
generator => 'categorymembers',
gcmtitle => "Category:Programming Languages",
prop => 'categoryinfo')
.map({ %( name => .<title>.subst(/^'Category:'/, ''),
count => .<categoryinfo><pages> || 0 ) })
.sort({ -.<count>, .<name> })
.map({ last if .<count>==0; sprintf "%3d. %3d - %s", ++$, .<count name> });
 
sub mediawiki-query ($site, $type, *%query) {
my $url = "$site/api.php?" ~ uri-query-string(
:action<query>, :format<json>, :gcmlimit<350>, :rawcontinue(), |%query);
my $continue = '';
my $client = HTTP::UserAgent.new;
gather loop {
my $response = $client.get("$url&$continue");
my $data = from-json($response.content);
take $_ for $data.<query>.{$type}.values;
$continue = uri-query-string |($data.<query-continue>{*}».hash.hash or last);
}
}
 
sub uri-query-string (*%fields) {
%fields.map({ "{.key}={uri-encode .value}" }).join("&")
}
 
sub uri-encode ($str) {
$str.subst(/<[\x00..\xff]-[a..zA..Z0..9_.~-]>/, *.ord.fmt('%%%02X'), :g)
}</lang>
 
===Perl 6: Using web scraping===
 
Scraping the languages and categories pages. Perl 6 automatically handles Unicode names correctly.
<lang perl6>my $languages = qx{wget -O - 'http://rosettacode.org/wiki/Category:Programming_Languages'};
my $categories = qx{wget -O - 'http://www.rosettacode.org/mw/index.php?title=Special:Categories&limit=5000'};
<span style="color: #008080;">include</span> <span style="color: #000000;">rosettacode_cache</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span> <span style="color: #000080;font-style:italic;">-- see [[Rosetta_Code/Count_examples#Phix]]</span>
my @lines = $languages.lines;
shift @lines until @lines[0] ~~ / '<h2>Subcategories</h2>' /;
my \languages = set gather for @lines {
last if / '/bodycontent' /;
take ~$0 if
/ '<li><a href="/wiki/Category:' .*? '" title="Category:' .*? '">' (.*?) '</a></li>' /;
}
<span style="color: #008080;">function</span> <span style="color: #000000;">correct_name</span><span style="color: #0000FF;">(</span><span style="color: #004080;">string</span> <span style="color: #000000;">ri</span><span style="color: #0000FF;">)</span>
@lines = $categories.lines;
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`&quot;`</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`"`</span><span style="color: #0000FF;">)</span>
my @results = sort -*.[0], gather for @lines {
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`&#039;`</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`'`</span><span style="color: #0000FF;">)</span>
take [+$1, ~$0] if
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\xE2\x80\x99"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"'"</span><span style="color: #0000FF;">)</span>
/ '<li><a href="/wiki/Category:' .*? '" title="Category:' .*? '">'
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\xC3\xB6"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"o"</span><span style="color: #0000FF;">)</span>
(.*?) <?{ ~$0 ∈ languages }>
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%3A"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">":"</span><span style="color: #0000FF;">)</span>
'</a>' .*? '(' (\d+) ' member' /;
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%E2%80%93"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"-"</span><span style="color: #0000FF;">)</span>
}
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%E2%80%99"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"'"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%27"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"'"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%2B"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"+"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%C3%A8"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"e"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%C3%A9"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"e"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%C3%B6"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"o"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%C5%91"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"o"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%22"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`"`</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%2A"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"*"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\xC2\xB5"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"u"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\xC3\xA0"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"a"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\xC3\xA6"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"a"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\xC3\xA9"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"e"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\xC3\xB4"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"o"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\xC5\x8D"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"o"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\xCE\x9C"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"u"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\xD0\x9C\xD0\x9A"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"MK"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\xE0\xAE\x89\xE0\xAE\xAF\xE0\xAE\xBF\xE0\xAE\xB0\xE0\xAF\x8D/"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">""</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"APEX"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Apex"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"uC++ "</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"UC++"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`CASIO BASIC`</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`Casio BASIC`</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`Visual BASIC`</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`Visual Basic`</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`INTERCAL`</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`Intercal`</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`SETL4`</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`Setl4`</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`QBASIC`</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`QBasic`</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`RED`</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`Red`</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`OCTAVE`</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`Octave`</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`OoREXX`</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`OoRexx`</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">return</span> <span style="color: #000000;">ri</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #008080;">include</span> <span style="color: #000000;">builtins</span><span style="color: #0000FF;">/</span><span style="color: #000000;">sets</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">cat_title</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">`title="Category:`</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">extract_names</span><span style="color: #0000FF;">()</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">results</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{}</span> <span style="color: #000080;font-style:italic;">-- {rank,count,name}</span>
<span style="color: #008080;">if</span> <span style="color: #7060A8;">get_file_type</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"rc_cache"</span><span style="color: #0000FF;">)!=</span><span style="color: #004600;">FILETYPE_DIRECTORY</span> <span style="color: #008080;">then</span>
<span style="color: #008080;">if</span> <span style="color: #008080;">not</span> <span style="color: #000000;">create_directory</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"rc_cache"</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">then</span>
<span style="color: #7060A8;">crash</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"cannot create rc_cache directory"</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #000080;font-style:italic;">-- 1) extract languages from eg title="Category:Phix"</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">language_names</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{}</span>
<span style="color: #004080;">string</span> <span style="color: #000000;">langs</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">open_download</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"languages.htm"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">languages</span><span style="color: #0000FF;">),</span>
<span style="color: #000000;">language_name</span>
<span style="color: #000000;">langs</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">langs</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">..</span><span style="color: #7060A8;">match</span><span style="color: #0000FF;">(</span><span style="color: #008000;">`&lt;div class="printfooter"&gt;`</span><span style="color: #0000FF;">,</span><span style="color: #000000;">langs</span><span style="color: #0000FF;">)-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">start</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">match</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"&lt;h2&gt;Subcategories&lt;/h2&gt;"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">langs</span><span style="color: #0000FF;">),</span> <span style="color: #000000;">k</span>
<span style="color: #008080;">while</span> <span style="color: #004600;">true</span> <span style="color: #008080;">do</span>
<span style="color: #000000;">k</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">match</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cat_title</span><span style="color: #0000FF;">,</span><span style="color: #000000;">langs</span><span style="color: #0000FF;">,</span><span style="color: #000000;">start</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">k</span><span style="color: #0000FF;">=</span><span style="color: #000000;">0</span> <span style="color: #008080;">then</span> <span style="color: #008080;">exit</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #000000;">k</span> <span style="color: #0000FF;">+=</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cat_title</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">start</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">find</span><span style="color: #0000FF;">(</span><span style="color: #008000;">'"'</span><span style="color: #0000FF;">,</span><span style="color: #000000;">langs</span><span style="color: #0000FF;">,</span><span style="color: #000000;">k</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">language_name</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">correct_name</span><span style="color: #0000FF;">(</span><span style="color: #000000;">langs</span><span style="color: #0000FF;">[</span><span style="color: #000000;">k</span><span style="color: #0000FF;">..</span><span style="color: #000000;">start</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">])</span>
<span style="color: #000000;">language_names</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">append</span><span style="color: #0000FF;">(</span><span style="color: #000000;">language_names</span><span style="color: #0000FF;">,</span><span style="color: #000000;">language_name</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<span style="color: #000080;font-style:italic;">-- 2) extract results from eg title="Category:Phix"&gt;Phix&lt;/a&gt;?? (997 members)&lt;/li&gt;
-- but obviously only when we have found that language in the phase above.
-- (note there is / ignore some wierd uncode-like stuff after the &lt;/a&gt;...)</span>
<span style="color: #004080;">string</span> <span style="color: #000000;">cats</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">open_download</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"categories.htm"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">categories</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">start</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">1</span>
<span style="color: #008080;">while</span> <span style="color: #004600;">true</span> <span style="color: #008080;">do</span>
<span style="color: #000000;">k</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">match</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cat_title</span><span style="color: #0000FF;">,</span><span style="color: #000000;">cats</span><span style="color: #0000FF;">,</span><span style="color: #000000;">start</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">k</span><span style="color: #0000FF;">=</span><span style="color: #000000;">0</span> <span style="color: #008080;">then</span> <span style="color: #008080;">exit</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #000000;">k</span> <span style="color: #0000FF;">+=</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cat_title</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">start</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">find</span><span style="color: #0000FF;">(</span><span style="color: #008000;">'"'</span><span style="color: #0000FF;">,</span><span style="color: #000000;">cats</span><span style="color: #0000FF;">,</span><span style="color: #000000;">k</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">language_name</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">correct_name</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cats</span><span style="color: #0000FF;">[</span><span style="color: #000000;">k</span><span style="color: #0000FF;">..</span><span style="color: #000000;">start</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">])</span>
<span style="color: #000000;">start</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">match</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"&lt;/a&gt;"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">cats</span><span style="color: #0000FF;">,</span><span style="color: #000000;">start</span><span style="color: #0000FF;">)+</span><span style="color: #000000;">4</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">output_users</span> <span style="color: #008080;">then</span>
<span style="color: #008080;">if</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">language_name</span><span style="color: #0000FF;">)></span><span style="color: #000000;">5</span>
<span style="color: #008080;">and</span> <span style="color: #000000;">language_name</span><span style="color: #0000FF;">[-</span><span style="color: #000000;">5</span><span style="color: #0000FF;">..-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">" User"</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">language_name</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">correct_name</span><span style="color: #0000FF;">(</span><span style="color: #000000;">language_name</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">..-</span><span style="color: #000000;">6</span><span style="color: #0000FF;">])</span>
<span style="color: #008080;">else</span>
<span style="color: #000000;">language_name</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">""</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">if</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">language_name</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">and</span> <span style="color: #7060A8;">find</span><span style="color: #0000FF;">(</span><span style="color: #000000;">language_name</span><span style="color: #0000FF;">,</span><span style="color: #000000;">language_names</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">then</span>
<span style="color: #008080;">while</span> <span style="color: #008080;">not</span> <span style="color: #7060A8;">find</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cats</span><span style="color: #0000FF;">[</span><span style="color: #000000;">start</span><span style="color: #0000FF;">],</span><span style="color: #008000;">"(&lt;"</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span> <span style="color: #000000;">start</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span> <span style="color: #008080;">end</span> <span style="color: #008080;">while</span> <span style="color: #000080;font-style:italic;">-- (ignore)</span>
<span style="color: #004080;">string</span> <span style="color: #000000;">members</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">cats</span><span style="color: #0000FF;">[</span><span style="color: #000000;">start</span><span style="color: #0000FF;">..</span><span style="color: #7060A8;">find</span><span style="color: #0000FF;">(</span><span style="color: #008000;">'&lt;'</span><span style="color: #0000FF;">,</span><span style="color: #000000;">cats</span><span style="color: #0000FF;">,</span><span style="color: #000000;">start</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)]</span>
<span style="color: #000000;">members</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">members</span><span style="color: #0000FF;">,</span><span style="color: #008000;">","</span><span style="color: #0000FF;">,</span><span style="color: #008000;">""</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">scanf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">members</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"(%d member%s)&lt;"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">results</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">append</span><span style="color: #0000FF;">(</span><span style="color: #000000;">results</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">res</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">][</span><span style="color: #000000;">1</span><span style="color: #0000FF;">],</span><span style="color: #000000;">language_name</span><span style="color: #0000FF;">})</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<span style="color: #000000;">results</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">sort_columns</span><span style="color: #0000FF;">(</span><span style="color: #000000;">results</span><span style="color: #0000FF;">,{-</span><span style="color: #000000;">2</span><span style="color: #0000FF;">,</span><span style="color: #000000;">3</span><span style="color: #0000FF;">})</span> <span style="color: #000080;font-style:italic;">-- (descending 2nd column, then asc 3rd)
--3) assign rank</span>
for @results.kv -> $i, @l {
<span style="color: #004080;">integer</span> <span style="color: #000000;">count</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">prev</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">rank</span>
printf "%d:\t%3d - %s\n", $i+1, |@l;
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">results</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
}</lang>
<span style="color: #000000;">count</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">results</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">][</span><span style="color: #000000;">2</span><span style="color: #0000FF;">]</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">count</span><span style="color: #0000FF;">=</span><span style="color: #000000;">prev</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">results</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">][</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"="</span>
<span style="color: #008080;">else</span>
<span style="color: #000000;">rank</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">i</span>
<span style="color: #000000;">results</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">][</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">sprint</span><span style="color: #0000FF;">(</span><span style="color: #000000;">rank</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">prev</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">count</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">return</span> <span style="color: #000000;">results</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #008080;">procedure</span> <span style="color: #000000;">show</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">results</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">progress</span><span style="color: #0000FF;">(</span><span style="color: #008000;">""</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #000000;">limit</span><span style="color: #0000FF;">?</span><span style="color: #000000;">limit</span><span style="color: #0000FF;">:</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">results</span><span style="color: #0000FF;">))</span> <span style="color: #008080;">do</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%3s: %,d - %s\n"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">results</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">])</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
<span style="color: #000000;">show</span><span style="color: #0000FF;">(</span><span style="color: #000000;">extract_names</span><span style="color: #0000FF;">())</span>
<!--</syntaxhighlight>-->
{{out}}
As of July 31st, 2019
(As of 2014-07-11.) Here we show only the top 10.
<pre>1: 833 - Tcl
Downloading rc_cache\languages.htm...
2: 781 - Racket
Downloading rc_cache\categories.htm...
3: 770 - Python
1: 1,156 - Go
4: 730 - Perl 6
5 2: 725 1,092 - JPhix
6 3: 712 1,090 - CPerl 6
7 4: 708 1,074 - RubyJulia
8 5: 698 1,066 - DPython
9 6: 674 1,046 - GoKotlin
10 7: 656 1,026 - Perl</pre>
8: 991 - Racket
9: 953 - C
10: 945 - J
11: 943 - Zkl
12: 930 - Tcl
13: 915 - REXX
14: 910 - Java
15: 897 - Ruby
16: 892 - D
17: 872 - Haskell
18: 816 - Sidef
19: 814 - Scala
20: 786 - C sharp
</pre>
 
=={{header|PicoLisp}}==
<langsyntaxhighlight PicoLisplang="picolisp">(load "@lib/http.l")
 
(for (I . X)
Line 3,248 ⟶ 3,991:
(when (format (till " " T))
(link (cons @ (ht:Pack Cat))) ) ) ) ) ) ) )
(prinl (align 3 I) ". " (car X) " - " (cdr X)) )</langsyntaxhighlight>
{{out|Output (dec15)}}
<pre> 1. 903 - Racket
Line 3,263 ⟶ 4,006:
 
=={{header|PowerShell}}==
{{trans|C sharp|C#}}
<syntaxhighlight lang="powershell">
<lang PowerShell>
$get1 = (New-Object Net.WebClient).DownloadString("http://www.rosettacode.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:Programming_Languages&cmlimit=700&format=json")
$get2 = (New-Object Net.WebClient).DownloadString("http://www.rosettacode.org/w/index.php?title=Special:Categories&limit=5000")
Line 3,292 ⟶ 4,035:
}
}| Format-Table -AutoSize
</syntaxhighlight>
</lang>
<b>Output: August 04, 2015</b>
<pre>
Line 3,327 ⟶ 4,070:
29 441 PARI/GP 59 249 Delphi
30 434 JavaScript 60 239 Smalltalk
</pre>
===PowerShell: Using web scraping===
{{trans|Python}}
<syntaxhighlight lang="powershell">
$response = (New-Object Net.WebClient).DownloadString("http://rosettacode.org/wiki/Category:Programming_Languages")
$languages = [regex]::matches($response,'title="Category:(.*?)">') | foreach {$_.Groups[1].Value}
 
$response = [Net.WebClient]::new().DownloadString("http://rosettacode.org/w/index.php?title=Special:Categories&limit=5000")
$response = [regex]::Replace($response,'(\d+),(\d+)','$1$2')
 
$members = [regex]::matches($response,'<li><a[^>]+>([^<]+)</a>[^(]*[(](\d+) member[s]?[)]</li>') | foreach { [pscustomobject]@{
Members = [Int]($_.Groups[2].Value)
Language = [String]($_.Groups[1].Value)
}} | where {$languages.Contains($_.Language)} | sort -Descending Members
 
Get-Date -UFormat "Sample output on %d %B %Y at %R %Z"
$members | Select-Object -First 10 | foreach -Begin {$r, $rank, $count = 0, 0,-1} {
$r++
if ($count -ne $_.Members) {$rank = $r}
$count = $_.Members
$x = $_.Members.ToString("N0",[System.Globalization.CultureInfo]::CreateSpecificCulture('en-US'))
$entry = "($x entries)"
[String]::Format("Rank: {0,2} {1,15} {2}",$rank,$entry,$_.Language)
}
</syntaxhighlight>
{{out}}
<pre>
Sample output on 13 septembre 2019 at 12:17 +02
Rank: 1 (1,177 entries) Go
Rank: 2 (1,116 entries) Phix
Rank: 3 (1,107 entries) Perl 6
Rank: 4 (1,104 entries) Julia
Rank: 5 (1,080 entries) Python
Rank: 6 (1,053 entries) Kotlin
Rank: 7 (1,048 entries) Perl
Rank: 8 (1,045 entries) Racket
Rank: 9 (970 entries) C
Rank: 10 (960 entries) Zkl
</pre>
 
===PowerShell: Using MediaWiki API method===
{{trans|Python}}
<syntaxhighlight lang="powershell">
$languages = @{}
$Body = @{
format = 'json'
action = 'query'
generator = 'categorymembers'
gcmtitle = 'Category:Programming Languages'
gcmlimit = '200'
gcmcontinue = ''
continue = ''
prop = 'categoryinfo'
}
$params = @{
Method = 'Get'
Uri = 'http://rosettacode.org/mw/api.php'
Body = $Body
}
while ($true) {
$response = Invoke-RestMethod @params
$response.query.pages.PSObject.Properties | ForEach-Object {
if (($_.value.PSObject.Properties.Name -Contains 'title') -and ($_.value.PSObject.Properties.Name -Contains 'categoryinfo')) {
$languages[$_.value.title.replace('Category:', '')] = $_.value.categoryinfo.size
}
}
if ($response.PSObject.Properties.Name -Contains 'continue') {
$gcmcontinue = $response.continue.gcmcontinue
$params.Body.gcmcontinue = $gcmcontinue
} else {
break
}
}
$members = $languages.GetEnumerator() | sort -Descending value
Get-Date -UFormat "Sample output on %d %B %Y at %R %Z"
$members | Select-Object -First 10 | foreach -Begin {$r, $rank, $count = 0, 0,-1} {
$r++
if ($count -ne $_.Members) {$rank = $r}
$count = $_.Value
$x = $_.Value.ToString("N0",[System.Globalization.CultureInfo]::CreateSpecificCulture('en-US'))
$entry = "($x entries)"
[String]::Format("Rank: {0,2} {1,15} {2}",$rank, $entry, $_.Name)
}
</syntaxhighlight>
{{out}}
<pre>
Sample output on 05 juillet 2022 at 19:53 +02
Rank: 1 (1,552 entries) Phix
Rank: 2 (1,545 entries) Wren
Rank: 3 (1,521 entries) Julia
Rank: 4 (1,498 entries) Go
Rank: 5 (1,497 entries) Raku
Rank: 6 (1,456 entries) Perl
Rank: 7 (1,402 entries) Nim
Rank: 8 (1,401 entries) Python
Rank: 9 (1,206 entries) C
Rank: 10 (1,180 entries) J
</pre>
 
=={{header|PureBasic}}==
===Using MediaWiki API method===
<langsyntaxhighlight lang="purebasic">Procedure handleError(value, msg.s)
If value = 0
MessageRequester("Error", msg)
Line 3,458 ⟶ 4,298:
Print(#CRLF$ + #CRLF$ + "Press ENTER to exit"): Input()
CloseConsole()
EndIf</langsyntaxhighlight>
Sample output:
<pre>608 languages.
Line 3,526 ⟶ 4,366:
 
===Using web scraping method===
<langsyntaxhighlight lang="purebasic">
;Uses a web scraping method.
 
Line 3,582 ⟶ 4,422:
PrintN( Str(i + 1) + ". " + Str(Row(i)\count) + " - " + Row(i)\Name)
Next
Input()</langsyntaxhighlight>
Sample output:
<pre>1. 907 - Racket
Line 3,618 ⟶ 4,458:
 
===Python: Using web scraping===
{{works with|Python|3.5}}
Using <code>requests</code> library.
Scraping the languages and categories pages.
 
<langsyntaxhighlight lang="python">import requests
import re
 
LANGUAGES_URLresponse = requests.get("http://rosettacode.org/wiki/Category:Programming_Languages").text
languages = re.findall('title="Category:(.*?)">',response)[:-3] # strip last 3
CATEG_ENTRIES_URL = "http://rosettacode.org/mw/index.php?title=Special:Categories&limit=5000"
 
response = requests.get("http://rosettacode.org/mw/index.php?title=Special:Categories&limit=5000").text
languages_source = requests.get(LANGUAGES_URL).text
response = re.sub('(\d+),(\d+)',r'\1'+r'\2',response) # strip ',' from popular languages above 999 members
categ_entries_source = requests.get(CATEG_ENTRIES_URL).text
members = re.findall('<li><a[^>]+>([^<]+)</a>[^(]*[(](\\d+) member[s]*[)]</li>',response) # find language and members
 
for cnt, (language, members) in enumerate(sorted(members, key=lambda x: -int(x[1]))[:15]): # show only top 15 languages
raw_languages = re.findall('title="Category:(.+?)">', languages_source)
# remove dumb if language entriesin languages:
print("{:4d} {:4d} - {}".format(cnt+1, int(members), language))
languages = [lang for lang in raw_languages
if lang not in ('Languages', 'Static Category Cache', 'Encyclopedia')]
 
</syntaxhighlight>
categ_entries = re.findall(
{{out|Output (as of Dec 21, 2020)}}
'<li><a[^>]+>([^<]+)</a>[^(]*[(](\\d+) member[s]*[)]</li>',
1 1306 - Go
categ_entries_source)
2 1275 - Phix
3 1265 - Julia
4 1257 - Raku
5 1196 - Python
6 1182 - Perl
7 1107 - Kotlin
8 1080 - C
9 1074 - Java
10 1061 - Racket
11 1022 - REXX
12 1012 - Zkl
13 1002 - J
14 983 - Ruby
15 972 - Haskell
 
===Python: Using MediaWiki API method===
lang_entries = [(categ, int(entries))
<syntaxhighlight lang="python">
for categ, entries in categ_entries if categ in languages]
import requests
sorted_lang_entries = sorted(lang_entries, key=lambda x: -x[1])
import operator
import re
 
api_url = 'http://rosettacode.org/mw/api.php'
for i, (lang, entries) in enumerate(sorted_lang_entries):
languages = {}
print("{:4d}. {:4d} - {}".format(i+1, entries, lang))</lang>
 
parameters = {
{{out|Output (as of Jul 17, 2016)}}
1. 'format': 908 - Racket 'json',
2. 'action': 899 - Tcl 'query',
'generator': 'categorymembers',
3. 880 - Python
'gcmtitle': 'Category:Programming Languages',
4. 853 - J
5. 'gcmlimit': 827 - Perl 6 '200',
'gcmcontinue': '',
6. 797 - Ruby
7. 'continue': 780 - C '',
'prop': 'categoryinfo'
8. 770 - Go
}
9. 767 - Java
10. 750 - D
11. 746 - REXX
12. 739 - Perl
13. 714 - Zkl
14. 713 - Haskell
15. 699 - PicoLisp
. . .
 
===Python: not working===
{{improve|Python|This solution scrapes Special:Categories &limit 5000 which will break if the HTML style changes or the number of languages exceeds 5000. It could use the MediWiki API to get the language names and pages in a single call, in blocks of 500 until complete with no upper limit. See the [[Rosetta_Code/Rank_languages_by_popularity#AWK|Awk example]]. If you make an API-based version please retain the web-scrapping version in its own sub-section (following the lead of [[Rosetta_Code/Rank_languages_by_popularity#Tcl|TCL on this page]]).}}
 
{{works with|Python|2.6}}
This uses MediaWiki's JSON API to query the members of [[:Category:Programming Languages]] and then scrapes [[:Special:Categories]] for the number of pages in each language's category.
<lang python>import urllib, re
 
while(True):
key1 = lambda x: int(x[1])
response = requests.get(api_url, params=parameters).json()
for k,v in response['query']['pages'].items():
if 'title' in v and 'categoryinfo' in v:
languages[v['title']]=v['categoryinfo']['size']
if 'continue' in response:
gcmcontinue = response['continue']['gcmcontinue']
# print(gcmcontinue)
parameters.update({'gcmcontinue': gcmcontinue})
else:
break
 
# report top 15 languages
get1 = urllib.urlopen("http://www.rosettacode.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:Programming_Languages&cmlimit=500&format=json").read()
for i, (language, size) in enumerate(sorted(languages.items(), key=operator.itemgetter(1), reverse=True)[:15]):
get2 = urllib.urlopen("http://www.rosettacode.org/w/index.php?title=Special:Categories&limit=5000").read()
print("{:4d} {:4d} - {}".format(i+1, size, re.sub('Category:','',language))) # strip Category: from language
 
langs = re.findall("\"title\":\"Category:(.+?)\"",get1)
qtdmbr = re.findall("title=\"Category:(.+?)\">.+?</a> \((\d+) members\)",get2)
 
</syntaxhighlight>
result = [(x,int(y)) for x,y in qtdmbr if x in langs]
{{out|Output (as of Dec 21, 2020)}}
1 1306 - Go
2 1275 - Phix
3 1265 - Julia
4 1257 - Raku
5 1196 - Python
6 1182 - Perl
7 1107 - Kotlin
8 1080 - C
9 1074 - Java
10 1061 - Racket
11 1022 - REXX
12 1012 - Zkl
13 1002 - J
14 983 - Ruby
15 972 - Haskell
 
=={{header|R}}==
for n, i in enumerate(sorted(result,key=key1,reverse=True)):
print "%3d. %3d - %s" % (n+1, i[1], i[0])</lang>
{{out|Output (as of Sep 11, 2010)}}
1. 423 - Tcl
2. 394 - Python
3. 368 - J
4. 365 - PicoLisp
5. 362 - Ruby
6. 355 - C
7. 351 - Haskell
8. 339 - OCaml
9. 316 - Perl
10. 315 - PureBasic
11. 306 - D
12. 302 - AutoHotkey
13. 300 - Common Lisp
14. 295 - Java
15. 293 - Ada
16. 278 - Oz
17. 260 - C++
18. 260 - C sharp
. . .
 
<syntaxhighlight lang="rsplus">
=={{header|R}}==
{{improve|Perl|It only finds 500 languages (which is the max 'gcmlimit' for a single API request), but there are now over 500 languages on Rosettacode. The code needs to be changed to make additional requests as needed.}}
<lang R>
library(rvest)
library(plyr)
library(dplyr)
options(stringsAsFactors=FALSE)
 
# getting the required table from the rosetta website
langUrl <- "http://rosettacode.org/mw/api.php?format=xml&action=query&generator=categorymembers&gcmtitle=Category:Programming%20Languages&prop=categoryinfo&gcmlimit=500"
langUrl <- "https://rosettacode.org/wiki/Rosetta_Code/Rank_languages_by_popularity/Full_list"
langs <- html(langUrl) %>%
langs <- read_html(langUrl) %>%
html_nodes('page')
html_nodes(xpath='/html/body/div/div/div[1]/div[3]/main/div[2]/div[3]/div[1]/table') %>%
html_table() %>%
data.frame() %>%
select(c("Rank","TaskEntries","Language"))
 
ff <- function(xml_node) {
language <- xml_node %>% html_attr("title")
language <- sub("^Category:", "", language)
npages <- xml_node %>% html_nodes('categoryinfo') %>%
html_attr("pages")
c(language, npages)
}
tbl <- ldply(sapply(langs, ff), rbind)
names(tbl) <- c("language", "n")
tbl %>%
mutate(n=as.integer(n)) %>%
arrange(desc(n)) %>%
head
</lang>
{{out|Output (as of July, 5, 2015)}}
<pre>
language n
1 Tcl 878
2 Racket 868
3 Python 837
4 J 787
5 Ruby 770
6 Perl 6 762
</pre>
 
# changing the columns to required format
langs$Rank = paste("Rank: ",langs$Rank)
langs$TaskEntries = paste0("(", format(langs$TaskEntries, big.mark = ",")
," entries", ")")
 
names(langs) <- NULL
{{incorrect|R|This solution fails if there are more than 500 users in a language, which is now the case for the top 25 languages as of May 2015.}}
<lang R>library(RJSONIO)
langUrl <- "http://rosettacode.org/mw/api.php?action=query&format=json&cmtitle=Category:Solutions_by_Programming_Language&list=categorymembers&cmlimit=500"
 
langs[1:10,]
languages <- fromJSON(langUrl)$query$categorymembers
languages <- sapply(languages, function(x) sub("Category:", "", x$title))
 
# fails if there are more than 500 users per language
user <- function (lang) {
userBaseUrl <- "http://rosettacode.org/mw/api.php?action=query&format=json&list=categorymembers&cmlimit=500&cmtitle=Category:"
userUrl <- paste(userBaseUrl, URLencode(paste(lang, " User", sep="")),sep="")
length(fromJSON(userUrl)$query$categorymembers)
}
 
</syntaxhighlight>
users <- sapply(languages, user)
{{out|Output (as of October, 24, 2022)}}
head(sort(users, decreasing=TRUE),15)</lang>
{{out|Output (as of March, 13, 2010)}}
<pre>
1 Rank: 1 (1,589 entries) Phix
C C++ Java Python JavaScript Perl UNIX Shell
2 Rank: 1 (1,589 entries) Wren
55 55 37 32 27 27 22
3 Rank: 3 (1,552 entries) Julia
Pascal BASIC PHP SQL Haskell AWK C sharp
4 Rank: 4 (1,535 entries) Raku
20 19 19 18 17 16 16
5 Rank: 5 (1,500 entries) Go
Ruby
6 Rank: 6 (1,485 entries) 14 Perl
7 Rank: 7 (1,422 entries) Python
8 Rank: 8 (1,402 entries) Nim
9 Rank: 9 (1,293 entries) J
10 Rank: 10 (1,213 entries) C
</pre>
 
=={{header|Racket}}==
<lang racket>#lang racket
 
{{trans|Python}}
(require net/url)
(require json)
 
<syntaxhighlight lang="racket">#lang racket
(define proglangs_url "http://rosettacode.org/mw/api.php?action=query&list=categorymembers&cmtitle=Category:Programming_Languages&cmlimit=500&format=json")
(define categories_url "http://rosettacode.org/mw/index.php?title=Special:Categories&limit=5000")
(require racket/hash
net/url
json)
(define limit 15)
(define (replacer cat) (regexp-replace #rx"^Category:(.*?)$" cat "\\1"))
(define category "Category:Programming Languages")
(define entries "entries")
(define api-url (string->url "http://rosettacode.org/mw/api.php"))
(define (make-complete-url gcmcontinue)
(struct-copy url api-url
[query `([format . "json"]
[action . "query"]
[generator . "categorymembers"]
[gcmtitle . ,category]
[gcmlimit . "200"]
[gcmcontinue . ,gcmcontinue]
[continue . ""]
[prop . "categoryinfo"])]))
 
(define (fetch-json@ urlstringhash-ref)
(read-json (get-pure-port (string->url urlstring))))
 
(define programmingtable (make-languageshash))
(for/set ([h (in-list
(let loop ([gcmcontinue ""])
(hash-ref (hash-ref (fetch-json proglangs_url) 'query)
(define resp (read-json (get-pure-port (make-complete-url gcmcontinue))))
'categorymembers))])
(hash-union! table
(substring (hash-ref h 'title) 9)))
(for/hash ([(k v) (in-hash (@ (@ resp 'query) 'pages))])
(values (@ v 'title #f) (@ (@ v 'categoryinfo (hash)) 'size 0))))
(cond [(@ resp 'continue #f) => (λ (c) (loop (@ c 'gcmcontinue)))]))
(for/fold ([prev #f] [rank #f] #:result (void))
([item (in-list (sort (hash->list table) > #:key cdr))] [i (in-range limit)])
(match-define (cons cat size) item)
(define this-rank (if (equal? prev size) rank (add1 i)))
(printf "Rank: ~a ~a ~a\n"
(~a this-rank #:align 'right #:min-width 2)
(~a (format "(~a ~a)" size entries) #:align 'right #:min-width 14)
(replacer cat))
(values size this-rank))</syntaxhighlight>
 
Output on September 4, 2019:
(define result '())
(for ([l (in-port read-line (get-pure-port (string->url categories_url)))])
(let ([res (regexp-match #px"title=\"Category:(.+?)\".+\\((\\d+) member" l)])
(when (and res (set-member? programming-languages (cadr res)))
(set! result (cons (cons (cadr res)
(string->number (caddr res)))
result)))))
 
<pre>
(printf "Place\tCount\tName~n")
Rank: 1 (1176 entries) Go
(for ([lang (in-list (sort result > #:key cdr))]
Rank: 2 (1112 entries) Phix
[place (in-naturals 1)])
Rank: 3 (1107 entries) Perl 6
(printf "~a\t~a\t~a~n" place (cdr lang) (car lang)))
Rank: 4 (1099 entries) Julia
</lang>
Rank: 5 (1079 entries) Python
Output, 2013-5-25:
Rank: 6 (1053 entries) Kotlin
<pre>Place Count Name
Rank: 7 (1038 entries) Racket
1 737 Tcl
Rank: 8 (1037 entries) Perl
2 676 Python
Rank: 9 (968 entries) C
3 660 C
Rank: 10 (960 entries) Zkl
4 638 J
Rank: 11 (945 entries) J
5 626 PicoLisp
Rank: 12 (935 entries) REXX
6 609 Perl 6
Rank: 13 (930 entries) Tcl
7 609 D
Rank: 14 (910 entries) Java
8 601 Racket
Rank: 15 (904 entries) Ruby
9 592 Ruby
10 589 Go
...
</pre>
 
Recent, occasionally (hourly-ish) updated output also available at:
http://www.timb.net/popular-languages.html.
 
=={{header|Raku}}==
(formerly Perl 6)
 
===Raku: Using the API===
Note that this counts '''only''' the tasks. It does not include other non-task categories in the counts yielding more realistic, non-inflated numbers. Raku is Unicode aware and handles non-ASCII names natively. This does not attempt to 'unify' different language names that are the same behind the scenes as a result of Rosettacodes' capitalization peculiarities. (E.G. μC++, UC++ & ΜC++)
 
<syntaxhighlight lang="raku" line>use HTTP::UserAgent;
use URI::Escape;
use JSON::Fast;
use Sort::Naturally;
 
my $client = HTTP::UserAgent.new;
 
my $url = 'https://rosettacode.org/w';
 
my $tablefile = './RC_Popularity.txt';
 
my %cat = (
'Programming_Tasks' => 'Task',
'Draft_Programming_Tasks' => 'Draft'
);
my %tasks;
 
for %cat.keys.sort -> $cat {
mediawiki-query(
$url, 'pages',
:generator<categorymembers>,
:gcmtitle("Category:$cat"),
:gcmlimit<350>,
:rawcontinue(),
:prop<title>
).map({ %tasks{%cat{$cat}}++ });
}
 
my %counts =
mediawiki-query(
$url, 'pages',
:generator<categorymembers>,
:gcmtitle<Category:Programming Languages>,
:gcmlimit<350>,
:rawcontinue(),
:prop<categoryinfo>
)
.map({
my $title = .<title>.subst(/^'Category:'/, '');
my $tasks = (.<categoryinfo><pages> || 0);
my $categories = (.<categoryinfo><subcats> || 0);
my $total = (.<categoryinfo><size> || 0);
$title => [$tasks ,$categories, $total]
});
 
my $out = open($tablefile, :w) or die "$!\n";
 
# Add table boilerplate and header
$out.say:
"\{|class=\"wikitable sortable\"\n",
"|+ As of { Date.today } :: {+%counts} Languages\n",
'!Rank!!Language!!Task<br>Entries!!Tasks<br>done %!!Non-task<br>Subcate-<br>gories!!Total<br>Categories'
;
 
my @bg = <#fff; #ccc;>;
my $ff = 0;
my $rank = 1;
my $ties = 0;
 
# Get sorted unique task counts
for %counts.values»[0].unique.sort: -* -> $count {
$ff++;
# Get list of tasks with this count
my @these = %counts.grep( *.value[0] == $count )».keys.sort: *.&naturally;
 
for @these {
$ties++;
$out.say:
"|- style=\"background-color: { @bg[$ff % 2] }\"\n"~
"|$rank\n"~
"|[[:Category:$_|]]\n"~
"|$count\n"~
"|{(100 * $count/%tasks<Draft Task>.sum).round(.01)} %\n"~
"|{%counts{$_}[1]}\n"~
"|{%counts{$_}[2]}"
}
$rank += $ties;
$ties = 0;
}
$out.say( "|}" );
$out.say('=' x 5, " query, download & processing: {(now - INIT now).round(.01)} seconds ", '=' x 5);
$out.close;
 
sub mediawiki-query ($site, $type, *%query) {
my $url = "$site/api.php?" ~ uri-query-string(
:action<query>, :format<json>, :formatversion<2>, |%query);
my $continue = '';
 
gather loop {
my $response = $client.get("$url&$continue");
my $data = from-json($response.content);
take $_ for $data.<query>.{$type}.values;
$continue = uri-query-string |($data.<query-continue>{*}».hash.hash or last);
}
}
 
sub uri-query-string (*%fields) {
join '&', %fields.map: { "{.key}={uri-escape .value}" }
}</syntaxhighlight>
 
{{out|Abridged output}} See [[Rosetta_Code/Rank_languages_by_popularity/Full_list|full output here]].
{|class="wikitable sortable"
|+ As of 2019-02-10 :: 715 Languages
!Rank!!Language!!Task<br>Entries!!Tasks<br>done %!!Non-task<br>Subcate-<br>gories!!Total<br>Categories
|- style="background-color: #ccc;"
|1
|[[:Category:Go|Go]]
|1100
|96.15 %
|4
|1104
|- style="background-color: #fff;"
|2
|[[:Category:Perl 6|Perl 6]]
|1046
|91.43 %
|4
|1050
|- style="background-color: #ccc;"
|3
|[[:Category:Kotlin|Kotlin]]
|1029
|89.95 %
|1
|1030
|- style="background-color: #fff;"
|4
|[[:Category:Python|Python]]
|1017
|88.9 %
|17
|1034
|- style="background-color: #ccc;"
|5
|[[:Category:Phix|Phix]]
|991
|86.63 %
|3
|994
|- style="background-color: #fff;"
|6
|[[:Category:Racket|Racket]]
|986
|86.19 %
|3
|989
|- style="background-color: #ccc;"
|7
|[[:Category:Perl|Perl]]
|963
|84.18 %
|5
|968
|- style="background-color: #fff;"
|8
|[[:Category:Julia|Julia]]
|958
|83.74 %
|3
|961
|- style="background-color: #ccc;"
|9
|[[:Category:C|C]]
|940
|82.17 %
|3
|943
|- style="background-color: #fff;"
|10
|[[:Category:Tcl|Tcl]]
|925
|80.86 %
|4
|929
|- style="background-color: #ccc;"
|11
|[[:Category:Zkl|Zkl]]
|918
|80.24 %
|1
|919
|- style="background-color: #fff;"
|12
|[[:Category:J|J]]
|901
|78.76 %
|3
|904
|- style="background-color: #ccc;"
|13
|[[:Category:Java|Java]]
|897
|78.41 %
|3
|900
|- style="background-color: #fff;"
|14
|[[:Category:REXX|REXX]]
|886
|77.45 %
|4
|890
|- style="background-color: #ccc;"
|15
|[[:Category:D|D]]
|871
|76.14 %
|3
|874
|- style="background-color: #fff;"
|16
|[[:Category:Ruby|Ruby]]
|866
|75.7 %
|3
|869
|- style="background-color: #ccc;"
|17
|[[:Category:Haskell|Haskell]]
|849
|74.21 %
|3
|852
|- style="background-color: #fff;"
|18
|[[:Category:Scala|Scala]]
|789
|68.97 %
|3
|792
|- style="background-color: #ccc;"
|19
|[[:Category:Sidef|Sidef]]
|787
|68.79 %
|1
|788
|- style="background-color: #fff;"
|20
|[[:Category:PicoLisp|PicoLisp]]
|772
|67.48 %
|3
|775
|}
 
===Raku: Using web scraping===
 
Scraping the languages and categories pages. Raku automatically handles Unicode names correctly.
<syntaxhighlight lang="raku" line>my $languages = qx{wget -O - 'http://rosettacode.org/wiki/Category:Programming_Languages'};
my $categories = qx{wget -O - 'http://www.rosettacode.org/mw/index.php?title=Special:Categories&limit=5000'};
my @lines = $languages.lines;
shift @lines until @lines[0] ~~ / '<h2>Subcategories</h2>' /;
my \languages = set gather for @lines {
last if / '/bodycontent' /;
take ~$0 if
/ '<li><a href="/wiki/Category:' .*? '" title="Category:' .*? '">' (.*?) '</a></li>' /;
}
@lines = $categories.lines;
my @results = sort -*.[0], gather for @lines {
take [+$1.subst(',', ''), ~$0] if
/ '<li><a href="/wiki/Category:' .*? '" title="Category:' .*? '">'
(.*?) <?{ ~$0 ∈ languages }>
'</a>' .*? '(' (<[, 0..9]>+) ' member' /;
}
for @results.kv -> $i, @l {
printf "%d:\t%4d - %s\n", $i+1, |@l;
}</syntaxhighlight>
{{out}}
(As of 2018-10-28) Here we show only the top 10.
<pre>1: 1036 - Go
2: 1029 - Kotlin
3: 1014 - Python
4: 998 - Perl 6
5: 980 - Racket
6: 929 - Tcl
7: 926 - C
8: 910 - Perl
9: 904 - Zkl
10: 901 - J</pre>
 
=={{header|Red}}==
proccesses only languages with more than 25 entries to keep the list short
<syntaxhighlight lang="red">Red []
 
data: read http://www.rosettacode.org/mw/index.php?title=Special:Categories&limit=5000
lb: make block! 500
;;data: read %data.html ;; for testing save html and use flat file
arr: split data newline
 
k: "Category:"
;; exclude list:
exrule: [thru ["programming"
| "users"
| "Implementations"
| "Solutions by "
| "Members"
| "WikipediaSourced"
| "Typing/Strong"
| "Impl needed"
]
to end
]
foreach line arr [
unless find line k [continue]
parse line [ thru k thru ">" copy lang to "<" to end ] ;; extract/parse language
if 20 < length? lang [continue]
if parse lang [exrule] [continue] ;; exclude invalid
cnt: 0
;; parse number of entries
parse line [thru "</a>" thru "(" copy cnt to " member" (cnt: to-integer cnt ) to end]
if cnt > 25 [ append lb reduce [to-string lang cnt] ] ;; only process lang with > 25 entries
]
 
lb: sort/skip/compare lb 2 2 ;; sort series by entries
 
print reduce [ "Rank Entries Language" ] ;; header
 
last: 0
rank: 0
 
lb: tail lb ;; process the series backwards
 
until [
lb: skip lb -2
cnt: second lb
if cnt <> last [
rank: rank + 1
]
print rejoin [ pad/left rank 4 "." pad/left cnt 5 " - " first lb ]
last: cnt
head? lb ;; until head reached
]
</syntaxhighlight>
Output: (30.12.2017)
<pre>
Rank Entries Language
1. 961 - Racket
2. 959 - Python
3. 926 - Perl 6
4. 918 - Tcl
5. 900 - Kotlin
6. 883 - J
7. 875 - C
8. 859 - Zkl
9. 846 - Ruby
10. 833 - D
11. 828 - Go
12. 812 - REXX
13. 809 - Haskell
14. 802 - Java
15. 785 - Perl
16. 768 - PicoLisp
17. 733 - Sidef
18. 723 - Mathematica
19. 702 - Julia
20. 683 - Phix
21. 668 - C++
22. 648 - Ada
23. 647 - Common Lisp
24. 637 - C sharp
25. 621 - AutoHotkey
</pre>
 
=={{header|REXX}}==
(Native) &nbsp; REXX doesn't support web-page reading, so the mentioned &nbsp; ''Rosettaso Code categories'' &nbsp;the andaforementioned
<br>::: &nbsp; ''Rosetta Code Languagescategories'' &nbsp; were downloaded&nbsp; to local files.&nbsp; and
::: &nbsp; ''Rosetta Code languages''
<br>were downloaded to local files.
 
<br>This program reads the &nbsp; ''Languages'' &nbsp; file and uses the contents of that file for a validation of
Line 3,830 ⟶ 5,046:
The mechanism is to use a (sparse) stemmed array which holds only the names of languages which
<br>(for most REXXes) uses a hashing algorithm to locate the entry &nbsp; (which is very fast).
 
<br><br>Programming note: &nbsp; (REXX doesn't handle Unicode characters) &nbsp; some special cases that are translated:
Programming note: &nbsp; (REXX doesn't handle Unicode characters) &nbsp; some special cases that are translated:
:::* &nbsp; '''╬£C++''' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; translated into &nbsp; '''µC++''' &nbsp; &nbsp; &nbsp; &nbsp; [Greek micro]
:::* &nbsp; '''£╨Ü-61/52C++''' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; translated into &nbsp; '''MK-61/52µC++''' &nbsp; [Cyrillic&nbsp; &nbsp; '''МК-61/52'''&nbsp;&nbsp; [Greek micro])
:::* &nbsp; '''??╨£╨Ü-61/52''' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; translated into &nbsp; '''MK-61/52''' &nbsp; [Cyrillic &nbsp; '''МК-61/52'''])
:::* &nbsp; '''D├⌐j├á Vu??-61/52''' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; translated into &nbsp; '''DéjàMK-61/52''' Vu&nbsp; [Cyrillic &nbsp; '''МК-61/52'''])
:::* &nbsp; '''Cach├⌐D├⌐j├á Vu''' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; translated into &nbsp; '''CachéDéjà Vu'''
:::* &nbsp; '''α«ëα«»α«┐α«░α»ì/UyirCach├⌐''' &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; translated into &nbsp; '''UyirCaché'''
:::* &nbsp; '''F┼ìrmul├ª''' &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; translated into &nbsp; '''Fôrmulæ'''
:::* &nbsp; '''உயிர்/Uyir''' &nbsp;&nbsp; &nbsp; translated into &nbsp; '''Uyir'''
:::* &nbsp; '''МiniZinc''' &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; translated into &nbsp; '''MiniZinc'''
(The 3<sup>rd</sup> entry is most likely caused by the inability to render unsupported glyphs when it was first used to add that language.)
 
 
Code was added to support the renaming of the computer programming language &nbsp; '''Perl 6''' &nbsp; ──► &nbsp; '''Raku'''.
 
Note that this REXX example properly ranks tied languages.
 
This REXX version now sorts the &nbsp; tied &nbsp; languages by language name (thanks to Walter Pachl's suggestion).
===REXX program===
<langsyntaxhighlight lang="rexx">/*REXX program reads two files and displays a ranked list of Rosetta Code languages.*/
sep='█'; L.=0; #.=0; u.=0; catHeap=; old.= /*assign some REXX variable defaults. */
parse arg catFID lanFID outFID . /*obtain optional arguments from the CL*/
call init /*initialize some REXX variables. */
if catFID=='' then catFID = "RC_POP.CAT" /*Not specified? Then use the default.*/
ifcall lanFID==''get then lanFID = "RC_POP.LAN" /* " " " " " " /*obtain data from two separate files. */
ifcall outFID==''eSort #,0 then outFID = 'RC_POP.OUT' /* " " " " " /*sort languages along with " members. */
call tSort /* " " that are tied in rank.*/
call tell center('timestamp: ' date() time("Civil"),79,'═'), 2, 1 /*timestamp,title.*/
langs=0;call eSort #,1 call reader 'languages' /*assign languages " ───► L.ααα " along with members. */
call out call reader 'categories' /*append categories ───► catHeap /*create the RC_POP.OUT (output) file.*/
#=exit 0 /*stick a fork /*thein numberit, of categorieswe're all (so far)done. */
do j=1 until catHeap=='' /*process the heap of categories. */
parse var catHeap cat.j (sep) catHeap /*get a category from the catHeap. */
parse var cat.j cat.j '<' "(" mems . /*untangle the strange-looking string. */
cat.j=space(cat.j); ?=cat.j; upper ? /*remove any superfluous blanks. */
if ?=='' | \L.? then iterate /*it's blank or it's not a language. */
if \datatype(mems,'W') then iterate /*is the "members" not numeric ? */
#.0=#.0 + mems /*bump the number of members found. */
if u.?\==0 then do; do f=1 for # until ?==@u.f; end /*f*/
#.f=#.f + mems; iterate j /*languages that're in different cases.*/
end /* [↑] handle any possible duplicates.*/
u.?=u.? + 1
#=#+1; #.#=#.#+mems; @.#=cat.j; @u.#=? /*bump the counter; assign it (upper).*/
end /*j=1 until ··· */
!.= /*array holds indication of TIED langs.*/
call tell right(commas(#), 9) '(total) number of languages detected in the category file,'
call tell right(commas(langs),9) ' " " " " " " " language " ,'
call tell right(commas(#.0), 9) '(total) number of entries detected.', , 1
call eSort #, 0 /*sort the languages along with number.*/
tied= /*add true rank (tR) ───► the entries. */
r=0; do j=# by -1 for #; r=r+1; tR=r; !tR.j=r; jp=j+1; jm=j-1
if tied=='' then pR=r; tied= /*handle when language rank is untied. */
if #.j==#.jp | #.j==#.jm then do; !.j= '[tied]'; tied=!.j; end
if #.j==#.jp then do; tR=pR; !tR.j=pR; end
else pR=r
end /*j=# by ···*/
call eSort #, 1 /*sort the languages along with entries*/
w=length(#) /* [↓] show by ascending rank of lang.*/
rank=0
do t=# by -1 for #; rank=rank + 1 /*bump the counter for the rank. */
call tell right('rank:' right(!tR.t, w), 20-1) right(!.t, 7),
right('('#.t left("entr"s(#.t, 'ies', "y")')', 9), 20) @.t
end /*#*/ /* [↑] s(···) pluralizes a word. */
 
call tell left('', 27) '☼ end─of─list. ☼', 1, 2 /*the bottom title.*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
commas: procedure; parse arg _; n do jc=length(_'.9';)-3 #=123456789; #0=#"0"to 1 by -3; #0._=#0'.';b=verify insert(n,#","M",_,jc); end; return _
s: if arg(1)==1 then return arg(3); return word(arg(2) 's',1) /*pluralizer.*/
e=verify(n,#0,,verify(n,#0.,'M'))-4; do j=e to b by -3; _=insert(",",_,j); end; return _
/*──────────────────────────────────────────────────────────────────────────────────────*/
eSort: procedure expose #. @. !tr.; arg N,p2; h= N /*sort by: number entries.of members*/
do while while h>1; h= h % 2 /*the sorthalve kindanumber halved.of records*/
do i=1 for N-h; j= i; k= h +i i /*sort this part of list.*/
if p2 then do while !tR.k==!tR.j & @.k>@.j /*this uses a hard swap ↓*/
t@= @.j; tt#= !tR.j; @.j= @.k; !tR.j= !tR.k; @.k=t @; !tR.k=tt #
if h>=j then leave; j= j - h; k= k - h
end /*while !tR.k==···*/
else do while #.k<#.j /*this uses a hard swap ↓*/
t@= @.j; tt#= #.j; @.j= @.k; #.j= #.k; @.k=t; @; #.k=tt #
if h>=j then leave; j= j - h; k= k - h
end /*while #.k<#.j···*/
end /*i*/ /*hard swaps needed for embedded blanks.*/
end /*while h>1*/; return
return
/*──────────────────────────────────────────────────────────────────────────────────────*/
readerget: arg whichlangs= 20; igAst=1 call rdr 'languages' /*assign languages ───► L.ααα /*ARG uppers WHICH, obtain the 1st char*/
if which=='L' then inFID=lanFID call rdr 'categories' /*useappend categories ───► thiscatHeap fileID for the languages. */
#= 0
if which=='C' then inFID=catFID /* " " " " " categories. */
Uyir do j=1 until catHeap=='உயிர்/Uyir' /*Unicode (inprocess text)the heap nameof forcategories. Uyir */
old.1= '╬£C++' parse var ;catHeap newcat.1= "µC++" j (sep) catHeap /*Unicodeget ╬£C++a category ───►from ASCII-8:the µC++catHeap. */
old.2= 'UC++' parse var cat.j ; newcat.2=j '<' "µC++(" mems . /*olduntangle the strange─looking UC++ ───► ASCII-8: µC++ string. */
old.3= '╨£╨Ü-' cat.j= space(cat.j); new?=cat.3= "MK-" j; upper ? /*Unicoderemove ╨£╨Ü-any superfluous ───►blanks. ASCII-8: MK- */
old.4= if ?=='D├⌐j├á' | \L.? ; new.4= "Déjà" then iterate /*Unicodeit's ├⌐j├áblank ───►or ASCII-8: it's Déjànot a language. */
if pos(',', mems)\==0 then mems= space(translate(mems,,","), 0) /*¬commas.*/
old.5= 'Cach├⌐' ; new.5= "Caché" /*Unicode Cach├⌐ ───► ASCII-8: Caché */
if \datatype(mems, 'W') then iterate /*is the "members" number not numeric? */
old.6= '??-61/52' ; new.6= "MK-61/52" /*somewhere past, a mistranslated: MK- */
old #.70= Uyir#.0 + mems ; new.7= 'Uyir' /*Unicode ───►/*bump ASCII─8:the number Uyirof members found. */
if u.?\==0 then do; do f=1 for # until ?==@u.f
end /*f*/
#.f= #.f + mems; iterate j /*languages in different cases.*/
end /* [↑] handle any possible duplicates.*/
u.?= u.? + 1; #= # + 1 /*bump a couple of counters. */
#.#= #.# + mems; @.#= cat.j; @u.#=? /*bump the counter; assign it (upper).*/
end /*j*/
 
!.=; do recs @tno=0 '(total) number of' while lines(inFID)\==0 /*read a file, aarray singleholds lineindication atof aTIED timelangs.*/
call tell right(commas(#), 9) @tno 'languages detected in the category file'
$=translate( linein(inFID), , '9'x) /*handle any stray TAB ('09'x) chars.*/
call tell right(commas(langs),9) ' " " " " " " " language "
$$=space($); if $$=='' then iterate /*ignore all blank lines in the file(s)*/
call tell right(commas(#.0), 9) @tno 'entries (solutions) detected', , 1; term= 0
do v=1 while old.v\=='' /*translate Unicode variations of langs*/
return /*don't show any more msgs──►term. [↑] */
if pos(old.v, $$) \==0 then $$=changestr(old.v, $$, new.v)
/*──────────────────────────────────────────────────────────────────────────────────────*/
end /*v*/ /* [↑] handle different lang spellings*/
init: sep= '█'; L.=0; #.=0; u.=#.; catHeap=; term=1; old.= /*assign some REXX vars*/
if igAst then do; igAst=pos(' * ',$)==0; if igAst then iterate; end
if catFID=='' then catFID= "RC_POP.CAT" /*Not specified? Then use the default.*/
if pos('RETRIEVED FROM',translate($$))\==0 then leave /*a pseudo End-Of-Data?*/
if whichlanFID=='L' then dolanFID= "RC_POP.LAN" /* " " " " " " */
if outFID=='' then outFID= "RC_POP.OUT" /* " " if" left($$, 1)\=='*' " then iterate " " /*lang not legitimate?*/
call tell center('timestamp: ' date() time("Civil"),79,'═'), 2, 1; return
parse upper var $$ '*' $$ "<"; $$=space($$); L.$$=1
/*──────────────────────────────────────────────────────────────────────────────────────*/
langs=langs + 1 /*bump the number of languages found. */
out: w= length( commas(#) ); rank= iterate 0 /*iterates the[↓] show by ascending rank DOof recs looplang. */
do t=# by -1 for #; rank= rank + end 1 /*bump [↓]rank of picka off theprogramming language name. */
ifcall lefttell right($$'rank:' right(commas(!tR.t), w), 20-1)=='*' then $$=sep || space( substrright($$!.t, 2) 7),
catHeap=catHeap $$ right('('commas(#.t) left("entr"s(#.t, 'ies', "y")')', 9), /*append to the catHeap (CATegory20) heap*/ @.t
end /*recs#*/ /* [↑] S(···) pluralizes a word. */
call tell left('', 27) "☼ end─of─list. ☼", 1, 2; return /*bottom title.*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
rdr: arg which 2; igAst= 1 /*ARG uppers WHICH, obtain the 1st char*/
if which=='L' then inFID= lanFID /*use this fileID for the languages. */
if which=='C' then inFID= catFID /* " " " " " categories. */
Uyir= 'உயிர்/Uyir' /*Unicode (in text) name for Uyir */
old.0= '╬£C++' ; new.0= "µC++" /*Unicode ╬£C++ ───► ASCII─8: µC++ */
old.1= 'UC++' ; new.1= "µC++" /*old UC++ ───► ASCII─8: µC++ */
old.2= '╨£╨Ü-' ; new.2= "MK-" /*Unicode ╨£╨Ü─ ───► ASCII-8: MK- */
old.3= 'D├⌐j├á' ; new.3= "Déjà" /*Unicode ├⌐j├á ───► ASCII─8: Déjà */
old.4= 'Cach├⌐' ; new.4= "Caché" /*Unicode Cach├⌐ ───► ASCII─8: Caché */
old.5= '??-61/52' ; new.5= "MK-61/52" /*somewhere past, a mis─translated: MK-*/
old.6= 'F┼ìrmul├ª' ; new.6= 'Fôrmulæ' /*Unicode ───► ASCII─8: Fôrmulæ */
old.7= '╨£iniZinc' ; new.7= 'MiniZinc' /*Unicode ───► ASCII─8: MiniZinc*/
old.8= Uyir ; new.8= 'Uyir' /*Unicode ───► ASCII─8: Uyir */
old.9= 'Perl 6' ; new.9= 'Raku' /* (old name) ───► (new name) */
 
calldo recs=0 tell while right( commaslines(recsinFID), 9)\== 0 'records /*read froma file:, 'a single line at a inFIDtime.*/
$= translate( linein(inFID), , '9'x) /*handle any stray TAB ('09'x) chars.*/
return
$$= space($); if $$=='' then iterate /*ignore all blank lines in the file(s)*/
do v=0 while old.v \== '' /*translate Unicode variations of langs*/
if pos(old.v, $$) \==0 then $$= changestr(old.v, $$, new.v)
end /*v*/ /* [↑] handle different lang spellings*/
if igAst then do; igAst= pos(' * ', $)==0; if igAst then iterate; end
if pos('RETRIEVED FROM', translate($$))\==0 then leave /*pseudo End─Of─Data?.*/
if which=='L' then do; if left($$, 1)\=="*" then iterate /*lang ¬legitimate?*/
parse upper var $$ '*' $$ "<"; $$= space($$)
if $$=='' then iterate; L.$$= 1
langs= langs + 1 /*bump number of languages found. */
iterate
end /* [↓] extract computer language name.*/
if left($$, 1)=='*' then $$= sep || space( substr($$, 2) )
catHeap= catHeap $$ /*append to the catHeap (CATegory) heap*/
end /*recs*/
call tell right( commas(recs), 9) 'records read from file: ' inFID
return
/*──────────────────────────────────────────────────────────────────────────────────────*/
stell: if arg(1)==1 then returndo '0'arg(32); call lineout outFID," return" ; if term then say ; word(arg(2) 's',1) /*pluralizer.*/end
call lineout outFID,arg(1) ; if term then say arg(1)
do '0'arg(3); call lineout outFID," " ; if term then say ; end
return /*show BEFORE blank lines (if any), message, show AFTER blank lines.*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
telltSort: tied=; do '0'arg(2); call lineout outFID," " ; say r= 0 /*add true rank ;(tR) ───► the entries. end*/
do j=# by -1 for #; r= r+1; tR= r; call lineout!tR.j= outFID,arg(1)r; jp= j+1; sayjm= arg(j-1)
if do tied=='0'arg(3); call lineout outFID," " then pR= r; tied= say /*handle when language rank is untied. ; end*/
if #.j==#.jp | #.j==#.jm then do; !.j= '[tied]'; tied= !.j; end
return /*show BEFORE blank lines (if any), message, show AFTER blank lines.*/</lang>
if #.j==#.jp then do; tR= pR; !tR.j= pR; end
Some older REXXes don't have a &nbsp; '''changestr''' &nbsp; BIF, &nbsp; so one is included here: &nbsp; ───► &nbsp; [[CHANGESTR.REX]].
else pR= r
<br><br>
end /*j*/; return</syntaxhighlight>
 
===all ranked 651813 languages===
The '''output''' &nbsp; for this REXX (RC_POP.REX) program is included here &nbsp; ──► &nbsp; [[RC_POP.OUT]].
 
[See the talk page about some programming languages using different cases (lower/upper/mixed) for the language names, &nbsp; as well as those that use Unicode characters in the name.]
 
[See the talk page about some programming languages using different cases (lower/upper/mixed) for the language names,
[Note: the timestamp reflects the local time which is USA &nbsp; CST or CDT &nbsp; ('''C'''entral '''S'''tandard '''T'''ime &nbsp; or &nbsp; '''C'''entral '''D'''aylight '''T'''ime).
<br>as well as those that use Unicode characters in the name.] <br><br><br>
<br><br>
 
=={{header|Ring}}==
<syntaxhighlight lang="ring">
# Project: Rosetta Code/Rank languages by popularity
load "stdlib.ring"
ros= download("http://rosettacode.org/wiki/Category:Programming_Languages")
pos = 1
totalros = 0
rosname = ""
rosnameold = ""
rostitle = ""
roslist = []
for n = 1 to len(ros)
nr = searchstring(ros,'<li><a href="/wiki/',pos)
if nr = 0
exit
else
pos = nr + 1
ok
nr = searchname(nr)
nr = searchtitle(nr)
next
roslist = sortfirst(roslist)
roslist = reverse(roslist)
 
see nl
for n = 1 to len(roslist)
see "rank: " + n + " (" + roslist[n][1] + " entries) " + roslist[n][2] + nl
next
 
func searchstring(str,substr,n)
newstr=right(str,len(str)-n+1)
nr = substr(newstr, substr)
if nr = 0
return 0
else
return n + nr -1
ok
func count(cstring,dstring)
sum = 0
while substr(cstring,dstring) > 0
sum = sum + 1
cstring = substr(cstring,substr(cstring,dstring)+len(string(sum)))
end
return sum
 
func searchname(sn)
nr2 = searchstring(ros,"/wiki/Category:",sn)
nr3 = searchstring(ros,"title=",sn)
nr4 = searchstring(ros,'">',sn)
nr5 = searchstring(ros,"</a></li>",sn)
rosname = substr(ros,nr2+15,nr3-nr2-17)
rosnameold = substr(ros,nr4+2,nr5-nr4-2)
return sn
func searchtitle(sn)
rostitle = "rosettacode.org/wiki/Category:" + rosname
rostitle = download(rostitle)
nr2 = 0
roscount = count(rostitle,"The following")
if roscount > 0
rp = 1
for rc = 1 to roscount
nr2 = searchstring(rostitle,"The following",rp)
rp = nr2 + 1
next
ok
nr3 = searchstring(rostitle,"pages are in this category",nr2)
if nr2 > 0 and nr3 > 0
rosnr = substr(rostitle,nr2+14,nr3-nr2-15)
rosnr = substr(rosnr,",","")
add(roslist,[rosnr,rosnameold])
ok
return sn
func sortfirst(alist)
for n = 1 to len(alist) - 1
for m = n + 1 to len(alist)
if alist[m][1] < alist[n][1]
swap(alist,m,n)
ok
if alist[m][1] = alist[n][1] and strcmp(alist[m][2],alist[n][2]) > 0
swap(alist,m,n)
ok
next
next
return alist
</syntaxhighlight>
Output:
<pre>
rank: 1 (1010 entries) Kotlin
rank: 2 (977 entries) Racket
rank: 3 (968 entries) Python
rank: 4 (962 entries) Perl 6
rank: 5 (931 entries) Go
rank: 6 (914 entries) Tcl
rank: 7 (905 entries) C
rank: 8 (888 entries) J
rank: 9 (882 entries) Zkl
rank: 10 (875 entries) Java
......
rank: 30 (580 entries) Ring
......
rank: 523 (2 entries) TechBASIC
rank: 524 (2 entries) Thyrd
rank: 525 (2 entries) ToffeeScript
rank: 526 (2 entries) Viua VM assembly
rank: 527 (2 entries) XL
rank: 528 (2 entries) XProc
rank: 529 (2 entries) XSLT 1.0
rank: 530 (2 entries) XTalk
rank: 531 (2 entries) XUL
rank: 532 (2 entries) ZPL
</pre>
 
=={{header|Ruby}}==
Line 3,963 ⟶ 5,307:
 
Uses the <code>RosettaCode</code> module from [[Count programming examples#Ruby]]
<langsyntaxhighlight lang="ruby">require 'rosettacode'
 
langs = []
Line 3,992 ⟶ 5,336:
langcount.sort_by {|key,val| val}.reverse[0,25].each_with_index do |(lang, count), i|
puts "#{i+1}. #{count} - #{lang.sub(/Category:/, '')}"
end</langsyntaxhighlight>
{{out|Results}}
<pre style="height: 40ex; overflow: scroll">2010-07-08 14:52:46 -0500
Line 4,024 ⟶ 5,368:
 
=={{header|Run BASIC}}==
<langsyntaxhighlight lang="runbasic">sqliteconnect #mem, ":memory:" ' make memory DB
#mem execute("CREATE TABLE stats(lang,cnt)")
a$ = httpGet$("http://rosettacode.org/wiki/Category:Programming_Languages")
Line 4,051 ⟶ 5,395:
html "<TR><TD align=right>";rank;"</td><td>";#row lang$();"</td><td align=right>";#row cnt();"</td></tr>"
WEND
html "</table>"</langsyntaxhighlight>
<table border=2>
<TR><TD align=right>1</td><td>Tcl</td><td align=right>687</td></tr>
Line 4,087 ⟶ 5,431:
===Parallel internet querying===
Entry point @ object <code>GhettoParserPar</code>
<langsyntaxhighlight lang="scala">import akka.actor.{Actor, ActorSystem, Props}
import scala.collection.immutable.TreeSet
import scala.xml.XML
Line 4,231 ⟶ 5,575:
Concurrent.logInfo("Parallel version started")
ActorSystem("Main").actorOf(Props[Concurrent.Listener])
}</langsyntaxhighlight>
 
===Sequential internet querying===
Line 4,302 ⟶ 5,646:
 
=={{header|Seed7}}==
<langsyntaxhighlight lang="seed7">$ include "seed7_05.s7i";
include "gethttp.s7i";
include "scanstri.s7i";
Line 4,359 ⟶ 5,703:
place +:= length(ranking[numList[listIdx]]);
end for;
end func;</langsyntaxhighlight>
 
List of languages as of 2014-01-15:
Line 4,398 ⟶ 5,742:
=={{header|Sidef}}==
{{trans|Perl}}
<langsyntaxhighlight lang="ruby">require('MediaWiki::API')
 
var api = %O<MediaWiki::API>.new(
Line 4,434 ⟶ 5,778:
sorted_languages.each_kv { |i, lang|
printf("%3d. %20s - %3d\n", i+1, lang{:title}, lang{:categoryinfo}{:size})
}</langsyntaxhighlight>
{{out}}
<pre>
Line 4,459 ⟶ 5,803:
=={{header|SNOBOL4}}==
{{Works with|SNOBOL4|CSNOBOL4 CVS test}}
<langsyntaxhighlight SNOBOL4lang="snobol4">-include "url.sno"
http.recl = "K,32767" ;* Read next 32767 characters
;* of very long lines.
Line 4,478 ⟶ 5,822:
read line = line fin :f(done)
get line languagepat = :f(read)
langtable<syntaxhighlight lang="text"> = langtable<syntaxhighlight lang="text"> + count :(get)
done langarray = rsort(langtable,2) :s(write)
Line 4,488 ⟶ 5,832:
url.close(.fin)
end</langsyntaxhighlight>
 
'''Abridged output (top 30 languages as of August 25, 2015):'''
Line 4,527 ⟶ 5,871:
First we build the database:
 
<langsyntaxhighlight lang="stata">copy "http://rosettacode.org/wiki/Category:Programming_Languages" lang.html, replace
import delimited lang.html, delim("@") enc("utf-8") clear
keep if ustrpos(v1,"/wiki/Category:")
Line 4,561 ⟶ 5,905:
gen rank=1
replace rank=rank[_n-1]+(count[_n]!=count[_n-1]) in 2/l
save tasks, replace</langsyntaxhighlight>
 
Now some results, as of 2017-12-03:
 
<langsyntaxhighlight lang="stata">* Total number of entries
qui sum n
di r(sum)
Line 4,595 ⟶ 5,939:
| Ruby 845 9 |
| Go 828 10 |
+-----------------------+</langsyntaxhighlight>
 
=={{header|Tcl}}==
===By web scraping===
<langsyntaxhighlight lang="tcl">package require Tcl 8.5
package require http
Line 4,638 ⟶ 5,982:
lassign $entry num lang
puts [format "%d. %d - %s" [incr i] $num $lang]
}</langsyntaxhighlight>
{{out|Output on 29 July 2015 (top 20 entries only)}}
<pre>1. 887 - Tcl
Line 4,667 ⟶ 6,011:
{{libheader|tDOM}}
 
<langsyntaxhighlight lang="tcl">package require Tcl 8.5
package require http
package require tdom
Line 4,776 ⟶ 6,120:
}
 
popreport $langcounts</langsyntaxhighlight>
 
{{out}}
Line 4,802 ⟶ 6,146:
 
=={{header|TUSCRIPT}}==
<langsyntaxhighlight lang="tuscript">$$ MODE TUSCRIPT
remotedata = REQUEST ("http://www.rosettacode.org/mw/index.php?title=Special:Categories&limit=5000")
allmembers=allnames=""
Line 4,850 ⟶ 6,194:
balt=b
ENDLOOP
ENDCOMPILE</langsyntaxhighlight>
{{out}}
<pre style='height:30ex;overflow:scroll'>
Line 4,895 ⟶ 6,239:
 
{{libheader|curl}}
<langsyntaxhighlight lang="bash">curl 'http://rosettacode.org/mw/index.php?title=Special:Categories&limit=5000' |
sed -nre 's/^<li.*title="Category:([^"(]+)".*\(([0-9]+) members\).*/\2 - \1/p' |
sort -nr | awk '{printf "%2d. %s\n",NR,$0}'</langsyntaxhighlight>
 
=={{header|VBScript}}==
Uses the API. Instead of displaying it on the command prompt, the records of the languages are saved on a text file "OutVBRC.txt" encoded with Unicode.
<langsyntaxhighlight lang="vb"> '''''''''''''''''''''''''''''''''''''''''''''
' Rosetta Code/Rank Languages by Popularity '
' VBScript Implementation '
Line 5,018 ⟶ 6,362:
Set HTML = Nothing
Set objFSO = Nothing
WScript.Quit(0)</langsyntaxhighlight>
{{Out|Some Parts of Output as of December 31, 2016}}
<pre>As of 12/31/2016 11:52:05 PM, RC has 624 languages.
Line 5,048 ⟶ 6,392:
0 Examples - WML
0 Examples - VAX Assembly</pre>
 
=={{header|Visual Basic .NET}}==
Uses Web scrapping to get the information from the Languages category page - as this now shows the number of pages in each category with the non-task pages separated, there is no need to access other pages.<br>
It may be necessary to set the Security Protocol to Tls12 at the start of the Main method in order to run this - see the "Problem running the C# entry" section on the [[Talk:Rosetta Code/Count examples]] page.
<syntaxhighlight lang="vbnet">
Imports System.Collections
Imports System.Collections.Generic
Imports System.Net
Imports System.Text.RegularExpressions
 
Module RankLanguagesByPopularity
 
Private Class LanguageStat
Public name As String
Public count As Integer
Public Sub New(name As String, count As Integer)
Me.name = name
Me.count = count
End Sub
End Class
 
Private Function CompareLanguages(x As LanguageStat, y As languageStat) As Integer
Dim result As Integer = 0
If x IsNot Nothing Or y IsNot Nothing Then
If x Is Nothing Then
result = -1
ElseIf y Is Nothing
result = 1
Else
result = - x.count.CompareTo(y.count) ' Sort descending count
If result = 0 Then
result = x.name.CompareTo(y.name) ' Sort ascending name
End If
End If
End If
Return result
End Function
 
Public Sub Main(ByVal args As String())
 
Dim languages As New List(Of LanguageStat)
Dim basePage As String = "https://rosettacode.org/wiki/Category:Programming_Languages"
Dim nextPage As String = basePage
 
Dim nextPageEx = New RegEx("<a href=""/wiki/Category:Programming_Languages([?]subcatfrom=[^""]*)""")
Dim languageStatEx = _
New Regex(">([^<]+?)</a>[^<]*<span title=""Contains *[0-9,.]* *[a-z]*, *([0-9,.]*) *page")
 
Do While nextPage <> ""
Dim wc As New WebClient()
Dim page As String = wc.DownloadString(nextPage)
 
nextPage = ""
For Each link In nextPageEx.Matches(page)
nextPage = basePage & link.Groups(1).Value
Next link
 
For Each language In languageStatEx.Matches(page)
Dim lCount As Integer = 0
Dim lName As String = language.Groups(1).Value
Dim countText As String = language.Groups(2).Value.Replace(",", "").Replace(".", "")
If Not Integer.TryParse(countText, lCount)
Console.Out.WriteLine(lName & "Invalid page count: <<" & countText & ">>")
Else
languages.Add(New LanguageStat(lName, lCount))
End If
Next language
Loop
 
languages.Sort(AddressOf CompareLanguages)
 
Dim prevCount As Integer = -1
Dim prevPosition As Integer = -1
Dim position As Integer = 0
For Each stat As LanguageStat In languages
position += 1
If stat.count <> prevCount Then
prevPosition = position
prevCount = stat.Count
End If
Console.Out.WriteLine(prevPosition.ToString.PadLeft(4) & ": " &
stat.count.ToString.PadLeft(4) & " " & stat.name)
Next stat
 
End Sub
 
End Module
</syntaxhighlight>
{{out}}
Sample output as at 11th September 2023
<pre>
1: 1652 Phix
1: 1652 Wren
3: 1614 Julia
4: 1595 Raku
5: 1576 Nim
6: 1546 Go
7: 1531 Perl
8: 1470 Python
9: 1375 J
10: 1285 C
. . .
</pre>
 
=={{header|Wren}}==
{{libheader|libcurl}}
{{libheader|Wren-pattern}}
{{libheader|Wren-fmt}}
An embedded program so we can use libcurl.
<syntaxhighlight lang="wren">/* Rosetta_Code_Rank_languages_by_popularity.wren */
 
import "./pattern" for Pattern
import "./fmt" for Fmt
 
var CURLOPT_URL = 10002
var CURLOPT_FOLLOWLOCATION = 52
var CURLOPT_WRITEFUNCTION = 20011
var CURLOPT_WRITEDATA = 10001
 
foreign class Buffer {
construct new() {} // C will allocate buffer of a suitable size
 
foreign value // returns buffer contents as a string
}
 
foreign class Curl {
construct easyInit() {}
 
foreign easySetOpt(opt, param)
 
foreign easyPerform()
 
foreign easyCleanup()
}
 
var curl = Curl.easyInit()
 
var getContent = Fn.new { |url|
var buffer = Buffer.new()
curl.easySetOpt(CURLOPT_URL, url)
curl.easySetOpt(CURLOPT_FOLLOWLOCATION, 1)
curl.easySetOpt(CURLOPT_WRITEFUNCTION, 0) // write function to be supplied by C
curl.easySetOpt(CURLOPT_WRITEDATA, buffer)
curl.easyPerform()
return buffer.value
}
 
var p1 = Pattern.new("> <a href/=\"//wiki//Category:+1^\"\" title/=\"Category:[+1^\"]\">+1^,, [+1^ ] page")
var p2 = Pattern.new("subcatfrom/=[+1^#/#mw-subcategories]\"")
 
var findLangs = Fn.new {
var url = "https://rosettacode.org/w/index.php?title=Category:Programming_Languages"
var subcatfrom = ""
var langs = []
while (true) {
var content = getContent.call(url + subcatfrom)
var matches1 = p1.findAll(content)
for (m in matches1) {
var name = m.capsText[0]
var tasks = Num.fromString(m.capsText[1].replace(",", ""))
langs.add([name, tasks])
}
var m2 = p2.find(content)
if (m2) subcatfrom = "&subcatfrom=%(m2.capsText[0])" else break
}
return langs
}
 
var langs = findLangs.call()
langs.sort { |a, b| a[1] > b[1] }
System.print("Languages with most examples as at 3 February, 2024:")
var rank = 0
var lastScore = 0
var lastRank = 0
for (i in 0...langs.count) {
var pair = langs[i]
var eq = " "
rank = i + 1
if (lastScore == pair[1]) {
eq = "="
rank = lastRank
} else {
lastScore = pair[1]
lastRank = rank
}
Fmt.print("$-3d$s $-20s $,5d", rank, eq, pair[0], pair[1])
}</syntaxhighlight>
<br>
We now embed this script in the following C program, build and run.
<syntaxhighlight lang="c">/* gcc Rosetta_Code_Rank_languages_by_popularity.c -o Rosetta_Code_Rank_languages_by_popularity -lcurl -lwren -lm */
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <curl/curl.h>
#include "wren.h"
 
struct MemoryStruct {
char *memory;
size_t size;
};
 
/* C <=> Wren interface functions */
 
static size_t WriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp) {
size_t realsize = size * nmemb;
struct MemoryStruct *mem = (struct MemoryStruct *)userp;
char *ptr = realloc(mem->memory, mem->size + realsize + 1);
if(!ptr) {
/* out of memory! */
printf("not enough memory (realloc returned NULL)\n");
return 0;
}
 
mem->memory = ptr;
memcpy(&(mem->memory[mem->size]), contents, realsize);
mem->size += realsize;
mem->memory[mem->size] = 0;
return realsize;
}
 
void C_bufferAllocate(WrenVM* vm) {
struct MemoryStruct *ms = (struct MemoryStruct *)wrenSetSlotNewForeign(vm, 0, 0, sizeof(struct MemoryStruct));
ms->memory = malloc(1);
ms->size = 0;
}
 
void C_bufferFinalize(void* data) {
struct MemoryStruct *ms = (struct MemoryStruct *)data;
free(ms->memory);
}
 
void C_curlAllocate(WrenVM* vm) {
CURL** pcurl = (CURL**)wrenSetSlotNewForeign(vm, 0, 0, sizeof(CURL*));
*pcurl = curl_easy_init();
}
 
void C_value(WrenVM* vm) {
struct MemoryStruct *ms = (struct MemoryStruct *)wrenGetSlotForeign(vm, 0);
wrenSetSlotString(vm, 0, ms->memory);
}
 
void C_easyPerform(WrenVM* vm) {
CURL* curl = *(CURL**)wrenGetSlotForeign(vm, 0);
curl_easy_perform(curl);
}
 
void C_easyCleanup(WrenVM* vm) {
CURL* curl = *(CURL**)wrenGetSlotForeign(vm, 0);
curl_easy_cleanup(curl);
}
 
void C_easySetOpt(WrenVM* vm) {
CURL* curl = *(CURL**)wrenGetSlotForeign(vm, 0);
CURLoption opt = (CURLoption)wrenGetSlotDouble(vm, 1);
if (opt < 10000) {
long lparam = (long)wrenGetSlotDouble(vm, 2);
curl_easy_setopt(curl, opt, lparam);
} else if (opt < 20000) {
if (opt == CURLOPT_WRITEDATA) {
struct MemoryStruct *ms = (struct MemoryStruct *)wrenGetSlotForeign(vm, 2);
curl_easy_setopt(curl, opt, (void *)ms);
} else if (opt == CURLOPT_URL) {
const char *url = wrenGetSlotString(vm, 2);
curl_easy_setopt(curl, opt, url);
}
} else if (opt < 30000) {
if (opt == CURLOPT_WRITEFUNCTION) {
curl_easy_setopt(curl, opt, &WriteMemoryCallback);
}
}
}
 
WrenForeignClassMethods bindForeignClass(WrenVM* vm, const char* module, const char* className) {
WrenForeignClassMethods methods;
methods.allocate = NULL;
methods.finalize = NULL;
if (strcmp(module, "main") == 0) {
if (strcmp(className, "Buffer") == 0) {
methods.allocate = C_bufferAllocate;
methods.finalize = C_bufferFinalize;
} else if (strcmp(className, "Curl") == 0) {
methods.allocate = C_curlAllocate;
}
}
return methods;
}
 
WrenForeignMethodFn bindForeignMethod(
WrenVM* vm,
const char* module,
const char* className,
bool isStatic,
const char* signature) {
if (strcmp(module, "main") == 0) {
if (strcmp(className, "Buffer") == 0) {
if (!isStatic && strcmp(signature, "value") == 0) return C_value;
} else if (strcmp(className, "Curl") == 0) {
if (!isStatic && strcmp(signature, "easySetOpt(_,_)") == 0) return C_easySetOpt;
if (!isStatic && strcmp(signature, "easyPerform()") == 0) return C_easyPerform;
if (!isStatic && strcmp(signature, "easyCleanup()") == 0) return C_easyCleanup;
}
}
return NULL;
}
 
static void writeFn(WrenVM* vm, const char* text) {
printf("%s", text);
}
 
void errorFn(WrenVM* vm, WrenErrorType errorType, const char* module, const int line, const char* msg) {
switch (errorType) {
case WREN_ERROR_COMPILE:
printf("[%s line %d] [Error] %s\n", module, line, msg);
break;
case WREN_ERROR_STACK_TRACE:
printf("[%s line %d] in %s\n", module, line, msg);
break;
case WREN_ERROR_RUNTIME:
printf("[Runtime Error] %s\n", msg);
break;
}
}
 
char *readFile(const char *fileName) {
FILE *f = fopen(fileName, "r");
fseek(f, 0, SEEK_END);
long fsize = ftell(f);
rewind(f);
char *script = malloc(fsize + 1);
fread(script, 1, fsize, f);
fclose(f);
script[fsize] = 0;
return script;
}
 
static void loadModuleComplete(WrenVM* vm, const char* module, WrenLoadModuleResult result) {
if( result.source) free((void*)result.source);
}
 
WrenLoadModuleResult loadModule(WrenVM* vm, const char* name) {
WrenLoadModuleResult result = {0};
if (strcmp(name, "random") != 0 && strcmp(name, "meta") != 0) {
result.onComplete = loadModuleComplete;
char fullName[strlen(name) + 6];
strcpy(fullName, name);
strcat(fullName, ".wren");
result.source = readFile(fullName);
}
return result;
}
 
int main(int argc, char **argv) {
WrenConfiguration config;
wrenInitConfiguration(&config);
config.writeFn = &writeFn;
config.errorFn = &errorFn;
config.bindForeignClassFn = &bindForeignClass;
config.bindForeignMethodFn = &bindForeignMethod;
config.loadModuleFn = &loadModule;
WrenVM* vm = wrenNewVM(&config);
const char* module = "main";
const char* fileName = "Rosetta_Code_Rank_languages_by_popularity.wren";
char *script = readFile(fileName);
WrenInterpretResult result = wrenInterpret(vm, module, script);
switch (result) {
case WREN_RESULT_COMPILE_ERROR:
printf("Compile Error!\n");
break;
case WREN_RESULT_RUNTIME_ERROR:
printf("Runtime Error!\n");
break;
case WREN_RESULT_SUCCESS:
break;
}
wrenFreeVM(vm);
free(script);
return 0;
}</syntaxhighlight>
 
{{out}}
Showing just the top thirty.
<pre>
Languages with most examples as at 3 February, 2024:
1 Wren 1,665
1 = Phix 1,665
3 Julia 1,638
4 Raku 1,608
5 Nim 1,576
6 Go 1,547
7 Perl 1,540
8 Python 1,497
9 J 1,413
10 Java 1,318
11 C 1,293
12 C++ 1,258
13 Ruby 1,235
14 Mathematica 1,200
15 FreeBASIC 1,185
16 Haskell 1,166
17 REXX 1,152
18 Kotlin 1,143
19 Racket 1,099
20 Jq 1,081
21 Sidef 1,051
22 11l 1,016
23 Zkl 1,011
24 Factor 1,001
25 D 990
26 ALGOL 68 986
27 Tcl 983
28 Scala 948
29 Delphi 945
30 Ada 940
30 = Rust 940
</pre>
 
=={{header|zkl}}==
Line 5,054 ⟶ 6,815:
This solution using the API as the web scraping URL is pretty slow.
I'm using JSON as format=txt has been deprecated.
<langsyntaxhighlight lang="zkl">var [const] CURL=Import("zklCurl"), YAJL=Import("zklYAJL")[0];
 
fcn getLangCounts(language){ // -->( (count,lang), ...)
Line 5,091 ⟶ 6,852:
println("Most popular Rosetta Code languages as of ",Time.Date.prettyDay());
foreach n,name in ([1..15].zip(langCounts))
{ println("%2d: %3d %s".fmt(n,name.xplode())) }</langsyntaxhighlight>
{{out}}
<pre>
153

edits