Rosetta Code/Rank languages by popularity: Difference between revisions

m (updated the number of computer programming languages on Rosetta Code.)
(312 intermediate revisions by 17 users not shown)
Line 8:
Sort the most popular computer programming languages based in number of members in Rosetta Code categories.
 
Sample output on 02 August 2022 at 09:50 +02
 
<pre>Rank: 1 (1,565 entries) Phix
Sample output on 26 April 2019:
Rank: 2 (1,558 entries) Wren
<pre>
rankRank: 1 3 (1,138531 entries) GoJulia
rankRank: 2 4 (1,075507 entries) Perl 6Raku
rankRank: 3 5 (1,054500 entries) PythonGo
rankRank: 4 6 (1,042466 entries) KotlinPerl
rankRank: 5 7 (1,008409 entries) PerlPython
rankRank: 6 [tied] 8 (9991,402 entries) JuliaNim
rankRank: 6 [tied] 9 (9991,254 entries) PhixJ
rankRank: 8 10 (9891,211 entries) RacketC
rank: 9 (949 entries) C
rank: 10 (934 entries) J
...</pre>
 
Line 30 ⟶ 28:
* &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 '''<span{{PAGESINCAT:Programming title="AS OF 2019-05-12">729</span>Languages}}''' [http[://www.rosettacode.org/wiki/Category:Programming_LanguagesProgramming Languages|programming languages]], updated periodically, ''typically weekly''.
* &nbsp; A complete ranked listing of all &nbsp; '''706813''' &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 125 ⟶ 123:
Counts.Reverse_Iterate (Display'Access);
end Test;
</syntaxhighlight>
</lang>
 
=={{header|ALGOL 68}}==
Line 137 ⟶ 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 260 ⟶ 258:
printf(($g(-0)". "g(-0)" - "gl$,i,stats[i]))
OD
FI</langsyntaxhighlight>
{{out|Sample output}}
<pre>
Line 276 ⟶ 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 433 ⟶ 431:
lasttied := tied
FI
OD</langsyntaxhighlight>
{{out|Sample output top 10}}
<pre>
Line 453 ⟶ 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 538 ⟶ 536:
GuiClose:
ExitApp
return</langsyntaxhighlight>
 
=={{header|AWK}}==
Line 545 ⟶ 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 628 ⟶ 626:
print ++i ". " language " - " G[language]
 
}</langsyntaxhighlight>
{{out|Output from 26 May 2015}}
<pre>1. Tcl - 867
Line 648 ⟶ 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 737 ⟶ 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 777 ⟶ 775:
 
=={{header|Bracmat}}==
<langsyntaxhighlight lang="bracmat"> ( get-page
= url type
. !arg:(?url.?type)
Line 867 ⟶ 865:
)
)
& ;</langsyntaxhighlight>
Output:
<pre> 1. 816 - Tcl
Line 918 ⟶ 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 994 ⟶ 992:
 
return 0;
}</langsyntaxhighlight>
{{out}}
<pre> 563 Tcl
Line 1,014 ⟶ 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,162 ⟶ 1,160:
} while (sorted!=1);
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,178 ⟶ 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,190 ⟶ 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,205 ⟶ 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,215 ⟶ 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,287 ⟶ 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,369 ⟶ 1,394:
}
return 0 ;
}</langsyntaxhighlight>
{{out|Sample output (just the "top ten")}}
1. 367 - Tcl
Line 1,384 ⟶ 1,409:
=={{header|Caché ObjectScript}}==
 
<langsyntaxhighlight lang="cos">Class Utils.Net.RosettaCode [ Abstract ]
{
 
Line 1,463 ⟶ 1,488:
}
 
}</langsyntaxhighlight>
{{out|Example}}
<pre>
Line 1,482 ⟶ 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,501 ⟶ 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,523 ⟶ 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,586 ⟶ 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,613 ⟶ 1,810:
 
=={{header|F_Sharp|F#}}==
<langsyntaxhighlight lang="fsharp">open System
open System.Text.RegularExpressions
Line 1,665 ⟶ 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,690 ⟶ 1,887:
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import (
Line 1,804 ⟶ 2,001:
fmt.Printf("%3d. %3d - %s\n", lastIdx, lang.int, lang.string)
}
}</langsyntaxhighlight>
{{out|Output on 11 Aug 2014}}
<pre>
Line 1,822 ⟶ 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,830 ⟶ 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,845 ⟶ 2,042:
===Haskell: Using the API===
 
<langsyntaxhighlight lang="haskell">{-# LANGUAGE OverloadedStrings #-}
 
import Data.Aeson
Line 1,946 ⟶ 2,143:
 
main :: IO ()
main = runQuery [] queryStr</langsyntaxhighlight>
{{out}}
(As of 2015-07-29.) Here we show only the top 30.
Line 1,984 ⟶ 2,181:
 
Scraping the languages and categories pages.
<langsyntaxhighlight lang="haskell">import Network.Browser
import Network.HTTP
import Network.URI
Line 2,018 ⟶ 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,043 ⟶ 2,240:
 
=={{header|HicEst}}==
<langsyntaxhighlight lang="hicest">CHARACTER cats*50000, catlist*50000, sortedCat*50000, sample*100
DIMENSION RankNr(1)
 
Line 2,075 ⟶ 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,087 ⟶ 2,284:
8. 298 Perl
9. 288 WikiStubs
10. 281 Common Lisp</langsyntaxhighlight>
 
=={{header|Icon}} and {{header|Unicon}}==
Line 2,093 ⟶ 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,141 ⟶ 2,338:
close(page)
return text
end</langsyntaxhighlight>
 
Abridged output (top 26 languages as of July 30, 2016):
Line 2,175 ⟶ 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,194 ⟶ 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,205 ⟶ 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,340 ⟶ 2,537:
} // for lPos
} // main
} // GetRCLanguages</langsyntaxhighlight>
{{out}}
Top 10 languages as at 27th August 2015
Line 2,357 ⟶ 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,406 ⟶ 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,430 ⟶ 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.
<lang julia>using HTTP
<syntaxhighlight lang="julia">""" Rosetta code task rosettacode.org/wiki/Rosetta_Code/Rank_languages_by_popularity """
 
using Dates
try
using DataFrames
response = HTTP.request("GET", "http://rosettacode.org/mw/index.php?title=Special:Categories&limit=5000")
using HTTP
langcount = Dict{String, Int}()
using JSON3
for mat in eachmatch(r"<li><a href[^\>]+>([^\<]+)</a>[^1-9]+(\d+)[^\w]+member.?.?</li>", String(response.body))
 
if match(r"^Programming", mat.captures[1]) == nothing
""" Get listing of all tasks and draft tasks with authors and dates created, with the counts as popularity """
langcount[mat.captures[1]] = parse(Int, mat.captures[2])
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
 
langs = sort(collect(keys(langcount)), lt=(x, y)->langcount[x]<langcount[y], rev=true)
return sort!(df, :ExampleCount, rev = true)
for (i, lang) in enumerate(langs)
println("Language $lang can be ranked #$i at $(langcount[lang]).")
end
catch y
println("HTTP request failed: $y.")
exit()
end
 
</lang>{{out}
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
Language Phix can be ranked #1 at 995.
20×2 DataFrame
Language Racket can be ranked #2 at 989.
Row │ ProgrammingLanguage ExampleCount
Language Perl can be ranked #3 at 969.
│ String Int64
Language Julia can be ranked #4 at 968.
─────┼───────────────────────────────────
Language C can be ranked #5 at 944.
1 │ Wren 1569
Language Tcl can be ranked #6 at 930.
2 │ Phix 1569
Language Zkl can be ranked #7 at 919.
3 │ Julia 1537
Language J can be ranked #8 at 905.
4 │ Raku 1517
Language Java can be ranked #9 at 900.
5 │ Go 1496
Language REXX can be ranked #10 at 892.
6 │ Perl 1460
Language D can be ranked #11 at 874.
7 │ Python 1404
Language Ruby can be ranked #12 at 869.
8 │ Nim 1402
Language Haskell can be ranked #13 at 853.
9 │ J 1275
Language Scala can be ranked #14 at 792.
10 │ C 1210
Language Sidef can be ranked #15 at 788.
11 │ Mathematica 1178
Language PicoLisp can be ranked #16 at 775.
12 │ REXX 1149
Language C sharp can be ranked #17 at 763.
13 │ Haskell 1139
Language Mathematica can be ranked #18 at 743.
14 │ Java 1136
Language C++ can be ranked #19 at 738.
15 │ Kotlin 1133
Language Common Lisp can be ranked #20 at 667.
16 │ C++ 1120
Language Ada can be ranked #21 at 656.
17 │ Ruby 1103
Language AutoHotkey can be ranked #22 at 628.
18 │ Racket 1089
Language JavaScript can be ranked #23 at 619.
19 │ FreeBASIC 1069
Language Lua can be ranked #24 at 618.
20 │ Zkl 1011
Language WikiStubs can be ranked #25 at 614.
...
</pre>
 
=={{header|Kotlin}}==
{{trans|Java}}
<langsyntaxhighlight lang="scala">import java.net.URL
import java.io.*
 
Line 2,563 ⟶ 2,780:
}
}
}</langsyntaxhighlight>
{{out}}
<pre> 1, 901, Racket
Line 2,575 ⟶ 2,792:
 
=={{header|Lasso}}==
<langsyntaxhighlight Lassolang="lasso"><pre><code>[
sys_listtraits !>> 'xml_tree_trait' ? include('xml_tree.lasso')
local(lang = array)
Line 2,599 ⟶ 2,816:
'. '+#l->second + ' - ' + #l->first+'\r'
^}
]</code></pre></langsyntaxhighlight>
 
{{out}}
Line 2,619 ⟶ 2,836:
Update: Numbers above 999 get a comma (,) so we have to drop this using Filter$()
 
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Module RankLanguages {
Const Part1$="<a href="+""""+ "/wiki/Category", Part2$="member"
Line 2,696 ⟶ 2,913:
}
Print
\\ this type of iventoryinventory can get same keys
\\ also has stable sort
Report "Make Inventory list by Task"
Line 2,724 ⟶ 2,941:
}
RankLanguages
</syntaxhighlight>
</lang>
 
{{out}}
<pre style="height:30ex;overflow:scroll">
Sample output on MondaySaturday, NovemberJune 2622, 20182019:
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: 1. 1060 entries - Go
rank: 2. 1029 entries - Kotlin
rank: 3. 1020 entries - Python
rank: 4. 1012 entries - Perl 6
rank: 5. 979 entries - Racket
rank: 6. 938 entries - Perl
rank: 7. 929 entries - Tcl
rank: 8. 926 entries - C
rank: 9. 907 entries - Zkl
rank: 10. 900 entries - J
rank: 11. 895 entries - Phix
rank: 12. 894 entries - Java
rank: 13. 876 entries - REXX
rank: 14. 874 entries - D
rank: 15. 858 entries - Ruby
rank: 16. 849 entries - Julia
rank: 17. 848 entries - Haskell
rank: 18. 791 entries - Scala
rank: 19. 777 entries - Sidef
rank: 20. 774 entries - PicoLisp
rank: 21. 738 entries - Mathematica
rank: 22. 735 entries - C sharp
rank: 23. 707 entries - C++
rank: 24. 658 entries - Common Lisp
rank: 25. 652 entries - Ada
rank: 26. 627 entries - AutoHotkey
rank: 27. 614 entries - JavaScript
rank: 28. 604 entries - Ring
rank: 29. 601 entries - Lua
rank: 30. 590 entries - Unicon
rank: 31. 588 entries - Clojure
rank: 32. 560 entries - BBC BASIC
rank: 33. 554 entries - Fortran
rank: 34. 553 entries - PureBasic
rank: 35. 551 entries - ALGOL 68
rank: 36. 546 entries - Factor
rank: 37. 545 entries - Nim
rank: 38. 543 entries - OCaml
rank: 39. 537 entries - PARI/GP
rank: 40. 532 entries - Icon
rank: 41. 514 entries - F Sharp
rank: 42. 513 entries - Elixir
rank: 43. 490 entries - Erlang
rank: 44. 476 entries - FreeBASIC
rank: 45. 471 entries - PowerShell
rank: 46. 457 entries - Jq
rank: 47. 445 entries - Forth
rank: 48. 440 entries - Pascal
rank: 49. 431 entries - AWK
rank: 50. 425 entries - R
rank: 51. 423 entries - Rust
rank: 52. 407 entries - Seed7
rank: 53. 403 entries - PL/I
rank: 54. 399 entries - Groovy
rank: 55. 398 entries - PHP
rank: 56. 359 entries - Scheme
rank: 57. 357 entries - MATLAB
rank: 58. 343 entries - Maple
rank: 59. 334 entries - Liberty BASIC
rank: 60. 331 entries - Swift
rank: 61. 314 entries - Run BASIC
rank: 62. 308 entries - Oforth
rank: 63. 306 entries - Octave
rank: 64. 305 entries - XPL0
rank: 65. 304 entries - EchoLisp
rank: 66. 291 entries - M2000 Interpreter
rank: 67. 289 entries - Prolog
rank: 68. 289 entries - UNIX Shell
rank: 69. 288 entries - Bracmat
rank: 70. 287 entries - NetRexx
rank: 71. 280 entries - Oz
rank: 72. 273 entries - Objeck
rank: 73. 272 entries - E
rank: 74. 272 entries - VBScript
..........
rank: 685. 1 entries - WollokJacquard Loom
rank: 686. 1 entries - X86Kamailio 64 AssemblyScript
rank: 687. 1 entries - XanaduLambda Prolog
rank: 688. 1 entries - YaLibreOffice Basic
rank: 689. 01 entries - AngelScriptMAPPER
rank: 690. 01 entries - Binary Lambda CalculusMEL
rank: 691. 01 entries - EhBASICMiniZinc
rank: 692. 01 entries - EpigramMond
rank: 693. 01 entries - FLORA-2Monkey
rank: 694. 01 entries - FloridNASL
rank: 695. 01 entries - LC2200 AssemblyNeat
rank: 696. 01 entries - LeonNewtonScript
rank: 697. 01 entries - LLPNickle
rank: 698. 01 entries - Loglan82Nix
rank: 699. 01 entries - LolliOpa
rank: 700. 01 entries - LygonPare
rank: 701. 01 entries - ObjectIconQore
rank: 702. 01 entries - PL/BRapira
rank: 703. 01 entries - PlanRPGIV
rank: 704. 01 entries - ReduceSetl4
rank: 705. 01 entries - RubylogSoar
rank: 706. 01 entries - SimpleLangSoneKing Assembly
rank: 707. 01 entries - SpinSupernova
rank: 708. 01 entries - StarSuperTalk
rank: 709. 01 entries - X10Terra
rank: 710. 01 entries - XSTestML
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}}==
<langsyntaxhighlight Maplelang="maple">count_sizes := proc(arr_name,arr_pop,i,lst)
local index := i;
local language;
Line 2,864 ⟶ 3,101:
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:</langsyntaxhighlight>
{{Out|Output}}
<pre>#10:30 AM 10/05/2018
Line 2,885 ⟶ 3,122:
rank 685 0 examples Loglan82</pre>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="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,906 ⟶ 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"]:
langs.add(l["title"].str.split("Category:")[1])
 
varproc ranks:cmp(a, seq[tuple[langb: string, countRank): int]] = @[]
result = cmp(b.count, a.count)
for line in getContent(catSize).findAll(regex):
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[Rank]
for line in client.getContent(CatSite).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 3,020 ⟶ 3,309:
};
}
}</langsyntaxhighlight>
 
<pre>1. 849 - Tcl
Line 3,036 ⟶ 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 3,234 ⟶ 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,368 ⟶ 3,657:
If ta<<tb Then res=-1
Else res=1
Return res</langsyntaxhighlight>
 
Output (the beginning):
Line 3,384 ⟶ 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,427 ⟶ 3,747:
do
{System.showInfo I#". "#Count#" - "#Cat}
end</langsyntaxhighlight>
{{out}}
<pre>
Line 3,444 ⟶ 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,483 ⟶ 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)-->
Note that this counts '''only''' the tasks. It does not include other non-task categories in the counts yielding more realistic, non-inflated numbers. Perl 6 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++)
<span style="color: #000080;font-style:italic;">-- demo\rosetta\Rank_Languages.exw</span>
 
<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>
<lang perl6>use HTTP::UserAgent;
<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>
use URI::Escape;
<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>
use JSON::Fast;
<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>
use Sort::Naturally;
 
my $client = HTTP::UserAgent.new;
 
my $url = 'http://rosettacode.org/mw';
 
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}" }
}</lang>
 
{{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
|}
 
===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.subst(',', ''), ~$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>' .*? '(' (<[, 0..9]>+) ' 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>
for @results.kv -> $i, @l {
printf "%d:\t%4d - %s\n", $i+1, |@l;
<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>
}</lang>
{{out}}
<span style="color: #008080;">function</span> <span style="color: #000000;">extract_names</span><span style="color: #0000FF;">()</span>
(As of 2018-10-28) Here we show only the top 10.
<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>
<pre>1: 1036 - Go
2: 1029 - Kotlin
<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>
3: 1014 - Python
<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>
4: 998 - Perl 6
<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>
5: 980 - Racket
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
6: 929 - Tcl
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
7: 926 - C
<span style="color: #000080;font-style:italic;">-- 1) extract languages from eg title="Category:Phix"</span>
8: 910 - Perl
<span style="color: #004080;">sequence</span> <span style="color: #000000;">language_names</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{}</span>
9: 904 - Zkl
<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>
10: 901 - J</pre>
<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>
=={{header|Phix}}==
<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>
The distributed version also has an output_html option.
<span style="color: #008080;">while</span> <span style="color: #004600;">true</span> <span style="color: #008080;">do</span>
<lang Phix>-- demo\rosetta\Rank_Languages.exw
<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>
include builtins\timedate.e
<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>
include builtins\libcurl.e
<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>
constant output_users = false,
<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>
limit = 20, -- 0 to list all
<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>
refresh_cache = timedelta(days:=1), -- 0 for always
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
languages = "http://rosettacode.org/wiki/Category:Programming_Languages",
categories = "http://www.rosettacode.org/mw/index.php?title=Special:Categories&limit=5000"
<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.
function open_download(string filename, url)
-- (note there is / ignore some wierd uncode-like stuff after the &lt;/a&gt;...)</span>
bool refetch = true
<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>
if file_exists(filename) then
<span style="color: #000000;">start</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">1</span>
-- use existing file if <= refresh_cache (1 day) old
<span style="color: #008080;">while</span> <span style="color: #004600;">true</span> <span style="color: #008080;">do</span>
sequence last_mod = get_file_date(filename) -- (0.8.1+)
<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>
atom delta = timedate_diff(last_mod,date())
<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>
refetch = (delta>refresh_cache)
<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>
end if
<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>
if refetch then
<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>
printf(1,"Downloading %s...\n",{filename})
<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>
CURLcode res = curl_easy_get_file(url,"",filename) -- (no proxy)
<span style="color: #008080;">if</span> <span style="color: #000000;">output_users</span> <span style="color: #008080;">then</span>
if res!=CURLE_OK then
<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>
string error = sprintf("%d",res)
<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>
if res=CURLE_COULDNT_RESOLVE_HOST then
<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>
error &= " [CURLE_COULDNT_RESOLVE_HOST]"
end if<span style="color: #008080;">else</span>
<span style="color: #000000;">language_name</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">""</span>
printf(1, "Error %s downloading file\n", error)
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
{} = wait_key()
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
abort(0)
<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>
end if
<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>
end if
<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>
return get_text(filename)
<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>
end function
<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>
constant cat_title = "title=\"Category:"
<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>
function extract_names()
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
sequence results = {} -- {rank,count,name}
<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)
 
-- 1) extract languages from eg title="Category:Phix"
--3) assign rank</span>
sequence language_names = {}
<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>
string langs = open_download("languages.htm",languages),
<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>
language_name
<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>
langs = langs[1..match("<div class=\"printfooter\">",langs)-1]
<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>
integer start = match("<h2>Subcategories</h2>",langs), k
<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>
while true do
<span style="color: #008080;">else</span>
k = match(cat_title,langs,start)
<span style="color: #000000;">rank</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">i</span>
if k=0 then exit end if
<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>
k += length(cat_title)
<span style="color: #000000;">prev</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">count</span>
start = find('"',langs,k)
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
language_name = langs[k..start-1]
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
language_names = append(language_names,language_name)
end while
<span style="color: #008080;">return</span> <span style="color: #000000;">results</span>
 
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
-- 2) extract results from eg title="Category:Phix">Phix</a>?? (997 members)</li>
-- but obviously only when we have found that language in the phase above.
<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>
-- (note there is / ignore some wierd uncode-like stuff after the </a>...)
<span style="color: #7060A8;">progress</span><span style="color: #0000FF;">(</span><span style="color: #008000;">""</span><span style="color: #0000FF;">)</span>
string cats = open_download("categories.htm",categories)
<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>
start = 1
<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>
while true do
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
k = match(cat_title,cats,start)
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
if k=0 then exit end if
k += length(cat_title)
<span style="color: #000000;">show</span><span style="color: #0000FF;">(</span><span style="color: #000000;">extract_names</span><span style="color: #0000FF;">())</span>
start = find('"',cats,k)
<!--</syntaxhighlight>-->
language_name = cats[k..start-1]
start = match("</a>",cats,start)+4
if output_users then
if length(language_name)>5
and language_name[-5..-1] = " User" then
language_name = language_name[1..-6]
else
language_name = ""
end if
end if
if length(language_name)
and find(language_name,language_names) then
while not find(cats[start],"(<") do start += 1 end while -- (ignore)
string members = cats[start..find('<',cats,start+1)]
members = substitute(members,",","")
sequence res = scanf(members,"(%d member%s)<")
results = append(results,{0,res[1][1],language_name})
end if
end while
results = sort_columns(results,{-2,3}) -- (descending 2nd column, then asc 3rd)
 
--3) assign rank
integer count, prev = 0, rank
for i=1 to length(results) do
count = results[i][2]
if count!=prev then rank = i end if
prev = count
results[i][1] = rank
end for
 
return results
end function
 
procedure show(sequence results)
for i=1 to iff(limit?limit:length(results)) do
printf(1,"%3d: %,d - %s\n",results[i])
end for
end procedure
 
show(extract_names())</lang>
{{out}}
As of AprilJuly 26th31st, 2019
<pre>
Downloading rc_cache\languages.htm...
1: 1,137 - Go
Downloading rc_cache\categories.htm...
2: 1,075 - Perl 6
31: 1,054156 - PythonGo
42: 1,042092 - KotlinPhix
53: 1,006090 - Perl 6
64: 9981,074 - Julia
75: 9971,066 - PhixPython
86: 9891,046 - RacketKotlin
97: 9491,026 - CPerl
10 8: 934991 - JRacket
11 9: 931953 - ZklC
10: 945 - J
11: 943 - Zkl
12: 930 - Tcl
13: 906915 - JavaREXX
14: 902910 - REXXJava
15: 875897 - DRuby
16: 873892 - RubyD
17: 869872 - Haskell
18: 804816 - Sidef
19: 793814 - Scala
20: 775786 - PicoLispC sharp
</pre>
 
=={{header|PicoLisp}}==
<langsyntaxhighlight PicoLisplang="picolisp">(load "@lib/http.l")
 
(for (I . X)
Line 3,919 ⟶ 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,934 ⟶ 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,963 ⟶ 4,035:
}
}| Format-Table -AutoSize
</syntaxhighlight>
</lang>
<b>Output: August 04, 2015</b>
<pre>
Line 3,998 ⟶ 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 4,129 ⟶ 4,298:
Print(#CRLF$ + #CRLF$ + "Press ENTER to exit"): Input()
CloseConsole()
EndIf</langsyntaxhighlight>
Sample output:
<pre>608 languages.
Line 4,197 ⟶ 4,366:
 
===Using web scraping method===
<langsyntaxhighlight lang="purebasic">
;Uses a web scraping method.
 
Line 4,253 ⟶ 4,422:
PrintN( Str(i + 1) + ". " + Str(Row(i)\count) + " - " + Row(i)\Name)
Next
Input()</langsyntaxhighlight>
Sample output:
<pre>1. 907 - Racket
Line 4,291 ⟶ 4,460:
Using <code>requests</code> library.
 
<langsyntaxhighlight lang="python">import requests
import re
 
Line 4,301 ⟶ 4,470:
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
cnt = 0
for (language, members) in sorted(members, key=lambda x: -int(x[1])):
if language in languages:
print("{:4d} {:4d} - {}".format(cnt+1, int(members), language))
cnt += 1
print("{:4d} {:4d} - {}".format(cnt, int(members), language))
if cnt >= 15: # show only top 15 languages
break
 
</syntaxhighlight>
</lang>
{{out|Output (as of JanDec 2621, 20192020)}}
1 10951306 - Go
2 10431275 - Perl 6Phix
3 10321265 - PythonJulia
4 10301257 - KotlinRaku
5 9941196 - PhixPython
6 9881182 - RacketPerl
7 9571107 - PerlKotlin
8 9411080 - C
9 9411074 - JuliaJava
10 9291061 - TclRacket
11 9161022 - ZklREXX
12 9031012 - JZkl
13 8951002 - JavaJ
14 886983 - REXXRuby
15 874972 - DHaskell
 
===Python: Using MediaWiki API method===
<syntaxhighlight lang ="python">import requests
import requests
import operator
import re
Line 4,360 ⟶ 4,526:
# report top 15 languages
for i, (language, size) in enumerate(sorted(languages.items(), key=operator.itemgetter(1), reverse=True)[:15]):
print("{:4d} {:4d} - {}".format(i+1, size, re.sub('Category:','',language))) # strip Category: from language
 
 
</lang>
</syntaxhighlight>
{{out|Output (as of Jan 27, 2019)}}
{{out|Output (as of Dec 21, 2020)}}
1 1095 - Go
21 10431306 - Perl 6Go
32 10321275 - PythonPhix
43 10301265 - KotlinJulia
54 9941257 - PhixRaku
65 9881196 - RacketPython
76 9571182 - Perl
87 9411107 - CKotlin
98 9411080 - JuliaC
10 9 9291074 - TclJava
1110 9161061 - ZklRacket
1211 9031022 - JREXX
1312 8951012 - JavaZkl
1413 8861002 - REXXJ
1514 874983 - DRuby
15 972 - Haskell
 
=={{header|R}}==
 
<lang rsplus>
<syntaxhighlight lang="rsplus">
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=5000"
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) {
# changing the columns to required format
language <- xml_node %>% html_attr("title")
langs$Rank = paste("Rank: ",langs$Rank)
language <- sub("^Category:", "", language)
langs$TaskEntries = paste0("(", format(langs$TaskEntries, big.mark = ",")
npages <- xml_node %>% html_nodes('categoryinfo') %>%
," entries", ")")
html_attr("pages")
 
c(language, npages)
names(langs) <- NULL
}
 
tbl <- ldply(sapply(langs, ff), rbind)
langs[1:10,]
names(tbl) <- c("language", "n")
 
tbl %>%
</syntaxhighlight>
mutate(n=as.integer(n)) %>%
{{out|Output (as of October, 24, 2022)}}
arrange(desc(n)) %>%
head
</lang>
{{out|Output (as of March, 23, 2019)}}
<pre>
1 Rank: 1 (1,589 entries) Phix
language n
12 Rank: 1 (1,589 entries) Go 1114Wren
3 Rank: 3 (1,552 entries) Julia
2 Perl 6 1059
4 Rank: 4 (1,535 entries) Raku
3 Kotlin 1029
5 Rank: 5 (1,500 entries) Go
4 Phix 993
6 Rank: 6 (1,485 entries) Perl
5 Julia 992
7 Rank: 7 (1,422 entries) Python
6 Perl 978
8 Rank: 8 (1,402 entries) Nim
9 Rank: 9 (1,293 entries) J
10 Rank: 10 (1,213 entries) C
</pre>
 
=={{header|Racket}}==
{{incorrect|Racket|I believe this does not match eg "1,113 members" and hence omits all>999}}
<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
<langsyntaxhighlight Redlang="red">Red []
 
data: read http://www.rosettacode.org/mw/index.php?title=Special:Categories&limit=5000
Line 4,519 ⟶ 5,001:
head? lb ;; until head reached
]
</syntaxhighlight>
</lang>
Output: (30.12.2017)
<pre>
Line 4,549 ⟶ 5,031:
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 4,567 ⟶ 5,052:
:::* &nbsp; '''??-61/52''' &nbsp; &nbsp; &nbsp; &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''' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; translated into &nbsp; '''Déjà Vu'''
:::* &nbsp; '''Cach├⌐''' &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; translated into &nbsp; '''Caché'''
:::* &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=call eSort #,1 0; 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 /*thestick numbera offork categoriesin it, (so far)we're all 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 pos(',', mems)\==0 then mems= changestr(",", mems, '') /*elide commas from #.*/
if \datatype(mems, 'W') then iterate /*is the "members" number 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 /*bump a couple of counters. */
#.#= #.# + mems; @.#= cat.j; @u.#= ? /*bump the counter; assign it (upper).*/
end /*j*/
!.= /*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*/
call eSort #,1 /*sort the languages along with entries*/
w= length( commas(#) ) /* [↓] show by ascending rank of lang.*/
rank= 0
do t=# by -1 for #; rank= rank + 1 /*bump rank of a programming language. */
call tell right('rank:' right(commas(!tR.t), w), 20-1) right(!.t, 7),
right('('commas(#.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 _; do jjc=length(_)-3 to 1 by -3; _= insert(",",_,jjc); end; return _
s: if arg(1)==1 then return arg(3); return word(arg(2) 's',1) /*pluralizer.*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
eSort: procedure expose #. @. !tr.; arg N,p2; h= N /*sort: number of members*/
Line 4,636 ⟶ 5,088:
@= @.j; #= #.j; @.j= @.k; #.j= #.k; @.k= @; #.k= #
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
/*──────────────────────────────────────────────────────────────────────────────────────*/
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. */
Formulae = 'F┼ìrmul├ª' do j=1 until catHeap=='' /*Unicodeprocess the heap (inof text)categories. name for Fôrmulæ */
parse Uyir = 'உயிர்/Uyir' var catHeap cat.j (sep) catHeap /*Unicodeget (in text)a category namefrom forthe UyircatHeap. */
parse var cat.j cat.j '<' "(" mems . /*untangle the strange─looking string. */
old.1= '╬£C++' ; new.1= "µC++" /*Unicode ╬£C++ ───► ASCII-8: µC++ */
old.2= 'UC++' cat.j= space(cat.j); new?=cat.2= "µC++" j; upper ? /*oldremove any superfluous blanks. UC++ ───► ASCII-8: µC++ */
old.3= if ?=='╨£╨Ü-' | \L.? ; new.3= "MK-" then iterate /*Unicodeit's ╨£╨Ü-blank ───►or ASCII-8: MK- it's not a language. */
if pos(',', mems)\==0 then mems= space(translate(mems,,","), 0) /*¬commas.*/
old.4= 'D├⌐j├á' ; new.4= "Déjà" /*Unicode ├⌐j├á ───► ASCII-8: Déjà */
if \datatype(mems, 'W') then iterate /*is the "members" number not numeric? */
old.5= 'Cach├⌐' ; new.5= "Caché" /*Unicode Cach├⌐ ───► ASCII-8: Caché */
#.0= #.0 + mems /*bump the number of members found. */
old.6= '??-61/52' ; new.6= "MK-61/52" /*somewhere past, a mis─translated: MK-*/
old.7= Formulae if ; newu.7?\==0 'Fôrmulæ' then do; /*Unicode do f=1 for ───►# ASCII─8: Fôrmulæuntil */?==@u.f
old.8= '╨£iniZinc' ; new.8= 'MiniZinc' /*Unicode ───► ASCII─8: MiniZinc end /*f*/
old.9= Uyir ; new.9= 'Uyir' /*Unicode #.f= #.f + mems; iterate j ───► ASCII─8: Uyir /*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 pos('RETRIEVED FROM',translate($$))\catFID==0'' then leavecatFID= "RC_POP.CAT" /*pseudoNot End-Of-Dataspecified? Then use the default.*/
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," " ; sayr= 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 705813 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.] <br><br><br>
<br>as well as those that use Unicode characters in the name.] <br><br><br>
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
# Project: Rosetta Code/Rank languages by popularity
Line 4,779 ⟶ 5,273:
next
return alist
</syntaxhighlight>
</lang>
Output:
<pre>
Line 4,813 ⟶ 5,307:
 
Uses the <code>RosettaCode</code> module from [[Count programming examples#Ruby]]
<langsyntaxhighlight lang="ruby">require 'rosettacode'
 
langs = []
Line 4,842 ⟶ 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,874 ⟶ 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,901 ⟶ 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,937 ⟶ 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 5,081 ⟶ 5,575:
Concurrent.logInfo("Parallel version started")
ActorSystem("Main").actorOf(Props[Concurrent.Listener])
}</langsyntaxhighlight>
 
===Sequential internet querying===
Line 5,152 ⟶ 5,646:
 
=={{header|Seed7}}==
<langsyntaxhighlight lang="seed7">$ include "seed7_05.s7i";
include "gethttp.s7i";
include "scanstri.s7i";
Line 5,209 ⟶ 5,703:
place +:= length(ranking[numList[listIdx]]);
end for;
end func;</langsyntaxhighlight>
 
List of languages as of 2014-01-15:
Line 5,248 ⟶ 5,742:
=={{header|Sidef}}==
{{trans|Perl}}
<langsyntaxhighlight lang="ruby">require('MediaWiki::API')
 
var api = %O<MediaWiki::API>.new(
Line 5,284 ⟶ 5,778:
sorted_languages.each_kv { |i, lang|
printf("%3d. %20s - %3d\n", i+1, lang{:title}, lang{:categoryinfo}{:size})
}</langsyntaxhighlight>
{{out}}
<pre>
Line 5,309 ⟶ 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 5,328 ⟶ 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 5,338 ⟶ 5,832:
url.close(.fin)
end</langsyntaxhighlight>
 
'''Abridged output (top 30 languages as of August 25, 2015):'''
Line 5,377 ⟶ 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 5,411 ⟶ 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 5,445 ⟶ 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 5,488 ⟶ 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 5,517 ⟶ 6,011:
{{libheader|tDOM}}
 
<langsyntaxhighlight lang="tcl">package require Tcl 8.5
package require http
package require tdom
Line 5,626 ⟶ 6,120:
}
 
popreport $langcounts</langsyntaxhighlight>
 
{{out}}
Line 5,652 ⟶ 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 5,700 ⟶ 6,194:
balt=b
ENDLOOP
ENDCOMPILE</langsyntaxhighlight>
{{out}}
<pre style='height:30ex;overflow:scroll'>
Line 5,745 ⟶ 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,868 ⟶ 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,898 ⟶ 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,904 ⟶ 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,941 ⟶ 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>
218

edits