Rosetta Code/Rank languages by popularity: Difference between revisions

m (updated the total number of Rosetta Code programming examples/entries.)
(409 intermediate revisions by 18 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 15 May 2018:
Rank: 2 (1,558 entries) Wren
<pre>
rankRank: 13 (10061,531 entries) KotlinJulia
rankRank: 2 4 (9801,507 entries) RacketRaku
rankRank: 3 5 (9771,500 entries) PythonGo
rankRank: 4 6 (9491,466 entries) Perl 6
rankRank: 5 7 (9181,409 entries) TclPython
rankRank: 6 8 (8991,402 entries) CNim
rankRank: 7 9 (8911,254 entries) J
rankRank: 8 10 (8791,211 entries) ZklC
rank: 9 (870 entries) Java
rank: 10 (860 entries) D
...</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 '''{{PAGESINCAT:Programming Languages}}''' [[:Category:Programming Languages|programming languages]], updated periodically, ''typically weekly''.
* &nbsp; A complete ranked listing of all &nbsp; '''682''' &nbsp; languages (from the REXX example) is included here &nbsp; ──► &nbsp; [[RC_POP.OUT]].
* &nbsp; A complete ranked listing of all &nbsp; '''813''' &nbsp; languages (from the REXX example) is included here &nbsp; ──► &nbsp; [[RC_POP.OUT|output from the REXX program]].
* &nbsp; A complete accurate sortable wikitable listing is included &nbsp; [[Rosetta_Code/Rank_languages_by_popularity/Full_list|here]].
 
<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 126 ⟶ 123:
Counts.Reverse_Iterate (Display'Access);
end Test;
</syntaxhighlight>
</lang>
 
=={{header|ALGOL 68}}==
Line 138 ⟶ 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 261 ⟶ 258:
printf(($g(-0)". "g(-0)" - "gl$,i,stats[i]))
OD
FI</langsyntaxhighlight>
{{out|Sample output}}
<pre>
Line 277 ⟶ 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 434 ⟶ 431:
lasttied := tied
FI
OD</langsyntaxhighlight>
{{out|Sample output top 10}}
<pre>
Line 454 ⟶ 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 539 ⟶ 536:
GuiClose:
ExitApp
return</langsyntaxhighlight>
 
=={{header|AWK}}==
Line 546 ⟶ 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 629 ⟶ 626:
print ++i ". " language " - " G[language]
 
}</langsyntaxhighlight>
{{out|Output from 26 May 2015}}
<pre>1. Tcl - 867
Line 649 ⟶ 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 738 ⟶ 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 778 ⟶ 775:
 
=={{header|Bracmat}}==
<langsyntaxhighlight lang="bracmat"> ( get-page
= url type
. !arg:(?url.?type)
Line 868 ⟶ 865:
)
)
& ;</langsyntaxhighlight>
Output:
<pre> 1. 816 - Tcl
Line 919 ⟶ 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 995 ⟶ 992:
 
return 0;
}</langsyntaxhighlight>
{{out}}
<pre> 563 Tcl
Line 1,015 ⟶ 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,163 ⟶ 1,160:
} while (sorted!=1);
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,179 ⟶ 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,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,206 ⟶ 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,216 ⟶ 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,288 ⟶ 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,370 ⟶ 1,394:
}
return 0 ;
}</langsyntaxhighlight>
{{out|Sample output (just the "top ten")}}
1. 367 - Tcl
Line 1,385 ⟶ 1,409:
=={{header|Caché ObjectScript}}==
 
<langsyntaxhighlight lang="cos">Class Utils.Net.RosettaCode [ Abstract ]
{
 
Line 1,464 ⟶ 1,488:
}
 
}</langsyntaxhighlight>
{{out|Example}}
<pre>
Line 1,483 ⟶ 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,502 ⟶ 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,524 ⟶ 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,587 ⟶ 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,614 ⟶ 1,810:
 
=={{header|F_Sharp|F#}}==
<langsyntaxhighlight lang="fsharp">open System
open System.Text.RegularExpressions
Line 1,666 ⟶ 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,691 ⟶ 1,887:
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import (
Line 1,805 ⟶ 2,001:
fmt.Printf("%3d. %3d - %s\n", lastIdx, lang.int, lang.string)
}
}</langsyntaxhighlight>
{{out|Output on 11 Aug 2014}}
<pre>
Line 1,823 ⟶ 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,831 ⟶ 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,846 ⟶ 2,042:
===Haskell: Using the API===
 
<langsyntaxhighlight lang="haskell">{-# LANGUAGE OverloadedStrings #-}
 
import Data.Aeson
Line 1,947 ⟶ 2,143:
 
main :: IO ()
main = runQuery [] queryStr</langsyntaxhighlight>
{{out}}
(As of 2015-07-29.) Here we show only the top 30.
Line 1,985 ⟶ 2,181:
 
Scraping the languages and categories pages.
<langsyntaxhighlight lang="haskell">import Network.Browser
import Network.HTTP
import Network.URI
Line 2,019 ⟶ 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,044 ⟶ 2,240:
 
=={{header|HicEst}}==
<langsyntaxhighlight lang="hicest">CHARACTER cats*50000, catlist*50000, sortedCat*50000, sample*100
DIMENSION RankNr(1)
 
Line 2,076 ⟶ 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,088 ⟶ 2,284:
8. 298 Perl
9. 288 WikiStubs
10. 281 Common Lisp</langsyntaxhighlight>
 
=={{header|Icon}} and {{header|Unicon}}==
Line 2,094 ⟶ 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,142 ⟶ 2,338:
close(page)
return text
end</langsyntaxhighlight>
 
Abridged output (top 26 languages as of July 30, 2016):
Line 2,176 ⟶ 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,195 ⟶ 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,206 ⟶ 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,341 ⟶ 2,537:
} // for lPos
} // main
} // GetRCLanguages</langsyntaxhighlight>
{{out}}
Top 10 languages as at 27th August 2015
Line 2,358 ⟶ 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,407 ⟶ 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,431 ⟶ 2,627:
386. 1 - Algae
386. 1 - 80386 Assembly
386. 1 - 68000 Assembly</langsyntaxhighlight>
 
=={{header|Julia}}==
Uses the API for the language list and page scraping for the example counts for each language.
<syntaxhighlight lang="julia">""" Rosetta code task rosettacode.org/wiki/Rosetta_Code/Rank_languages_by_popularity """
 
using Dates
using DataFrames
using HTTP
using JSON3
 
""" Get listing of all tasks and draft tasks with authors and dates created, with the counts as popularity """
function rosetta_code_language_example_counts(verbose = false)
URL = "https://rosettacode.org/w/api.php?"
LANGPARAMS = ["action" => "query", "format" => "json", "formatversion" => "2", "generator" => "categorymembers",
"gcmtitle" => "Category:Programming_Languages", "gcmlimit" => "500", "rawcontinue" => "", "prop" => "title"]
queryparams = copy(LANGPARAMS)
df = empty!(DataFrame([[""], [0]], ["ProgrammingLanguage", "ExampleCount"]))
 
while true # get all the languages listed, with curid, eg rosettacode.org/w/index.php?curid=196 for C
resp = HTTP.get(URL * join(map(p -> p[1] * (p[2] == "" ? "" : ("=" * p[2])), queryparams), "&"))
json = JSON3.read(String(resp.body))
pages = json.query.pages
reg = r"The following \d+ pages are in this category, out of ([\d\,]+) total"
for p in pages
lang = replace(p.title, "Category:" => "")
langpage = String(HTTP.get("https://rosettacode.org/w/index.php?curid=" * string(p.pageid)).body)
if !((m = match(reg, langpage)) isa Nothing)
push!(df, [lang, parse(Int, replace(m.captures[1], "," => ""))])
verbose && println("Language: $lang, count: ", m.captures[1])
end
end
!haskey(json, "query-continue") && break # break if no more pages, else continue to next pages
queryparams = vcat(LANGPARAMS, "gcmcontinue" => json["query-continue"]["categorymembers"]["gcmcontinue"])
end
 
return sort!(df, :ExampleCount, rev = true)
end
 
println("Top 20 Programming Languages on Rosetta Code by Number of Examples, As of: ", now())
println(rosetta_code_language_example_counts()[begin:begin+19, :])
 
</syntaxhighlight>{{out}}
<pre>
Top 20 Programming Languages on Rosetta Code by Number of Examples, As of: 2022-09-05T14:59:56.316
20×2 DataFrame
Row │ ProgrammingLanguage ExampleCount
│ String Int64
─────┼───────────────────────────────────
1 │ Wren 1569
2 │ Phix 1569
3 │ Julia 1537
4 │ Raku 1517
5 │ Go 1496
6 │ Perl 1460
7 │ Python 1404
8 │ Nim 1402
9 │ J 1275
10 │ C 1210
11 │ Mathematica 1178
12 │ REXX 1149
13 │ Haskell 1139
14 │ Java 1136
15 │ Kotlin 1133
16 │ C++ 1120
17 │ Ruby 1103
18 │ Racket 1089
19 │ FreeBASIC 1069
20 │ Zkl 1011
</pre>
 
=={{header|Kotlin}}==
{{trans|Java}}
<langsyntaxhighlight lang="scala">import java.net.URL
import java.io.*
 
Line 2,515 ⟶ 2,780:
}
}
}</langsyntaxhighlight>
{{out}}
<pre> 1, 901, Racket
Line 2,527 ⟶ 2,792:
 
=={{header|Lasso}}==
<langsyntaxhighlight Lassolang="lasso"><pre><code>[
sys_listtraits !>> 'xml_tree_trait' ? include('xml_tree.lasso')
local(lang = array)
Line 2,551 ⟶ 2,816:
'. '+#l->second + ' - ' + #l->first+'\r'
^}
]</code></pre></langsyntaxhighlight>
 
{{out}}
Line 2,571 ⟶ 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,648 ⟶ 2,913:
}
Print
\\ this type of iventoryinventory can get same keys
\\ also has stable sort
Report "Make Inventory list by Task"
Line 2,663 ⟶ 2,928:
Report "Make List"
T=Each(ByTask)
final$="Sample output on "+Date$(Today, 1033, "long date")+{:
}
Line 2,676 ⟶ 2,941:
}
RankLanguages
</syntaxhighlight>
</lang>
 
{{out}}
<pre style="height:30ex;overflow:scroll">
Sample output on 9/8/2018Saturday, June 22, 2019:
rank: 1. 10191149 entries - KotlinGo
rank: 2. 9881084 entries - PythonPerl 6
rank: 3. 9801061 entries - RacketPython
rank: 4. 9761045 entries - Perl 6Kotlin
rank: 5. 9571044 entries - GoJulia
rank: 6. 9181033 entries - TclPhix
rank: 7. 9141026 entries - CPerl
rank: 8. 891991 entries - JRacket
rank: 9. 890951 entries - ZklC
rank: 10. 882944 entries - JavaJ
rank: 11. 868938 entries - DZkl
rank: 12. 851930 entries - RubyTcl
rank: 13. 839910 entries - REXX
rank: 14. 836909 entries - HaskellJava
rank: 15. 808883 entries - PerlRuby
rank: 16. 789881 entries - ScalaD
rank: 17. 788869 entries - JuliaHaskell
rank: 18. 774814 entries - PicoLispSidef
rank: 19. 771801 entries - SidefScala
rank: 20. 736779 entries - MathematicaC sharp
rank: 21. 735775 entries - PhixPicoLisp
rank: 22. 695772 entries - C sharp++
rank: 23. 693748 entries - C++Mathematica
rank: 24. 654678 entries - Common Lisp
rank: 25. 649668 entries - Ada
rank: 26. 621639 entries - AutoHotkeyJavaScript
rank: 27. 601633 entries - RingLua
rank: 28. 598628 entries - JavaScriptAutoHotkey
rank: 29. 590611 entries - UniconRing
rank: 30. 585595 entries - ClojureFactor
rank: 31. 582594 entries - LuaClojure
rank: 32. 560590 entries - BBC BASICUnicon
rank: 33. 553566 entries - FortranALGOL 68
rank: 34. 552563 entries - PureBasicNim
rank: 35. 545563 entries - ALGOL 68PureBasic
rank: 36. 543560 entries - OCamlBBC BASIC
rank: 37. 535559 entries - PARI/GPFortran
rank: 38. 532556 entries - IconOCaml
rank: 39. 529540 entries - NimPARI/GP
rank: 40. 513538 entries - ElixirF Sharp
rank: 41. 493532 entries - F SharpIcon
rank: 42. 489517 entries - ErlangElixir
rank: 43. 475497 entries - FreeBASIC
rank: 44. 471495 entries - PowerShellErlang
rank: 45. 457485 entries - JqRust
rank: 46. 455473 entries - FactorPowerShell
rank: 47. 436462 entries - ForthJq
rank: 48. 435456 entries - Pascal
rank: 49. 421453 entries - AWK
rank: 50. 416450 entries - RForth
rank: 51. 411448 entries - RustSeed7
rank: 52. 407435 entries - Seed7R
rank: 53. 403414 entries - PL/IGroovy
rank: 54. 393403 entries - GroovyPL/I
rank: 55. 391401 entries - PHP
rank: 56. 358383 entries - MATLABVBA
rank: 57. 354361 entries - Scheme
rank: 58. 340359 entries - MapleMATLAB
rank: 59. 334353 entries - Liberty BASICSwift
rank: 60. 314346 entries - RunM2000 BASICInterpreter
rank: 61. 308343 entries - OforthMaple
rank: 62. 306337 entries - OctaveLiberty BASIC
rank: 63. 305314 entries - XPL0Run BASIC
rank: 64. 304309 entries - EchoLispProlog
 
rank: 65. 299 entries - Swift
rank: 66. 289 entries - UNIX Shell
rank: 67. 288 entries - Bracmat
rank: 68. 287 entries - NetRexx
rank: 69. 280 entries - Oz
rank: 70. 279 entries - Prolog
rank: 71. 272 entries - E
rank: 72. 271 entries - VBScript
rank: 73. 268 entries - Objeck
rank: 74. 265 entries - COBOL
..........
rank: 675685. 1 entries - WollokJacquard Loom
rank: 676686. 1 entries - X86Kamailio 64 AssemblyScript
rank: 677687. 1 entries - XanaduLambda Prolog
rank: 678688. 1 entries - XPathLibreOffice 2.0Basic
rank: 679689. 1 entries - YaMAPPER
rank: 680690. 01 entries - AngelScriptMEL
rank: 681691. 01 entries - Binary Lambda CalculusMiniZinc
rank: 682692. 01 entries - EhBASICMond
rank: 683693. 01 entries - EpigramMonkey
rank: 684694. 01 entries - FLORA-2NASL
rank: 685695. 01 entries - FloridNeat
rank: 686696. 01 entries - LC2200 AssemblyNewtonScript
rank: 687697. 01 entries - LeonNickle
rank: 688698. 01 entries - LLPNix
rank: 689699. 01 entries - Loglan82Opa
rank: 690700. 01 entries - LolliPare
rank: 691701. 01 entries - LygonQore
rank: 692702. 01 entries - ObjectIconRapira
rank: 693703. 01 entries - PlanRPGIV
rank: 694704. 01 entries - ReduceSetl4
rank: 695705. 01 entries - RubylogSoar
rank: 696706. 01 entries - SimpleLangSoneKing Assembly
rank: 697707. 01 entries - SpinSupernova
rank: 698708. 01 entries - StarSuperTalk
rank: 699709. 01 entries - X10Terra
rank: 700710. 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,816 ⟶ 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,837 ⟶ 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,858 ⟶ 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 2,972 ⟶ 3,309:
};
}
}</langsyntaxhighlight>
 
<pre>1. 849 - Tcl
Line 2,988 ⟶ 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,186 ⟶ 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,320 ⟶ 3,657:
If ta<<tb Then res=-1
Else res=1
Return res</langsyntaxhighlight>
 
Output (the beginning):
Line 3,336 ⟶ 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,379 ⟶ 3,747:
do
{System.showInfo I#". "#Count#" - "#Cat}
end</langsyntaxhighlight>
{{out}}
<pre>
Line 3,396 ⟶ 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,435 ⟶ 3,803:
$_->{'categoryinfo'}{'size'};
}
</syntaxhighlight>
</lang>
{{out}}
 
<pre> 1. Phix - 1576
=={{header|Perl 6}}==
2. Wren - 1569
 
3. Julia - 1540
===Perl 6: Using the API===
4. Raku - 1520
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++)
5. Go - 1500
 
6. Perl - 1468
<lang perl6>use HTTP::UserAgent;
7. Python - 1422
use URI::Escape;
8. Nim - 1403
use JSON::Fast;
9. J - 1278
use Sort::Naturally;
10. C - 1213
 
...</pre>
my $client = HTTP::UserAgent.new;
 
my $url = 'http://rosettacode.org/mw';
 
my $tablefile = './RC_Popularity.txt';
 
my %counts =
mediawiki-query(
$url, 'pages',
:generator<categorymembers>,
:gcmtitle<Category:Programming Languages>,
:gcmlimit<350>,
:rawcontinue(),
:prop<categoryinfo>
)
.map({ .<title>.subst(/^'Category:'/, '') => .<categoryinfo><pages> || 0 });
 
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 !! Count"
;
 
my @bg = <#fff; #ccc;>;
my $ff = 0;
my $rank = 1;
my $ties = 0;
 
# Get sorted unique task counts
for %counts.values.unique.sort: -* -> $count {
$ff++;
# Get list of tasks with this count
my @these = %counts.grep( *.value == $count )».keys.sort: *.&naturally;
 
for @these {
$ties++;
$out.say:
"|-\n"~
"|style=\"background-color: { @bg[$ff % 2] }\"|$rank\n"~
"|style=\"background-color: { @bg[$ff % 2] }\"|[[:Category:$_|]]\n"~
"|style=\"background-color: { @bg[$ff % 2] }\"|$count";
}
$rank += $ties;
$ties = 0;
}
$out.say( "|}\n" );
$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>
 
=={{header|Phix}}==
{{out|Abridged output}} See full output [[Rosetta_Code/Rank_languages_by_popularity/Full_list|here]].
The distributed version also has an output_html option.
<div style="height:50em;overflow:scroll;">
{{libheader|Phix/libcurl}}
{|class="wikitable sortable"
<!--<syntaxhighlight lang="phix">(phixonline)-->
|+ As of 2018-05-18 :: 686 Languages
<span style="color: #000080;font-style:italic;">-- demo\rosetta\Rank_Languages.exw</span>
! Rank !! Language !! Count
<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>
|-
<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>
|style="background-color: #ccc;"|1
<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>
|style="background-color: #ccc;"|[[:Category:Kotlin|Kotlin]]
<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>
|style="background-color: #ccc;"|1006
|-
|style="background-color: #fff;"|2
|style="background-color: #fff;"|[[:Category:Racket|Racket]]
|style="background-color: #fff;"|977
|-
|style="background-color: #ccc;"|3
|style="background-color: #ccc;"|[[:Category:Python|Python]]
|style="background-color: #ccc;"|960
|-
|style="background-color: #fff;"|4
|style="background-color: #fff;"|[[:Category:Perl 6|Perl 6]]
|style="background-color: #fff;"|945
|-
|style="background-color: #ccc;"|5
|style="background-color: #ccc;"|[[:Category:Tcl|Tcl]]
|style="background-color: #ccc;"|914
|-
|style="background-color: #fff;"|6
|style="background-color: #fff;"|[[:Category:C|C]]
|style="background-color: #fff;"|896
|-
|style="background-color: #ccc;"|7
|style="background-color: #ccc;"|[[:Category:J|J]]
|style="background-color: #ccc;"|888
|-
|style="background-color: #fff;"|8
|style="background-color: #fff;"|[[:Category:Zkl|Zkl]]
|style="background-color: #fff;"|878
|-
|style="background-color: #ccc;"|9
|style="background-color: #ccc;"|[[:Category:Java|Java]]
|style="background-color: #ccc;"|867
|-
|style="background-color: #fff;"|10
|style="background-color: #fff;"|[[:Category:D|D]]
|style="background-color: #fff;"|857
|-
|style="background-color: #ccc;"|11
|style="background-color: #ccc;"|[[:Category:Ruby|Ruby]]
|style="background-color: #ccc;"|846
|-
|style="background-color: #fff;"|12
|style="background-color: #fff;"|[[:Category:Go|Go]]
|style="background-color: #fff;"|838
|-
|style="background-color: #ccc;"|13
|style="background-color: #ccc;"|[[:Category:Haskell|Haskell]]
|style="background-color: #ccc;"|824
|-
|style="background-color: #fff;"|14
|style="background-color: #fff;"|[[:Category:REXX|REXX]]
|style="background-color: #fff;"|823
|-
|style="background-color: #ccc;"|15
|style="background-color: #ccc;"|[[:Category:Perl|Perl]]
|style="background-color: #ccc;"|794
|-
|style="background-color: #fff;"|16
|style="background-color: #fff;"|[[:Category:Julia|Julia]]
|style="background-color: #fff;"|774
|-
|style="background-color: #ccc;"|17
|style="background-color: #ccc;"|[[:Category:PicoLisp|PicoLisp]]
|style="background-color: #ccc;"|768
|-
|style="background-color: #fff;"|18
|style="background-color: #fff;"|[[:Category:Sidef|Sidef]]
|style="background-color: #fff;"|763
|-
|style="background-color: #ccc;"|19
|style="background-color: #ccc;"|[[:Category:Mathematica|Mathematica]]
|style="background-color: #ccc;"|723
|-
|style="background-color: #fff;"|20
|style="background-color: #fff;"|[[:Category:Phix|Phix]]
|style="background-color: #fff;"|682
|}
</div>
 
===Perl 6: Using web scraping===
 
Scraping the languages and categories pages. Perl 6 automatically handles Unicode names correctly.
<lang perl6>my $languages = qx{wget -O - 'http://rosettacode.org/wiki/Category:Programming_Languages'};
my $categories = qx{wget -O - 'http://www.rosettacode.org/mw/index.php?title=Special:Categories&limit=5000'};
<span style="color: #008080;">include</span> <span style="color: #000000;">rosettacode_cache</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span> <span style="color: #000080;font-style:italic;">-- see [[Rosetta_Code/Count_examples#Phix]]</span>
my @lines = $languages.lines;
shift @lines until @lines[0] ~~ / '<h2>Subcategories</h2>' /;
my \languages = set gather for @lines {
last if / '/bodycontent' /;
take ~$0 if
/ '<li><a href="/wiki/Category:' .*? '" title="Category:' .*? '">' (.*?) '</a></li>' /;
}
<span style="color: #008080;">function</span> <span style="color: #000000;">correct_name</span><span style="color: #0000FF;">(</span><span style="color: #004080;">string</span> <span style="color: #000000;">ri</span><span style="color: #0000FF;">)</span>
@lines = $categories.lines;
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`&quot;`</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`"`</span><span style="color: #0000FF;">)</span>
my @results = sort -*.[0], gather for @lines {
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`&#039;`</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`'`</span><span style="color: #0000FF;">)</span>
take [+$1, ~$0] if
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\xE2\x80\x99"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"'"</span><span style="color: #0000FF;">)</span>
/ '<li><a href="/wiki/Category:' .*? '" title="Category:' .*? '">'
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\xC3\xB6"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"o"</span><span style="color: #0000FF;">)</span>
(.*?) <?{ ~$0 ∈ languages }>
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%3A"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">":"</span><span style="color: #0000FF;">)</span>
'</a>' .*? '(' (\d+) ' member' /;
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%E2%80%93"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"-"</span><span style="color: #0000FF;">)</span>
}
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%E2%80%99"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"'"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%27"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"'"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%2B"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"+"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%C3%A8"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"e"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%C3%A9"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"e"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%C3%B6"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"o"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%C5%91"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"o"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%22"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`"`</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%2A"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"*"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\xC2\xB5"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"u"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\xC3\xA0"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"a"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\xC3\xA6"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"a"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\xC3\xA9"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"e"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\xC3\xB4"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"o"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\xC5\x8D"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"o"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\xCE\x9C"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"u"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\xD0\x9C\xD0\x9A"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"MK"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\xE0\xAE\x89\xE0\xAE\xAF\xE0\xAE\xBF\xE0\xAE\xB0\xE0\xAF\x8D/"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">""</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"APEX"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Apex"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"uC++ "</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"UC++"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`CASIO BASIC`</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`Casio BASIC`</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`Visual BASIC`</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`Visual Basic`</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`INTERCAL`</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`Intercal`</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`SETL4`</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`Setl4`</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`QBASIC`</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`QBasic`</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`RED`</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`Red`</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`OCTAVE`</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`Octave`</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">ri</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">ri</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`OoREXX`</span><span style="color: #0000FF;">,</span><span style="color: #008000;">`OoRexx`</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">return</span> <span style="color: #000000;">ri</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #008080;">include</span> <span style="color: #000000;">builtins</span><span style="color: #0000FF;">/</span><span style="color: #000000;">sets</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">cat_title</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">`title="Category:`</span>
for @results.kv -> $i, @l {
printf "%d:\t%3d - %s\n", $i+1, |@l;
<span style="color: #008080;">function</span> <span style="color: #000000;">extract_names</span><span style="color: #0000FF;">()</span>
}</lang>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">results</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{}</span> <span style="color: #000080;font-style:italic;">-- {rank,count,name}</span>
<span style="color: #008080;">if</span> <span style="color: #7060A8;">get_file_type</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"rc_cache"</span><span style="color: #0000FF;">)!=</span><span style="color: #004600;">FILETYPE_DIRECTORY</span> <span style="color: #008080;">then</span>
<span style="color: #008080;">if</span> <span style="color: #008080;">not</span> <span style="color: #000000;">create_directory</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"rc_cache"</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">then</span>
<span style="color: #7060A8;">crash</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"cannot create rc_cache directory"</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #000080;font-style:italic;">-- 1) extract languages from eg title="Category:Phix"</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">language_names</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{}</span>
<span style="color: #004080;">string</span> <span style="color: #000000;">langs</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">open_download</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"languages.htm"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">languages</span><span style="color: #0000FF;">),</span>
<span style="color: #000000;">language_name</span>
<span style="color: #000000;">langs</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">langs</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">..</span><span style="color: #7060A8;">match</span><span style="color: #0000FF;">(</span><span style="color: #008000;">`&lt;div class="printfooter"&gt;`</span><span style="color: #0000FF;">,</span><span style="color: #000000;">langs</span><span style="color: #0000FF;">)-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">start</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">match</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"&lt;h2&gt;Subcategories&lt;/h2&gt;"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">langs</span><span style="color: #0000FF;">),</span> <span style="color: #000000;">k</span>
<span style="color: #008080;">while</span> <span style="color: #004600;">true</span> <span style="color: #008080;">do</span>
<span style="color: #000000;">k</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">match</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cat_title</span><span style="color: #0000FF;">,</span><span style="color: #000000;">langs</span><span style="color: #0000FF;">,</span><span style="color: #000000;">start</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">k</span><span style="color: #0000FF;">=</span><span style="color: #000000;">0</span> <span style="color: #008080;">then</span> <span style="color: #008080;">exit</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #000000;">k</span> <span style="color: #0000FF;">+=</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cat_title</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">start</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">find</span><span style="color: #0000FF;">(</span><span style="color: #008000;">'"'</span><span style="color: #0000FF;">,</span><span style="color: #000000;">langs</span><span style="color: #0000FF;">,</span><span style="color: #000000;">k</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">language_name</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">correct_name</span><span style="color: #0000FF;">(</span><span style="color: #000000;">langs</span><span style="color: #0000FF;">[</span><span style="color: #000000;">k</span><span style="color: #0000FF;">..</span><span style="color: #000000;">start</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">])</span>
<span style="color: #000000;">language_names</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">append</span><span style="color: #0000FF;">(</span><span style="color: #000000;">language_names</span><span style="color: #0000FF;">,</span><span style="color: #000000;">language_name</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<span style="color: #000080;font-style:italic;">-- 2) extract results from eg title="Category:Phix"&gt;Phix&lt;/a&gt;?? (997 members)&lt;/li&gt;
-- but obviously only when we have found that language in the phase above.
-- (note there is / ignore some wierd uncode-like stuff after the &lt;/a&gt;...)</span>
<span style="color: #004080;">string</span> <span style="color: #000000;">cats</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">open_download</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"categories.htm"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">categories</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">start</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">1</span>
<span style="color: #008080;">while</span> <span style="color: #004600;">true</span> <span style="color: #008080;">do</span>
<span style="color: #000000;">k</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">match</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cat_title</span><span style="color: #0000FF;">,</span><span style="color: #000000;">cats</span><span style="color: #0000FF;">,</span><span style="color: #000000;">start</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">k</span><span style="color: #0000FF;">=</span><span style="color: #000000;">0</span> <span style="color: #008080;">then</span> <span style="color: #008080;">exit</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #000000;">k</span> <span style="color: #0000FF;">+=</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cat_title</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">start</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">find</span><span style="color: #0000FF;">(</span><span style="color: #008000;">'"'</span><span style="color: #0000FF;">,</span><span style="color: #000000;">cats</span><span style="color: #0000FF;">,</span><span style="color: #000000;">k</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">language_name</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">correct_name</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cats</span><span style="color: #0000FF;">[</span><span style="color: #000000;">k</span><span style="color: #0000FF;">..</span><span style="color: #000000;">start</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">])</span>
<span style="color: #000000;">start</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">match</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"&lt;/a&gt;"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">cats</span><span style="color: #0000FF;">,</span><span style="color: #000000;">start</span><span style="color: #0000FF;">)+</span><span style="color: #000000;">4</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">output_users</span> <span style="color: #008080;">then</span>
<span style="color: #008080;">if</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">language_name</span><span style="color: #0000FF;">)></span><span style="color: #000000;">5</span>
<span style="color: #008080;">and</span> <span style="color: #000000;">language_name</span><span style="color: #0000FF;">[-</span><span style="color: #000000;">5</span><span style="color: #0000FF;">..-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">" User"</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">language_name</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">correct_name</span><span style="color: #0000FF;">(</span><span style="color: #000000;">language_name</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">..-</span><span style="color: #000000;">6</span><span style="color: #0000FF;">])</span>
<span style="color: #008080;">else</span>
<span style="color: #000000;">language_name</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">""</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">if</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">language_name</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">and</span> <span style="color: #7060A8;">find</span><span style="color: #0000FF;">(</span><span style="color: #000000;">language_name</span><span style="color: #0000FF;">,</span><span style="color: #000000;">language_names</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">then</span>
<span style="color: #008080;">while</span> <span style="color: #008080;">not</span> <span style="color: #7060A8;">find</span><span style="color: #0000FF;">(</span><span style="color: #000000;">cats</span><span style="color: #0000FF;">[</span><span style="color: #000000;">start</span><span style="color: #0000FF;">],</span><span style="color: #008000;">"(&lt;"</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span> <span style="color: #000000;">start</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span> <span style="color: #008080;">end</span> <span style="color: #008080;">while</span> <span style="color: #000080;font-style:italic;">-- (ignore)</span>
<span style="color: #004080;">string</span> <span style="color: #000000;">members</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">cats</span><span style="color: #0000FF;">[</span><span style="color: #000000;">start</span><span style="color: #0000FF;">..</span><span style="color: #7060A8;">find</span><span style="color: #0000FF;">(</span><span style="color: #008000;">'&lt;'</span><span style="color: #0000FF;">,</span><span style="color: #000000;">cats</span><span style="color: #0000FF;">,</span><span style="color: #000000;">start</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)]</span>
<span style="color: #000000;">members</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">members</span><span style="color: #0000FF;">,</span><span style="color: #008000;">","</span><span style="color: #0000FF;">,</span><span style="color: #008000;">""</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">scanf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">members</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"(%d member%s)&lt;"</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">results</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">append</span><span style="color: #0000FF;">(</span><span style="color: #000000;">results</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">res</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">][</span><span style="color: #000000;">1</span><span style="color: #0000FF;">],</span><span style="color: #000000;">language_name</span><span style="color: #0000FF;">})</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<span style="color: #000000;">results</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">sort_columns</span><span style="color: #0000FF;">(</span><span style="color: #000000;">results</span><span style="color: #0000FF;">,{-</span><span style="color: #000000;">2</span><span style="color: #0000FF;">,</span><span style="color: #000000;">3</span><span style="color: #0000FF;">})</span> <span style="color: #000080;font-style:italic;">-- (descending 2nd column, then asc 3rd)
--3) assign rank</span>
<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>
<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>
<span style="color: #000000;">count</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">results</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">][</span><span style="color: #000000;">2</span><span style="color: #0000FF;">]</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">count</span><span style="color: #0000FF;">=</span><span style="color: #000000;">prev</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">results</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">][</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"="</span>
<span style="color: #008080;">else</span>
<span style="color: #000000;">rank</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">i</span>
<span style="color: #000000;">results</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">][</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">sprint</span><span style="color: #0000FF;">(</span><span style="color: #000000;">rank</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">prev</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">count</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">return</span> <span style="color: #000000;">results</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #008080;">procedure</span> <span style="color: #000000;">show</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">results</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">progress</span><span style="color: #0000FF;">(</span><span style="color: #008000;">""</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #000000;">limit</span><span style="color: #0000FF;">?</span><span style="color: #000000;">limit</span><span style="color: #0000FF;">:</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">results</span><span style="color: #0000FF;">))</span> <span style="color: #008080;">do</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%3s: %,d - %s\n"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">results</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">])</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
<span style="color: #000000;">show</span><span style="color: #0000FF;">(</span><span style="color: #000000;">extract_names</span><span style="color: #0000FF;">())</span>
<!--</syntaxhighlight>-->
{{out}}
As of July 31st, 2019
(As of 2014-07-11.) Here we show only the top 10.
<pre>1: 833 - Tcl
Downloading rc_cache\languages.htm...
2: 781 - Racket
Downloading rc_cache\categories.htm...
3: 770 - Python
1: 1,156 - Go
4: 730 - Perl 6
5 2: 725 1,092 - JPhix
6 3: 712 1,090 - CPerl 6
7 4: 708 1,074 - RubyJulia
8 5: 698 1,066 - DPython
9 6: 674 1,046 - GoKotlin
10 7: 656 1,026 - Perl</pre>
8: 991 - Racket
9: 953 - C
10: 945 - J
11: 943 - Zkl
12: 930 - Tcl
13: 915 - REXX
14: 910 - Java
15: 897 - Ruby
16: 892 - D
17: 872 - Haskell
18: 816 - Sidef
19: 814 - Scala
20: 786 - C sharp
</pre>
 
=={{header|PicoLisp}}==
<langsyntaxhighlight PicoLisplang="picolisp">(load "@lib/http.l")
 
(for (I . X)
Line 3,655 ⟶ 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,670 ⟶ 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,699 ⟶ 4,035:
}
}| Format-Table -AutoSize
</syntaxhighlight>
</lang>
<b>Output: August 04, 2015</b>
<pre>
Line 3,734 ⟶ 4,070:
29 441 PARI/GP 59 249 Delphi
30 434 JavaScript 60 239 Smalltalk
</pre>
===PowerShell: Using web scraping===
{{trans|Python}}
<syntaxhighlight lang="powershell">
$response = (New-Object Net.WebClient).DownloadString("http://rosettacode.org/wiki/Category:Programming_Languages")
$languages = [regex]::matches($response,'title="Category:(.*?)">') | foreach {$_.Groups[1].Value}
 
$response = [Net.WebClient]::new().DownloadString("http://rosettacode.org/w/index.php?title=Special:Categories&limit=5000")
$response = [regex]::Replace($response,'(\d+),(\d+)','$1$2')
 
$members = [regex]::matches($response,'<li><a[^>]+>([^<]+)</a>[^(]*[(](\d+) member[s]?[)]</li>') | foreach { [pscustomobject]@{
Members = [Int]($_.Groups[2].Value)
Language = [String]($_.Groups[1].Value)
}} | where {$languages.Contains($_.Language)} | sort -Descending Members
 
Get-Date -UFormat "Sample output on %d %B %Y at %R %Z"
$members | Select-Object -First 10 | foreach -Begin {$r, $rank, $count = 0, 0,-1} {
$r++
if ($count -ne $_.Members) {$rank = $r}
$count = $_.Members
$x = $_.Members.ToString("N0",[System.Globalization.CultureInfo]::CreateSpecificCulture('en-US'))
$entry = "($x entries)"
[String]::Format("Rank: {0,2} {1,15} {2}",$rank,$entry,$_.Language)
}
</syntaxhighlight>
{{out}}
<pre>
Sample output on 13 septembre 2019 at 12:17 +02
Rank: 1 (1,177 entries) Go
Rank: 2 (1,116 entries) Phix
Rank: 3 (1,107 entries) Perl 6
Rank: 4 (1,104 entries) Julia
Rank: 5 (1,080 entries) Python
Rank: 6 (1,053 entries) Kotlin
Rank: 7 (1,048 entries) Perl
Rank: 8 (1,045 entries) Racket
Rank: 9 (970 entries) C
Rank: 10 (960 entries) Zkl
</pre>
 
===PowerShell: Using MediaWiki API method===
{{trans|Python}}
<syntaxhighlight lang="powershell">
$languages = @{}
$Body = @{
format = 'json'
action = 'query'
generator = 'categorymembers'
gcmtitle = 'Category:Programming Languages'
gcmlimit = '200'
gcmcontinue = ''
continue = ''
prop = 'categoryinfo'
}
$params = @{
Method = 'Get'
Uri = 'http://rosettacode.org/mw/api.php'
Body = $Body
}
while ($true) {
$response = Invoke-RestMethod @params
$response.query.pages.PSObject.Properties | ForEach-Object {
if (($_.value.PSObject.Properties.Name -Contains 'title') -and ($_.value.PSObject.Properties.Name -Contains 'categoryinfo')) {
$languages[$_.value.title.replace('Category:', '')] = $_.value.categoryinfo.size
}
}
if ($response.PSObject.Properties.Name -Contains 'continue') {
$gcmcontinue = $response.continue.gcmcontinue
$params.Body.gcmcontinue = $gcmcontinue
} else {
break
}
}
$members = $languages.GetEnumerator() | sort -Descending value
Get-Date -UFormat "Sample output on %d %B %Y at %R %Z"
$members | Select-Object -First 10 | foreach -Begin {$r, $rank, $count = 0, 0,-1} {
$r++
if ($count -ne $_.Members) {$rank = $r}
$count = $_.Value
$x = $_.Value.ToString("N0",[System.Globalization.CultureInfo]::CreateSpecificCulture('en-US'))
$entry = "($x entries)"
[String]::Format("Rank: {0,2} {1,15} {2}",$rank, $entry, $_.Name)
}
</syntaxhighlight>
{{out}}
<pre>
Sample output on 05 juillet 2022 at 19:53 +02
Rank: 1 (1,552 entries) Phix
Rank: 2 (1,545 entries) Wren
Rank: 3 (1,521 entries) Julia
Rank: 4 (1,498 entries) Go
Rank: 5 (1,497 entries) Raku
Rank: 6 (1,456 entries) Perl
Rank: 7 (1,402 entries) Nim
Rank: 8 (1,401 entries) Python
Rank: 9 (1,206 entries) C
Rank: 10 (1,180 entries) J
</pre>
 
=={{header|PureBasic}}==
===Using MediaWiki API method===
<langsyntaxhighlight lang="purebasic">Procedure handleError(value, msg.s)
If value = 0
MessageRequester("Error", msg)
Line 3,865 ⟶ 4,298:
Print(#CRLF$ + #CRLF$ + "Press ENTER to exit"): Input()
CloseConsole()
EndIf</langsyntaxhighlight>
Sample output:
<pre>608 languages.
Line 3,933 ⟶ 4,366:
 
===Using web scraping method===
<langsyntaxhighlight lang="purebasic">
;Uses a web scraping method.
 
Line 3,989 ⟶ 4,422:
PrintN( Str(i + 1) + ". " + Str(Row(i)\count) + " - " + Row(i)\Name)
Next
Input()</langsyntaxhighlight>
Sample output:
<pre>1. 907 - Racket
Line 4,025 ⟶ 4,458:
 
===Python: Using web scraping===
{{works with|Python|3.5}}
Using <code>requests</code> library.
Scraping the languages and categories pages.
 
<langsyntaxhighlight lang="python">import requests
import re
 
LANGUAGES_URLresponse = requests.get("http://rosettacode.org/wiki/Category:Programming_Languages").text
languages = re.findall('title="Category:(.*?)">',response)[:-3] # strip last 3
CATEG_ENTRIES_URL = "http://rosettacode.org/mw/index.php?title=Special:Categories&limit=5000"
 
response = requests.get("http://rosettacode.org/mw/index.php?title=Special:Categories&limit=5000").text
languages_source = requests.get(LANGUAGES_URL).text
response = re.sub('(\d+),(\d+)',r'\1'+r'\2',response) # strip ',' from popular languages above 999 members
categ_entries_source = requests.get(CATEG_ENTRIES_URL).text
members = re.findall('<li><a[^>]+>([^<]+)</a>[^(]*[(](\\d+) member[s]*[)]</li>',response) # find language and members
 
for cnt, (language, members) in enumerate(sorted(members, key=lambda x: -int(x[1]))[:15]): # show only top 15 languages
raw_languages = re.findall('title="Category:(.+?)">', languages_source)
# remove dumb if language entriesin languages:
print("{:4d} {:4d} - {}".format(cnt+1, int(members), language))
languages = [lang for lang in raw_languages
if lang not in ('Languages', 'Static Category Cache', 'Encyclopedia')]
 
</syntaxhighlight>
categ_entries = re.findall(
{{out|Output (as of Dec 21, 2020)}}
'<li><a[^>]+>([^<]+)</a>[^(]*[(](\\d+) member[s]*[)]</li>',
1 1306 - Go
categ_entries_source)
2 1275 - Phix
3 1265 - Julia
4 1257 - Raku
5 1196 - Python
6 1182 - Perl
7 1107 - Kotlin
8 1080 - C
9 1074 - Java
10 1061 - Racket
11 1022 - REXX
12 1012 - Zkl
13 1002 - J
14 983 - Ruby
15 972 - Haskell
 
===Python: Using MediaWiki API method===
lang_entries = [(categ, int(entries))
<syntaxhighlight lang="python">
for categ, entries in categ_entries if categ in languages]
import requests
sorted_lang_entries = sorted(lang_entries, key=lambda x: -x[1])
import operator
import re
 
api_url = 'http://rosettacode.org/mw/api.php'
for i, (lang, entries) in enumerate(sorted_lang_entries):
languages = {}
print("{:4d}. {:4d} - {}".format(i+1, entries, lang))</lang>
 
parameters = {
{{out|Output (as of Jul 17, 2016)}}
1. 'format': 908 - Racket 'json',
2. 'action': 899 - Tcl 'query',
'generator': 'categorymembers',
3. 880 - Python
'gcmtitle': 'Category:Programming Languages',
4. 853 - J
5. 'gcmlimit': 827 - Perl 6 '200',
'gcmcontinue': '',
6. 797 - Ruby
7. 'continue': 780 - C '',
'prop': 'categoryinfo'
8. 770 - Go
}
9. 767 - Java
10. 750 - D
11. 746 - REXX
12. 739 - Perl
13. 714 - Zkl
14. 713 - Haskell
15. 699 - PicoLisp
. . .
 
while(True):
===Python: not working===
response = requests.get(api_url, params=parameters).json()
{{improve|Python|This solution scrapes Special:Categories &limit 5000 which will break if the HTML style changes or the number of languages exceeds 5000. It could use the MediWiki API to get the language names and pages in a single call, in blocks of 500 until complete with no upper limit. See the [[Rosetta_Code/Rank_languages_by_popularity#AWK|Awk example]]. If you make an API-based version please retain the web-scrapping version in its own sub-section (following the lead of [[Rosetta_Code/Rank_languages_by_popularity#Tcl|TCL on this page]]).}}
for k,v in response['query']['pages'].items():
if 'title' in v and 'categoryinfo' in v:
languages[v['title']]=v['categoryinfo']['size']
if 'continue' in response:
gcmcontinue = response['continue']['gcmcontinue']
# print(gcmcontinue)
parameters.update({'gcmcontinue': gcmcontinue})
else:
break
 
# report top 15 languages
{{works with|Python|2.6}}
for i, (language, size) in enumerate(sorted(languages.items(), key=operator.itemgetter(1), reverse=True)[:15]):
This uses MediaWiki's JSON API to query the members of [[:Category:Programming Languages]] and then scrapes [[:Special:Categories]] for the number of pages in each language's category.
print("{:4d} {:4d} - {}".format(i+1, size, re.sub('Category:','',language))) # strip Category: from language
<lang python>import urllib, re
 
key1 = lambda x: int(x[1])
 
</syntaxhighlight>
get1 = urllib.urlopen("http://www.rosettacode.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:Programming_Languages&cmlimit=500&format=json").read()
{{out|Output (as of Dec 21, 2020)}}
get2 = urllib.urlopen("http://www.rosettacode.org/w/index.php?title=Special:Categories&limit=5000").read()
1 1306 - Go
 
2 1275 - Phix
langs = re.findall("\"title\":\"Category:(.+?)\"",get1)
3 1265 - Julia
qtdmbr = re.findall("title=\"Category:(.+?)\">.+?</a> \((\d+) members\)",get2)
4 1257 - Raku
 
5 1196 - Python
result = [(x,int(y)) for x,y in qtdmbr if x in langs]
6 1182 - Perl
 
7 1107 - Kotlin
for n, i in enumerate(sorted(result,key=key1,reverse=True)):
8 1080 - C
print "%3d. %3d - %s" % (n+1, i[1], i[0])</lang>
9 1074 - Java
{{out|Output (as of Sep 11, 2010)}}
1.10 4231061 - TclRacket
2.11 3941022 - PythonREXX
3.12 3681012 - JZkl
4.13 3651002 - PicoLispJ
5.14 362 983 - Ruby
6.15 355 972 - CHaskell
7. 351 - Haskell
8. 339 - OCaml
9. 316 - Perl
10. 315 - PureBasic
11. 306 - D
12. 302 - AutoHotkey
13. 300 - Common Lisp
14. 295 - Java
15. 293 - Ada
16. 278 - Oz
17. 260 - C++
18. 260 - C sharp
. . .
 
=={{header|R}}==
 
{{improve|R|It only finds 500 languages (which is the max 'gcmlimit' for a single API request), but there are now over 500 languages on Rosettacode. The code needs to be changed to make additional requests as needed.}}
<syntaxhighlight lang="rsplus">
<lang R>
library(rvest)
library(plyr)
library(dplyr)
options(stringsAsFactors=FALSE)
 
# getting the required table from the rosetta website
langUrl <- "http://rosettacode.org/mw/api.php?format=xml&action=query&generator=categorymembers&gcmtitle=Category:Programming%20Languages&prop=categoryinfo&gcmlimit=500"
langUrl <- "https://rosettacode.org/wiki/Rosetta_Code/Rank_languages_by_popularity/Full_list"
langs <- html(langUrl) %>%
langs <- read_html(langUrl) %>%
html_nodes('page')
html_nodes(xpath='/html/body/div/div/div[1]/div[3]/main/div[2]/div[3]/div[1]/table') %>%
html_table() %>%
data.frame() %>%
select(c("Rank","TaskEntries","Language"))
 
ff <- function(xml_node) {
language <- xml_node %>% html_attr("title")
language <- sub("^Category:", "", language)
npages <- xml_node %>% html_nodes('categoryinfo') %>%
html_attr("pages")
c(language, npages)
}
tbl <- ldply(sapply(langs, ff), rbind)
names(tbl) <- c("language", "n")
tbl %>%
mutate(n=as.integer(n)) %>%
arrange(desc(n)) %>%
head
</lang>
{{out|Output (as of July, 5, 2015)}}
<pre>
language n
1 Tcl 878
2 Racket 868
3 Python 837
4 J 787
5 Ruby 770
6 Perl 6 762
</pre>
 
# changing the columns to required format
langs$Rank = paste("Rank: ",langs$Rank)
langs$TaskEntries = paste0("(", format(langs$TaskEntries, big.mark = ",")
," entries", ")")
 
names(langs) <- NULL
{{incorrect|R|This solution fails if there are more than 500 users in a language, which is now the case for the top 25 languages as of May 2015.}}
<lang R>library(RJSONIO)
langUrl <- "http://rosettacode.org/mw/api.php?action=query&format=json&cmtitle=Category:Solutions_by_Programming_Language&list=categorymembers&cmlimit=500"
 
langs[1:10,]
languages <- fromJSON(langUrl)$query$categorymembers
languages <- sapply(languages, function(x) sub("Category:", "", x$title))
 
</syntaxhighlight>
# fails if there are more than 500 users per language
{{out|Output (as of October, 24, 2022)}}
user <- function (lang) {
userBaseUrl <- "http://rosettacode.org/mw/api.php?action=query&format=json&list=categorymembers&cmlimit=500&cmtitle=Category:"
userUrl <- paste(userBaseUrl, URLencode(paste(lang, " User", sep="")),sep="")
length(fromJSON(userUrl)$query$categorymembers)
}
 
users <- sapply(languages, user)
head(sort(users, decreasing=TRUE),15)</lang>
{{out|Output (as of March, 13, 2010)}}
<pre>
1 Rank: 1 (1,589 entries) Phix
C C++ Java Python JavaScript Perl UNIX Shell
2 Rank: 1 (1,589 entries) Wren
55 55 37 32 27 27 22
3 Rank: 3 (1,552 entries) Julia
Pascal BASIC PHP SQL Haskell AWK C sharp
4 Rank: 4 (1,535 entries) Raku
20 19 19 18 17 16 16
5 Rank: 5 (1,500 entries) Go
Ruby
6 Rank: 6 (1,485 entries) 14 Perl
7 Rank: 7 (1,422 entries) Python
8 Rank: 8 (1,402 entries) Nim
9 Rank: 9 (1,293 entries) J
10 Rank: 10 (1,213 entries) C
</pre>
 
=={{header|Racket}}==
<lang racket>#lang racket
 
{{trans|Python}}
(require net/url)
(require json)
 
<syntaxhighlight lang="racket">#lang racket
(define proglangs_url "http://rosettacode.org/mw/api.php?action=query&list=categorymembers&cmtitle=Category:Programming_Languages&cmlimit=500&format=json")
(define categories_url "http://rosettacode.org/mw/index.php?title=Special:Categories&limit=5000")
(require racket/hash
net/url
json)
(define limit 15)
(define (replacer cat) (regexp-replace #rx"^Category:(.*?)$" cat "\\1"))
(define category "Category:Programming Languages")
(define entries "entries")
(define api-url (string->url "http://rosettacode.org/mw/api.php"))
(define (make-complete-url gcmcontinue)
(struct-copy url api-url
[query `([format . "json"]
[action . "query"]
[generator . "categorymembers"]
[gcmtitle . ,category]
[gcmlimit . "200"]
[gcmcontinue . ,gcmcontinue]
[continue . ""]
[prop . "categoryinfo"])]))
 
(define (fetch-json@ urlstringhash-ref)
(read-json (get-pure-port (string->url urlstring))))
 
(define programmingtable (make-languageshash))
(for/set ([h (in-list
(let loop ([gcmcontinue ""])
(hash-ref (hash-ref (fetch-json proglangs_url) 'query)
(define resp (read-json (get-pure-port (make-complete-url gcmcontinue))))
'categorymembers))])
(hash-union! table
(substring (hash-ref h 'title) 9)))
(for/hash ([(k v) (in-hash (@ (@ resp 'query) 'pages))])
(values (@ v 'title #f) (@ (@ v 'categoryinfo (hash)) 'size 0))))
(cond [(@ resp 'continue #f) => (λ (c) (loop (@ c 'gcmcontinue)))]))
(for/fold ([prev #f] [rank #f] #:result (void))
([item (in-list (sort (hash->list table) > #:key cdr))] [i (in-range limit)])
(match-define (cons cat size) item)
(define this-rank (if (equal? prev size) rank (add1 i)))
(printf "Rank: ~a ~a ~a\n"
(~a this-rank #:align 'right #:min-width 2)
(~a (format "(~a ~a)" size entries) #:align 'right #:min-width 14)
(replacer cat))
(values size this-rank))</syntaxhighlight>
 
Output on September 4, 2019:
(define result '())
(for ([l (in-port read-line (get-pure-port (string->url categories_url)))])
(let ([res (regexp-match #px"title=\"Category:(.+?)\".+\\((\\d+) member" l)])
(when (and res (set-member? programming-languages (cadr res)))
(set! result (cons (cons (cadr res)
(string->number (caddr res)))
result)))))
 
<pre>
(printf "Place\tCount\tName~n")
Rank: 1 (1176 entries) Go
(for ([lang (in-list (sort result > #:key cdr))]
Rank: 2 (1112 entries) Phix
[place (in-naturals 1)])
Rank: 3 (1107 entries) Perl 6
(printf "~a\t~a\t~a~n" place (cdr lang) (car lang)))
Rank: 4 (1099 entries) Julia
</lang>
Rank: 5 (1079 entries) Python
Output, 2013-5-25:
Rank: 6 (1053 entries) Kotlin
<pre>Place Count Name
Rank: 7 (1038 entries) Racket
1 737 Tcl
Rank: 8 (1037 entries) Perl
2 676 Python
Rank: 9 (968 entries) C
3 660 C
Rank: 10 (960 entries) Zkl
4 638 J
Rank: 11 (945 entries) J
5 626 PicoLisp
Rank: 12 (935 entries) REXX
6 609 Perl 6
Rank: 13 (930 entries) Tcl
7 609 D
Rank: 14 (910 entries) Java
8 601 Racket
Rank: 15 (904 entries) Ruby
9 592 Ruby
10 589 Go
...
</pre>
 
Recent, occasionally (hourly-ish) updated output also available at:
http://www.timb.net/popular-languages.html.
 
=={{header|Raku}}==
(formerly Perl 6)
 
===Raku: Using the API===
Note that this counts '''only''' the tasks. It does not include other non-task categories in the counts yielding more realistic, non-inflated numbers. Raku is Unicode aware and handles non-ASCII names natively. This does not attempt to 'unify' different language names that are the same behind the scenes as a result of Rosettacodes' capitalization peculiarities. (E.G. μC++, UC++ & ΜC++)
 
<syntaxhighlight lang="raku" line>use HTTP::UserAgent;
use URI::Escape;
use JSON::Fast;
use Sort::Naturally;
 
my $client = HTTP::UserAgent.new;
 
my $url = 'https://rosettacode.org/w';
 
my $tablefile = './RC_Popularity.txt';
 
my %cat = (
'Programming_Tasks' => 'Task',
'Draft_Programming_Tasks' => 'Draft'
);
my %tasks;
 
for %cat.keys.sort -> $cat {
mediawiki-query(
$url, 'pages',
:generator<categorymembers>,
:gcmtitle("Category:$cat"),
:gcmlimit<350>,
:rawcontinue(),
:prop<title>
).map({ %tasks{%cat{$cat}}++ });
}
 
my %counts =
mediawiki-query(
$url, 'pages',
:generator<categorymembers>,
:gcmtitle<Category:Programming Languages>,
:gcmlimit<350>,
:rawcontinue(),
:prop<categoryinfo>
)
.map({
my $title = .<title>.subst(/^'Category:'/, '');
my $tasks = (.<categoryinfo><pages> || 0);
my $categories = (.<categoryinfo><subcats> || 0);
my $total = (.<categoryinfo><size> || 0);
$title => [$tasks ,$categories, $total]
});
 
my $out = open($tablefile, :w) or die "$!\n";
 
# Add table boilerplate and header
$out.say:
"\{|class=\"wikitable sortable\"\n",
"|+ As of { Date.today } :: {+%counts} Languages\n",
'!Rank!!Language!!Task<br>Entries!!Tasks<br>done %!!Non-task<br>Subcate-<br>gories!!Total<br>Categories'
;
 
my @bg = <#fff; #ccc;>;
my $ff = 0;
my $rank = 1;
my $ties = 0;
 
# Get sorted unique task counts
for %counts.values»[0].unique.sort: -* -> $count {
$ff++;
# Get list of tasks with this count
my @these = %counts.grep( *.value[0] == $count )».keys.sort: *.&naturally;
 
for @these {
$ties++;
$out.say:
"|- style=\"background-color: { @bg[$ff % 2] }\"\n"~
"|$rank\n"~
"|[[:Category:$_|]]\n"~
"|$count\n"~
"|{(100 * $count/%tasks<Draft Task>.sum).round(.01)} %\n"~
"|{%counts{$_}[1]}\n"~
"|{%counts{$_}[2]}"
}
$rank += $ties;
$ties = 0;
}
$out.say( "|}" );
$out.say('=' x 5, " query, download & processing: {(now - INIT now).round(.01)} seconds ", '=' x 5);
$out.close;
 
sub mediawiki-query ($site, $type, *%query) {
my $url = "$site/api.php?" ~ uri-query-string(
:action<query>, :format<json>, :formatversion<2>, |%query);
my $continue = '';
 
gather loop {
my $response = $client.get("$url&$continue");
my $data = from-json($response.content);
take $_ for $data.<query>.{$type}.values;
$continue = uri-query-string |($data.<query-continue>{*}».hash.hash or last);
}
}
 
sub uri-query-string (*%fields) {
join '&', %fields.map: { "{.key}={uri-escape .value}" }
}</syntaxhighlight>
 
{{out|Abridged output}} See [[Rosetta_Code/Rank_languages_by_popularity/Full_list|full output here]].
{|class="wikitable sortable"
|+ As of 2019-02-10 :: 715 Languages
!Rank!!Language!!Task<br>Entries!!Tasks<br>done %!!Non-task<br>Subcate-<br>gories!!Total<br>Categories
|- style="background-color: #ccc;"
|1
|[[:Category:Go|Go]]
|1100
|96.15 %
|4
|1104
|- style="background-color: #fff;"
|2
|[[:Category:Perl 6|Perl 6]]
|1046
|91.43 %
|4
|1050
|- style="background-color: #ccc;"
|3
|[[:Category:Kotlin|Kotlin]]
|1029
|89.95 %
|1
|1030
|- style="background-color: #fff;"
|4
|[[:Category:Python|Python]]
|1017
|88.9 %
|17
|1034
|- style="background-color: #ccc;"
|5
|[[:Category:Phix|Phix]]
|991
|86.63 %
|3
|994
|- style="background-color: #fff;"
|6
|[[:Category:Racket|Racket]]
|986
|86.19 %
|3
|989
|- style="background-color: #ccc;"
|7
|[[:Category:Perl|Perl]]
|963
|84.18 %
|5
|968
|- style="background-color: #fff;"
|8
|[[:Category:Julia|Julia]]
|958
|83.74 %
|3
|961
|- style="background-color: #ccc;"
|9
|[[:Category:C|C]]
|940
|82.17 %
|3
|943
|- style="background-color: #fff;"
|10
|[[:Category:Tcl|Tcl]]
|925
|80.86 %
|4
|929
|- style="background-color: #ccc;"
|11
|[[:Category:Zkl|Zkl]]
|918
|80.24 %
|1
|919
|- style="background-color: #fff;"
|12
|[[:Category:J|J]]
|901
|78.76 %
|3
|904
|- style="background-color: #ccc;"
|13
|[[:Category:Java|Java]]
|897
|78.41 %
|3
|900
|- style="background-color: #fff;"
|14
|[[:Category:REXX|REXX]]
|886
|77.45 %
|4
|890
|- style="background-color: #ccc;"
|15
|[[:Category:D|D]]
|871
|76.14 %
|3
|874
|- style="background-color: #fff;"
|16
|[[:Category:Ruby|Ruby]]
|866
|75.7 %
|3
|869
|- style="background-color: #ccc;"
|17
|[[:Category:Haskell|Haskell]]
|849
|74.21 %
|3
|852
|- style="background-color: #fff;"
|18
|[[:Category:Scala|Scala]]
|789
|68.97 %
|3
|792
|- style="background-color: #ccc;"
|19
|[[:Category:Sidef|Sidef]]
|787
|68.79 %
|1
|788
|- style="background-color: #fff;"
|20
|[[:Category:PicoLisp|PicoLisp]]
|772
|67.48 %
|3
|775
|}
 
===Raku: Using web scraping===
 
Scraping the languages and categories pages. Raku automatically handles Unicode names correctly.
<syntaxhighlight lang="raku" line>my $languages = qx{wget -O - 'http://rosettacode.org/wiki/Category:Programming_Languages'};
my $categories = qx{wget -O - 'http://www.rosettacode.org/mw/index.php?title=Special:Categories&limit=5000'};
my @lines = $languages.lines;
shift @lines until @lines[0] ~~ / '<h2>Subcategories</h2>' /;
my \languages = set gather for @lines {
last if / '/bodycontent' /;
take ~$0 if
/ '<li><a href="/wiki/Category:' .*? '" title="Category:' .*? '">' (.*?) '</a></li>' /;
}
@lines = $categories.lines;
my @results = sort -*.[0], gather for @lines {
take [+$1.subst(',', ''), ~$0] if
/ '<li><a href="/wiki/Category:' .*? '" title="Category:' .*? '">'
(.*?) <?{ ~$0 ∈ languages }>
'</a>' .*? '(' (<[, 0..9]>+) ' member' /;
}
for @results.kv -> $i, @l {
printf "%d:\t%4d - %s\n", $i+1, |@l;
}</syntaxhighlight>
{{out}}
(As of 2018-10-28) Here we show only the top 10.
<pre>1: 1036 - Go
2: 1029 - Kotlin
3: 1014 - Python
4: 998 - Perl 6
5: 980 - Racket
6: 929 - Tcl
7: 926 - C
8: 910 - Perl
9: 904 - Zkl
10: 901 - J</pre>
 
=={{header|Red}}==
proccesses only languages with more than 25 entries to keep the list short
<langsyntaxhighlight Redlang="red">Red []
 
data: read http://www.rosettacode.org/mw/index.php?title=Special:Categories&limit=5000
Line 4,277 ⟶ 5,001:
head? lb ;; until head reached
]
</syntaxhighlight>
</lang>
Output: (30.12.2017)
<pre>
Line 4,307 ⟶ 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,321 ⟶ 5,048:
 
Programming note: &nbsp; (REXX doesn't handle Unicode characters) &nbsp; some special cases that are translated:
:::* &nbsp; '''╬£C++''' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; translated into &nbsp; '''µC++''' &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; [Greek micro]
:::* &nbsp; '''╨£╨Ü-61/52''' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; translated into &nbsp; '''MK-61/52''' &nbsp; [Cyrillic &nbsp; '''МК-61/52'''])
:::* &nbsp; '''??-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=0;call eSort #,1 call reader 'languages' /*assign languages " ───► L.ααα " along with members. */
call out call reader 'categories' /*append categories ───► catHeap /*create the RC_POP.OUT (output) file.*/
#=exit 0 /*stick a fork /*thein numberit, of categorieswe're all (so far)done. */
do j=1 until catHeap=='' /*process the heap of categories. */
parse var catHeap cat.j (sep) catHeap /*get a category from the catHeap. */
parse var cat.j cat.j '<' "(" mems . /*untangle the strange-looking string. */
cat.j= space(cat.j); ?= cat.j; upper ? /*remove any superfluous blanks. */
if ?=='' | \L.? then iterate /*it's blank or it's not a language.*/
if pos(',', mems)\==0 then mems= changestr(",", mems, '') /*elide commas from #.*/
if \datatype(mems, 'W') then iterate /*is the "members" not numeric ? */
#.0= #.0 + mems /*bump the number of members found. */
if u.?\==0 then do; do f=1 for # until ?==@u.f; end /*f*/
#.f= #.f + mems; iterate j /*languages that're in different cases.*/
end /* [↑] handle any possible duplicates.*/
u.?= u.? + 1; #= # + 1 /*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 _; n do jc=length(_'.9';)-3 #=123456789; #0=#"0"to 1 by -3; #0._=#0'.';b=verify insert(n,#","M",_,jc); end; return _
s: if arg(1)==1 then return arg(3); return word(arg(2) 's',1) /*pluralizer.*/
e=verify(n,#0,,verify(n,#0.,'M'))-4; do j=e to b by -3; _=insert(",",_,j); end; return _
/*──────────────────────────────────────────────────────────────────────────────────────*/
eSort: procedure expose #. @. !tr.; arg N,p2; h= N h= N /*sort: number of members*/
do while h>1; h= h %2 2 /*halve number of records*/
do i=1 for N-h; j= i; k= h +i i /*sort this part of list.*/
if p2 then do while !tR.k==!tR.j & @.k>@.j /*this uses a hard swap ↓*/
@= @.j; #= !tR.j; @.j= @.k; !tR.j= !tR.k; @.k= @; !tR.k= #
if h>=j then leave; j= j - h; k= k - h
end /*while !tR.k==···*/
else do while #.k<#.j /*this uses a hard swap ↓*/
@= @.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
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 var catHeap cat.j (sep) catHeap /*get a category from the catHeap. */
Uyir = 'உயிர்/Uyir' /*Unicode (in text) name for Uyir */
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: it's MK- 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é */
old #.60= '??-61/52'#.0 + mems ; new.6= "MK-61/52" /*somewherebump past,the anumber mistranslated:of members found. MK- */
old.7= Formulae if ; newu.7?\==0 'Fôrmulæ' then do; /*Unicode do f=1 for # ───► ASCII─8:until Fôrmulæ*/?==@u.f
old.8= Uyir ; new.8= 'Uyir' /*Unicode ───► ASCII─8: Uyirend /*f*/
#.f= #.f + mems; iterate j /*languages in different cases.*/
end /* [↑] handle any possible duplicates.*/
u.?= u.? + 1; #= # + 1 /*bump a couple of counters. */
#.#= #.# + mems; @.#= cat.j; @u.#=? /*bump the counter; assign it (upper).*/
end /*j*/
 
!.=; do recs @tno=0 '(total) number of' while lines(inFID) \== 0 /*read a file, aarray singleholds lineindication atof aTIED timelangs.*/
call tell right(commas(#), 9) @tno 'languages detected in the category file'
$= translate( linein(inFID), , '9'x) /*handle any stray TAB ('09'x) chars.*/
call tell right(commas(langs),9) ' " " " " " " " language "
$$= space($); if $$=='' then iterate /*ignore all blank lines in the file(s)*/
call tell right(commas(#.0), 9) @tno 'entries (solutions) detected', , 1; term= 0
do v=1 while old.v \== '' /*translate Unicode variations of langs*/
return /*don't show any more msgs──►term. [↑] */
if pos(old.v, $$) \==0 then $$= changestr(old.v, $$, new.v)
/*──────────────────────────────────────────────────────────────────────────────────────*/
end /*v*/ /* [↑] handle different lang spellings*/
init: sep= '█'; L.=0; #.=0; u.=#.; catHeap=; term=1; old.= /*assign some REXX vars*/
if igAst then do; igAst= pos(' * ',$)==0; if igAst then iterate; end
if 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 681813 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>
[See the talk page about some programming languages using different cases (lower/upper/mixed) for the language names,
<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,536 ⟶ 5,273:
next
return alist
</syntaxhighlight>
</lang>
Output:
<pre>
Line 4,570 ⟶ 5,307:
 
Uses the <code>RosettaCode</code> module from [[Count programming examples#Ruby]]
<langsyntaxhighlight lang="ruby">require 'rosettacode'
 
langs = []
Line 4,599 ⟶ 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,631 ⟶ 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,658 ⟶ 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,694 ⟶ 5,431:
===Parallel internet querying===
Entry point @ object <code>GhettoParserPar</code>
<langsyntaxhighlight lang="scala">import akka.actor.{Actor, ActorSystem, Props}
import scala.collection.immutable.TreeSet
import scala.xml.XML
Line 4,838 ⟶ 5,575:
Concurrent.logInfo("Parallel version started")
ActorSystem("Main").actorOf(Props[Concurrent.Listener])
}</langsyntaxhighlight>
 
===Sequential internet querying===
Line 4,909 ⟶ 5,646:
 
=={{header|Seed7}}==
<langsyntaxhighlight lang="seed7">$ include "seed7_05.s7i";
include "gethttp.s7i";
include "scanstri.s7i";
Line 4,966 ⟶ 5,703:
place +:= length(ranking[numList[listIdx]]);
end for;
end func;</langsyntaxhighlight>
 
List of languages as of 2014-01-15:
Line 5,005 ⟶ 5,742:
=={{header|Sidef}}==
{{trans|Perl}}
<langsyntaxhighlight lang="ruby">require('MediaWiki::API')
 
var api = %O<MediaWiki::API>.new(
Line 5,041 ⟶ 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,066 ⟶ 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,085 ⟶ 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,095 ⟶ 5,832:
url.close(.fin)
end</langsyntaxhighlight>
 
'''Abridged output (top 30 languages as of August 25, 2015):'''
Line 5,134 ⟶ 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,168 ⟶ 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,202 ⟶ 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,245 ⟶ 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,274 ⟶ 6,011:
{{libheader|tDOM}}
 
<langsyntaxhighlight lang="tcl">package require Tcl 8.5
package require http
package require tdom
Line 5,383 ⟶ 6,120:
}
 
popreport $langcounts</langsyntaxhighlight>
 
{{out}}
Line 5,409 ⟶ 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,457 ⟶ 6,194:
balt=b
ENDLOOP
ENDCOMPILE</langsyntaxhighlight>
{{out}}
<pre style='height:30ex;overflow:scroll'>
Line 5,502 ⟶ 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,625 ⟶ 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,655 ⟶ 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,661 ⟶ 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,698 ⟶ 6,852:
println("Most popular Rosetta Code languages as of ",Time.Date.prettyDay());
foreach n,name in ([1..15].zip(langCounts))
{ println("%2d: %3d %s".fmt(n,name.xplode())) }</langsyntaxhighlight>
{{out}}
<pre>
153

edits