Rosetta Code/Rank languages by popularity: Difference between revisions

Undo revision 331877 by Blek (talk)
(Ranking updated)
(Undo revision 331877 by Blek (talk))
Line 8:
Sort the most popular computer programming languages based in number of members in Rosetta Code categories.
 
Sample output on 0403 MayApril 2021 at 1516:5033 +02:
<pre>Rank: 1 (1,355344 entries) PhixGo
Rank: 2 (1,350334 entries) GoPhix
Rank: 3 (1,347327 entries) Julia
Rank: 4 (1,325308 entries) Raku
Rank: 5 (1,279252 entries) Perl
Rank: 6 (1,237225 entries) Python
Rank: 7 (1,124120 entries) Kotlin
Rank: 8 (1,121110 entries) C
Rank: 9 (1,116095 entries) WrenJava
Rank: 10 (1,102070 entries) JavaWren
...</pre>
 
Line 2,224:
IF(pos > 0) THEN
READ(Text=members) count
IF(count > 0) TTHEN
nr = nr + 1
WRITE(Text=catlist, Format='i4, 1x, 2a', APPend) count, name, ';'
ENDIF
GOTO 1 ! no WHILE in HicEst
ENDIF ! catlist is now = " 1 ... User ; 2 100 doors ; 3 3D ; 8 4D ; ..."
 
ALLOCATE(RankNr, nr)
EDIT(Text=catlist, SePaRators=';', Option=1+4, SorTtoIndex=RankNr) ! case (1) and back (4)
 
sortedCat = ' ' ! get the sorted list in the sequence of RankNr:
ok = 0
DO i = 1, nr
EDIT(Text=catlist, SePaRators=';', ITeM=RankNr(i), CoPyto=sample)
discard = EDIT(Text=sample, LeXicon='user,attention,solutions,tasks,program,language,implementation,')
IF(discard == 0) THEN ! removes many of the non-language entries
ok = ok + 1
WRITE(Text=sortedCat, APPend, Format='F5.0, 2A') ok, TRIM(sample), $CRLF
ENDIF
ENDDO
DLG(Text=sortedCat, Format=$CRLF)
END</lang>
<lang hicest>2010-04-24 18:31
Top 10 entries (not all are languages)
1. 394 Tcl
2. 363 Python
3. 346 Ruby
4. 328 J
5. 319 C
6. 317 OCaml
7. 315 Haskell
8. 298 Perl
9. 288 WikiStubs
10. 281 Common Lisp</lang>
 
=={{header|Icon}} and {{header|Unicon}}==
===By using the API===
The following solution only works in Unicon.
 
<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/"
 
link strings
link hexcvt
 
procedure main()
cnt := create seq()
last := -1
every pair := !reverse(sort(langs := tallyPages(),2)) do {
n := if last ~=:= pair[2] then @cnt else (@cnt,"")
write(right(n,4),": ",left(pair[1],30,". "),right(pair[2],10,". "))
}
write(*langs, " languages")
end
 
# Generate page counts for each language
procedure tallyPages(url)
/url := RCLANGS
counts := table()
continue := ""
while \(txt := ReadURL(url||continue)) do {
txt ? {
if tab(find("gcmcontinue=")) then {
continue := "&"||tab(upto('"'))
move(1)
continue ||:= tab(upto('"'))
}
else continue := ""
while tab(find("<page ") & find(s := "title=\"Category:")+*s) do {
lang := tab(upto('"'))
tab(find(s := "pages=\"")+*s)
counts[lang] := numeric(tab(upto('"')))
}
if continue == "" then return counts
}
}
end
 
procedure ReadURL(url) #: read URL into string
page := open(url,"m",RCUA,RCXUA) | stop("Unable to open ",url)
text := ""
if page["Status-Code"] < 300 then while text ||:= reads(page,-1)
else write(&errout,image(url),": ",
page["Status-Code"]," ",page["Reason-Phrase"])
close(page)
return text
end</lang>
 
Abridged output (top 26 languages as of July 30, 2016):
<pre>
1: Racket. . . . . . . . . . . . . . . .904
2: Tcl . . . . . . . . . . . . . . . . .894
3: Python. . . . . . . . . . . . . . . .867
4: J . . . . . . . . . . . . . . . . . .852
5: Perl 6. . . . . . . . . . . . . . . .824
6: Ruby. . . . . . . . . . . . . . . . .796
7: C . . . . . . . . . . . . . . . . . .777
8: Go. . . . . . . . . . . . . . . . . .769
9: Java. . . . . . . . . . . . . . . . .764
10: D . . . . . . . . . . . . . . . . . .747
11: REXX. . . . . . . . . . . . . . . . .743
12: Perl. . . . . . . . . . . . . . . . .736
13: Haskell . . . . . . . . . . . . . . .712
: Zkl . . . . . . . . . . . . . . . . .712
15: PicoLisp. . . . . . . . . . . . . . .695
16: Mathematica . . . . . . . . . . . . .686
17: Sidef . . . . . . . . . . . . . . . .632
18: Ada . . . . . . . . . . . . . . . . .626
19: C++ . . . . . . . . . . . . . . . . .619
20: AutoHotkey. . . . . . . . . . . . . .603
21: Unicon. . . . . . . . . . . . . . . .578
22: Common Lisp . . . . . . . . . . . . .577
23: Scala . . . . . . . . . . . . . . . .561
24: BBC BASIC . . . . . . . . . . . . . .535
25: C sharp . . . . . . . . . . . . . . .529
26: Icon. . . . . . . . . . . . . . . . .520
...
604 languages
</pre>
 
=={{header|J}}==
{{works with|J|6.02 (32 bit only)}}
'''Solution''':<lang j>require 'web/gethttp xml/sax/x2j regex'
 
x2jclass 'rcPopLang'
 
rx =: (<0 1) {:: (2#a:) ,~ rxmatches rxfrom ]
 
'Popular Languages' x2jDefn
/ := langs : langs =: 0 2 $ a:
html/body/div/div/div/ul/li := langs =: langs ,^:(a:~:{.@[)~ lang ; ' \((\d+) members?\)' rx y
html/body/div/div/div/ul/li/a := lang =: '^\s*((?:.(?!User|Tasks|Omit|attention|operations|by))+)\s*$' rx y
)
 
cocurrent'base'
 
sortTab =. \: __ ". [: ;:^:_1: {:"1
formatTab =: [: ;:^:_1: [: (20 A. (<'-') , |. , [: ('.' <"1@:,.~ ":) 1 + 1 i.@,~ 1{$)&.|: sortTab f.
 
rcPopLangs =: formatTab@:process_rcPopLang_@:gethttp</lang>
'''Example''':<lang j> 10 {. rcPopLangs 'http://www.rosettacode.org/w/index.php?title=Special:Categories&limit=2000'
1. 687 - Tcl
2. 646 - Python
3. 637 - C
4. 626 - PicoLisp
5. 612 - J
6. 587 - Go
7. 556 - Ada
8. 550 - D
9. 549 - Mathematica
10. 526 - Perl</lang>
'''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.
<lang java>import java.net.URL;
import java.net.URLConnection;
import java.io.*;
import java.util.*;
 
public class GetRCLanguages
{
// Custom sort Comparator for sorting the language list
// assumes the first character is the page count and the rest is the language name
private static class LanguageComparator implements Comparator<String>
{
public int compare( String a, String b )
{
// as we "know" we will be comparaing languages, we will assume the Strings have the appropriate format
int result = ( b.charAt( 0 ) - a.charAt( 0 ) );
if( result == 0 )
{
// the counts are the same - compare the names
result = a.compareTo( b );
} // if result == 0
return result;
} // compare
} // LanguageComparator
 
// get the string following marker in text
private static String after( String text, int marker )
{
String result = "";
int pos = text.indexOf( marker );
if( pos >= 0 )
{
// the marker is in the string
result = text.substring( pos + 1 );
} // if pos >= 0
return result;
} // after
 
// read and parse the content of path
// results returned in gcmcontinue and languageList
public static void parseContent( String path
, String[] gcmcontinue
, ArrayList<String> languageList
)
{
try
{
 
URL url = new URL( path );
URLConnection rc = url.openConnection();
// Rosetta Code objects to the default Java user agant so use a blank one
rc.setRequestProperty( "User-Agent", "" );
BufferedReader bfr = new BufferedReader( new InputStreamReader( rc.getInputStream() ) );
gcmcontinue[0] = "";
String languageName = "?";
String line = bfr.readLine();
while( line != null )
{
line = line.trim();
if ( line.startsWith( "[title]" ) )
{
// have a programming language - should look like "[title] => Category:languageName"
languageName = after( line, ':' ).trim();
}
else if( line.startsWith( "[pages]" ) )
{
// number of pages the language has (probably)
String pageCount = after( line, '>' ).trim();
if( pageCount.compareTo( "Array" ) != 0 )
{
// haven't got "[pages] => Array" - must be a number of pages
languageList.add( ( (char) Integer.parseInt( pageCount ) ) + languageName );
languageName = "?";
} // if [pageCount.compareTo( "Array" ) != 0
}
else if( line.startsWith( "[gcmcontinue]" ) )
{
// have an indication of wether there is more data or not
gcmcontinue[0] = after( line, '>' ).trim();
} // if various line starts
line = bfr.readLine();
} // while line != null
bfr.close();
}
catch( Exception e )
{
e.printStackTrace();
} // try-catch
} // parseContent
 
public static void main( String[] args )
{
// get the languages
ArrayList<String> languageList = new ArrayList<String>( 1000 );
String[] gcmcontinue = new String[1];
gcmcontinue[0] = "";
do
{
String path = ( "http://www.rosettacode.org/mw/api.php?action=query"
+ "&generator=categorymembers"
+ "&gcmtitle=Category:Programming%20Languages"
+ "&gcmlimit=500"
+ ( gcmcontinue[0].compareTo( "" ) == 0 ? "" : ( "&gcmcontinue=" + gcmcontinue[0] ) )
+ "&prop=categoryinfo"
+ "&format=txt"
);
parseContent( path, gcmcontinue, languageList );
}
while( gcmcontinue[0].compareTo( "" ) != 0 );
// sort the languages
String[] languages = languageList.toArray(new String[]{});
Arrays.sort( languages, new LanguageComparator() );
// print the languages
int lastTie = -1;
int lastCount = -1;
for( int lPos = 0; lPos < languages.length; lPos ++ )
{
int count = (int) ( languages[ lPos ].charAt( 0 ) );
System.out.format( "%4d: %4d: %s\n"
, 1 + ( count == lastCount ? lastTie : lPos )
, count
, languages[ lPos ].substring( 1 )
);
if( count != lastCount )
{
lastTie = lPos;
lastCount = count;
} // if count != lastCount
} // for lPos
} // main
} // GetRCLanguages</lang>
{{out}}
Top 10 languages as at 27th August 2015
<pre>
1: 883: Tcl
2: 875: Racket
3: 837: Python
4: 799: J
5: 772: Ruby
6: 763: Perl 6
7: 756: C
8: 742: Go
9: 737: D
10: 707: Perl
...
</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.
<lang sh>#!/bin/bash
 
# produce lines of the form: [ "language", n ]
function categories {
curl -Ss 'http://rosettacode.org/mw/index.php?title=Special:Categories&limit=5000' |\
grep "/wiki/Category:" | grep member | grep -v '(.*(' |\
grep -v ' User</a>' |\
sed -e 's/.*title="Category://' -e 's/member.*//' |\
sed 's:^\([^"]*\)"[^(]*(\(.*\):["\1", \2]:'
}
 
# produce lines of the form: "language"
function languages {
curl -Ss 'http://rosettacode.org/wiki/Category:Programming_Languages' |\
sed '/Pages in category "Programming Languages"/,$d' |\
grep '<li><a href="/wiki/Category:' | fgrep title= |\
sed 's/.*Category:\([^"]*\)".*/"\1"/'
}
 
categories |\
/usr/local/bin/jq --argfile languages <(languages) -s -r '
 
# input: array of [score, _] sorted by score
# output: array of [ranking, score, _]
def ranking:
reduce .[] as $x
([]; # array of [count, rank, score, _]
if length == 0 then [[1, 1] + $x]
else .[length - 1] as $previous
| if $x[0] == $previous[2]
then . + [ [$previous[0] + 1, $previous[1]] + $x ]
else . + [ [$previous[0] + 1, $previous[0] + 1] + $x ]
end
end)
| [ .[] | .[1:] ];
 
# Every language page has three category pages that should be excluded
(reduce .[] as $pair
({};
($pair[1] as $n | if $n > 3 then . + {($pair[0]): ($n - 3)} else . end ))) as $freq
| [ $languages[] | select($freq[.] != null) | [$freq[.], .]]
| sort
| reverse
| ranking[]
| "\(.[0]). \(.[1]) - \(.[2])" '</lang>
{{out}}
<lang sh># First ten and last ten lines as of May 27, 2015
$ pop.sh
1. 868 - Tcl
2. 863 - Racket
3. 842 - Python
4. 778 - J
5. 769 - Ruby
6. 756 - Perl 6
7. 752 - C
8. 736 - D
9. 735 - Go
10. 700 - Perl
...
386. 1 - FP
386. 1 - ElastiC
386. 1 - ESQL
386. 1 - Clipper/XBase++
386. 1 - Bori
386. 1 - Biferno
386. 1 - AspectJ
386. 1 - Algae
386. 1 - 80386 Assembly
386. 1 - 68000 Assembly</lang>
 
=={{header|Julia}}==
<lang julia>using HTTP
 
try
response = HTTP.request("GET", "http://rosettacode.org/mw/index.php?title=Special:Categories&limit=5000")
langcount = Dict{String, Int}()
for mat in eachmatch(r"<li><a href[^\>]+>([^\<]+)</a>[^1-9]+(\d+)[^\w]+member.?.?</li>", String(response.body))
if match(r"^Programming", mat.captures[1]) == nothing
langcount[mat.captures[1]] = parse(Int, mat.captures[2])
end
end
langs = sort(collect(keys(langcount)), lt=(x, y)->langcount[x]<langcount[y], rev=true)
for (i, lang) in enumerate(langs)
println("Language $lang can be ranked #$i at $(langcount[lang]).")
end
catch y
println("HTTP request failed: $y.")
exit()
end
</lang>{{out}
<pre>
Language Phix can be ranked #1 at 995.
Language Racket can be ranked #2 at 989.
Language Perl can be ranked #3 at 969.
Language Julia can be ranked #4 at 968.
Language C can be ranked #5 at 944.
Language Tcl can be ranked #6 at 930.
Language Zkl can be ranked #7 at 919.
Language J can be ranked #8 at 905.
Language Java can be ranked #9 at 900.
Language REXX can be ranked #10 at 892.
Language D can be ranked #11 at 874.
Language Ruby can be ranked #12 at 869.
Language Haskell can be ranked #13 at 853.
Language Scala can be ranked #14 at 792.
Language Sidef can be ranked #15 at 788.
Language PicoLisp can be ranked #16 at 775.
Language C sharp can be ranked #17 at 763.
Language Mathematica can be ranked #18 at 743.
Language C++ can be ranked #19 at 738.
Language Common Lisp can be ranked #20 at 667.
Language Ada can be ranked #21 at 656.
Language AutoHotkey can be ranked #22 at 628.
Language JavaScript can be ranked #23 at 619.
Language Lua can be ranked #24 at 618.
Language WikiStubs can be ranked #25 at 614.
...
</pre>
 
===Julia: Using web scraping===
{{trans|Python}}
<lang Julia>
using HTTP, Dates
response = HTTP.request("GET", "http://rosettacode.org/wiki/Category:Programming_Languages")
languages = Set(m.captures[1] for m in eachmatch(r"title=\"Category:(.*?)\">",String(response.body)))
response = HTTP.request("GET", "http://rosettacode.org/mw/index.php?title=Special:Categories&limit=5000")
response = replace(String(response.body),"," => "")
reg = r"<li><a[^>]+>([^<]+)</a>[^(]*[\(](\d+) member[s]?[)]</li>"
ms = eachmatch(reg,response)
members = [[1,parse(Int,m.captures[2]),m.captures[1]] for m in ms]
filter!(x -> x[3] in languages, members)
sort!(members, by = x -> (-x[2],x[3]))
for i in 2:length(members)
if members[i-1][2] == members[i][2]
members[i][1] = members[i-1][1]
else
members[i][1] = i
end
end
println("Sample output on ", Dates.day(now()), " ", Dates.monthname(now()), " ", Dates.year(now()), ":\n")
for (rank,entries,name) in members[1:10]
println("Rank: ", lpad(rank,4), lpad(" ($entries entries) ",16), name)
end
</lang>
{{out}}
<pre>
Sample output on 22 July 2019:
 
Rank: 1 (1154 entries) Go
Rank: 2 (1089 entries) Perl 6
Rank: 3 (1070 entries) Julia
Rank: 4 (1066 entries) Python
Rank: 5 (1062 entries) Phix
Rank: 6 (1045 entries) Kotlin
Rank: 7 (1026 entries) Perl
Rank: 8 (991 entries) Racket
Rank: 9 (952 entries) C
Rank: 10 (945 entries) J
</pre>
 
=={{header|Kotlin}}==
{{trans|Java}}
<lang scala>import java.net.URL
import java.io.*
 
object Popularity {
/** Gets language data. */
fun ofLanguages(): List<String> {
val languages = mutableListOf<String>()
var gcm = ""
do {
val path = url + (if (gcm == "") "" else "&gcmcontinue=" + gcm) + "&prop=categoryinfo" + "&format=txt"
try {
val rc = URL(path).openConnection() // URL completed, connection opened
// Rosetta Code objects to the default Java user agent so use a blank one
rc.setRequestProperty("User-Agent", "")
val bfr = BufferedReader(InputStreamReader(rc.inputStream))
try {
gcm = ""
var languageName = "?"
var line: String? = bfr.readLine()
while (line != null) {
line = line.trim { it <= ' ' }
if (line.startsWith("[title]")) {
// have a programming language - should look like "[title] => Category:languageName"
languageName = line[':']
} else if (line.startsWith("[pages]")) {
// number of pages the language has (probably)
val pageCount = line['>']
if (pageCount != "Array") {
// haven't got "[pages] => Array" - must be a number of pages
languages += pageCount.toInt().toChar() + languageName
languageName = "?"
}
} else if (line.startsWith("[gcmcontinue]"))
gcm = line['>'] // have an indication of whether there is more data or not
line = bfr.readLine()
}
} finally {
bfr.close()
}
} catch (e: Exception) {
e.printStackTrace()
}
} while (gcm != "")
 
return languages.sortedWith(LanguageComparator)
}
 
/** Custom sort Comparator for sorting the language list.
* Assumes the first character is the page count and the rest is the language name. */
internal object LanguageComparator : java.util.Comparator<String> {
override fun compare(a: String, b: String): Int {
// as we "know" we will be comparing languages, we will assume the Strings have the appropriate format
var r = b.first() - a.first()
return if (r == 0) a.compareTo(b) else r
// r == 0: the counts are the same - compare the names
}
}
 
/** Gets the string following marker in text. */
private operator fun String.get(c: Char) = substringAfter(c).trim { it <= ' ' }
 
private val url = "http://www.rosettacode.org/mw/api.php?action=query" +
"&generator=categorymembers" + "&gcmtitle=Category:Programming%20Languages" +
"&gcmlimit=500"
}
 
fun main(args: Array<String>) {
// read/sort/print the languages (CSV format):
var lastTie = -1
var lastCount = -1
Popularity.ofLanguages().forEachIndexed { i, lang ->
val count = lang.first().toInt()
if (count == lastCount)
println("%12s%s".format("", lang.substring(1)))
else {
println("%4d, %4d, %s".format(1 + if (count == lastCount) lastTie else i, count, lang.substring(1)))
lastTie = i
lastCount = count
}
}
}</lang>
{{out}}
<pre> 1, 901, Racket
2, 893, Tcl
3, 851, Python
4, 826, J
5, 796, Perl 6
...
135, 70, Kotlin
...</pre>
 
=={{header|Lasso}}==
<lang Lasso><pre><code>[
sys_listtraits !>> 'xml_tree_trait' ? include('xml_tree.lasso')
local(lang = array)
local(f = curl('http://rosettacode.org/mw/index.php?title=Special:Categories&limit=5000')->result->asString)
local(ff) = xml_tree(#f)
local(lis = #ff->body->div(3)->div(3)->div(3)->div->ul->getnodes)
with li in #lis do => {
local(title = #li->a->attribute('title'))
#title->removeLeading('Category:')
local(num = #li->asString->split('(')->last)
#num->removeTrailing(')')
#num->removeTrailing('members')
#num->removeTrailing('member')
#num->trim
#num = integer(#num)
#lang->insert(#title = #num)
}
local(c = 1)
with l in #lang
order by #l->second descending
do => {^
#c++
'. '+#l->second + ' - ' + #l->first+'\r'
^}
]</code></pre></lang>
 
{{out}}
<pre>1. 759 - Tcl
2. 724 - Racket
3. 707 - Python
4. 692 - Programming Tasks
5. 672 - C
6. 643 - J
7. 635 - Perl 6
8. 632 - D
9. 627 - PicoLisp
10. 617 - Ruby
...</pre>
 
=={{header|M2000 Interpreter}}==
Based on BBC BASIC idea, and using M2000 Rinstr() and objects as Inventories, Document, and Microsoft.XMLHTTP for downloading (async use). Results also copy to Clipboard. We can use Msxml2.ServerXMLHTTP (code is the same, only name of object change).
 
Update: Numbers above 999 get a comma (,) so we have to drop this using Filter$()
 
<lang M2000 Interpreter>
Module RankLanguages {
Const Part1$="<a href="+""""+ "/wiki/Category", Part2$="member"
Const langHttp$="http://rosettacode.org/wiki/Category:Programming_Languages"
Const categoriesHttp$="http://www.rosettacode.org/mw/index.php?title=Special:Categories&limit=5000"
Def long m, i,j, tasks, counter, limit, T, t1
Def string LastLang$, job$
Document final$, languages$, categories$
httpGet$=lambda$ (url$, timeout=1000)->{
Declare htmldoc "Msxml2.ServerXMLHTTP"
With htmldoc , "readyState" as ready
Report "Download:"+url$
Method htmldoc "open","get", url$, True
Method htmldoc "send"
Profiler
While Ready<>4 {
Wait 20
Print Over format$("Wait: {0:3} sec", timecount/1000)
If timecount>timeout then Exit
}
If ready=4 Then With htmldoc, "responseText" as ready$ : =ready$
Declare htmldoc Nothing
print
}
languages$=httpGet$(langHttp$, 30000)
If Doc.Len(languages$)=0 then Error "File download failed (languages)"
Inventory Lang
m=Paragraph(languages$, 0)
If Forward(languages$,m) then {
While m {
job$=Paragraph$(languages$,(m))
If Instr(job$, part1$) Else Continue
i = Instr(job$, "</a>")
If i Else Continue ' same as If i=0 Then Continue
j = i
i=Rinstr(job$, ">", -i)
If i Else Continue
LastLang$=MID$(job$, i+1, j-i-1)
if Instr(job$, "Category:"+lastlang$) then Append lang, lastlang$:=0 : Print Over format$("Languages: {0}", len(lang))
}
}
Print
Document categories$=httpGet$(categoriesHttp$, 30000)
If Doc.Len(categories$)=0 then Error "File download failed (categories)"
limit=Doc.Par(categories$)
If limit<Len(Lang) then Error "Invalid data"
Refresh
set slow
m=Paragraph(categories$, 0)
counter=0
If Forward(categories$,m) then {
While m {
job$=Paragraph$(categories$,(m))
counter++
Print Over format$("{0:2:-6}%", counter/limit*100)
i=Instr(job$, part2$)
If i Else Continue
i=Rinstr(job$, "(", -i)
If i Else Continue
tasks=Val(Filter$(Mid$(job$, i+1),","))
If tasks Else Continue
i=Rinstr(job$, "<", -i)
If i Else Continue
j = i
i=Rinstr(job$, ">", -i)
If i Else Continue
LastLang$=MID$(job$, i+1, j-i-1)
If Exist(Lang, LastLang$) Then {
Return Lang, LastLang$:=Lang(LastLang$)+tasks
}
}
}
Print
\\ this type of inventory can get same keys
\\ also has stable sort
Report "Make Inventory list by Task"
Inventory queue ByTask
t1=Len(Lang)
T=Each(Lang)
While T {
Append ByTask, Eval(T):=Eval$(T!)
Print Over format$("Complete: {0} of {1}", T^+1, t1 )
}
Print
Report "Sort by task (stable sort, sort keys as numbers)"
Sort descending ByTask as number
Report "Make List"
T=Each(ByTask)
final$="Sample output on "+Date$(Today, 1033, "long date")+{:
}
While T {
final$=format$("rank:{0::-4}. {1:-5} entries - {2}", T^+1, Eval$(T!), Eval$(T))+{
}
}
Report "Copy to Clipboard"
clipboard final$
\\ present to console with 3/4 fill lines then stop for space bar or mouse click to continue
Report final$
}
RankLanguages
</lang>
 
{{out}}
<pre style="height:30ex;overflow:scroll">
Sample output on Saturday, June 22, 2019:
rank: 1. 1149 entries - Go
rank: 2. 1084 entries - Perl 6
rank: 3. 1061 entries - Python
rank: 4. 1045 entries - Kotlin
rank: 5. 1044 entries - Julia
rank: 6. 1033 entries - Phix
rank: 7. 1026 entries - Perl
rank: 8. 991 entries - Racket
rank: 9. 951 entries - C
rank: 10. 944 entries - J
rank: 11. 938 entries - Zkl
rank: 12. 930 entries - Tcl
rank: 13. 910 entries - REXX
rank: 14. 909 entries - Java
rank: 15. 883 entries - Ruby
rank: 16. 881 entries - D
rank: 17. 869 entries - Haskell
rank: 18. 814 entries - Sidef
rank: 19. 801 entries - Scala
rank: 20. 779 entries - C sharp
rank: 21. 775 entries - PicoLisp
rank: 22. 772 entries - C++
rank: 23. 748 entries - Mathematica
rank: 24. 678 entries - Common Lisp
rank: 25. 668 entries - Ada
rank: 26. 639 entries - JavaScript
rank: 27. 633 entries - Lua
rank: 28. 628 entries - AutoHotkey
rank: 29. 611 entries - Ring
rank: 30. 595 entries - Factor
rank: 31. 594 entries - Clojure
rank: 32. 590 entries - Unicon
rank: 33. 566 entries - ALGOL 68
rank: 34. 563 entries - Nim
rank: 35. 563 entries - PureBasic
rank: 36. 560 entries - BBC BASIC
rank: 37. 559 entries - Fortran
rank: 38. 556 entries - OCaml
rank: 39. 540 entries - PARI/GP
rank: 40. 538 entries - F Sharp
rank: 41. 532 entries - Icon
rank: 42. 517 entries - Elixir
rank: 43. 497 entries - FreeBASIC
rank: 44. 495 entries - Erlang
rank: 45. 485 entries - Rust
rank: 46. 473 entries - PowerShell
rank: 47. 462 entries - Jq
rank: 48. 456 entries - Pascal
rank: 49. 453 entries - AWK
rank: 50. 450 entries - Forth
rank: 51. 448 entries - Seed7
rank: 52. 435 entries - R
rank: 53. 414 entries - Groovy
rank: 54. 403 entries - PL/I
rank: 55. 401 entries - PHP
rank: 56. 383 entries - VBA
rank: 57. 361 entries - Scheme
rank: 58. 359 entries - MATLAB
rank: 59. 353 entries - Swift
rank: 60. 346 entries - M2000 Interpreter
rank: 61. 343 entries - Maple
rank: 62. 337 entries - Liberty BASIC
rank: 63. 314 entries - Run BASIC
rank: 64. 309 entries - Prolog
 
..........
rank: 685. 1 entries - Jacquard Loom
rank: 686. 1 entries - Kamailio Script
rank: 687. 1 entries - Lambda Prolog
rank: 688. 1 entries - LibreOffice Basic
rank: 689. 1 entries - MAPPER
rank: 690. 1 entries - MEL
rank: 691. 1 entries - MiniZinc
rank: 692. 1 entries - Mond
rank: 693. 1 entries - Monkey
rank: 694. 1 entries - NASL
rank: 695. 1 entries - Neat
rank: 696. 1 entries - NewtonScript
rank: 697. 1 entries - Nickle
rank: 698. 1 entries - Nix
rank: 699. 1 entries - Opa
rank: 700. 1 entries - Pare
rank: 701. 1 entries - Qore
rank: 702. 1 entries - Rapira
rank: 703. 1 entries - RPGIV
rank: 704. 1 entries - Setl4
rank: 705. 1 entries - Soar
rank: 706. 1 entries - SoneKing Assembly
rank: 707. 1 entries - Supernova
rank: 708. 1 entries - SuperTalk
rank: 709. 1 entries - Terra
rank: 710. 1 entries - TestML
rank: 711. 1 entries - WebAssembly
rank: 712. 1 entries - Wollok
rank: 713. 1 entries - Xanadu
rank: 714. 1 entries - Ya
rank: 715. 1 entries - МiniZinc
rank: 716. 0 entries - AngelScript
rank: 717. 0 entries - Binary Lambda Calculus
rank: 718. 0 entries - EhBASIC
rank: 719. 0 entries - Epigram
rank: 720. 0 entries - FLORA-2
rank: 721. 0 entries - Florid
rank: 722. 0 entries - Gerbil
rank: 723. 0 entries - LC2200 Assembly
rank: 724. 0 entries - Leon
rank: 725. 0 entries - Livecode
rank: 726. 0 entries - LLP
rank: 727. 0 entries - Loglan82
rank: 728. 0 entries - Lolli
rank: 729. 0 entries - Lygon
rank: 730. 0 entries - ObjectIcon
rank: 731. 0 entries - PL/B
rank: 732. 0 entries - Plan
rank: 733. 0 entries - Reduce
rank: 734. 0 entries - Rubylog
rank: 735. 0 entries - S BASIC
rank: 736. 0 entries - SimpleLang
rank: 737. 0 entries - Star
rank: 738. 0 entries - X10
rank: 739. 0 entries - XS
</pre >
 
=={{header|Maple}}==
<lang Maple>count_sizes := proc(arr_name,arr_pop,i,lst)
local index := i;
local language;
for language in lst do
language := language[1]:
arr_name(index) := txt["query"]["pages"][language]["title"][10..]:
if(assigned(txt["query"]["pages"][language]["categoryinfo"]["size"])) then
arr_pop(index) := txt["query"]["pages"][language]["categoryinfo"]["size"]:
else:
arr_pop(index) := 0:
end if:
index++:
end do:
return index:
end proc:
 
txt := JSON:-ParseFile("http://rosettacode.org/mw/api.php?action=query&generator=categorymembers&gcmtitle=Category:Programming%20Languages&gcmlimit=350&prop=categoryinfo&format=json"):
arr_name := Array():
arr_pop := Array():
i := count_sizes(arr_name, arr_pop, 1, [indices(txt["query"]["pages"])]):
while (assigned(txt["continue"]["gcmcontinue"])) do
continue := txt["continue"]["gcmcontinue"]:
txt := JSON:-ParseFile(cat("http://rosettacode.org/mw/api.php?action=query&generator=categorymembers&gcmtitle=Category:Programming%20Languages&gcmlimit=350&prop=categoryinfo&format=json", "&continue=", txt["continue"]["continue"], "&gcmcontinue=", txt["continue"]["gcmcontinue"])):
i:=count_sizes(arr_name,arr_pop,i,[indices(txt["query"]["pages"])]):
end do:
arr_name:= arr_name[sort(arr_pop,output=permutation)]:
arr_pop := sort(arr_pop, output=sorted):
i := i-1:
for x from i to 1 by -1 do
printf("rank %d %d examples %s\n", i-x+1, arr_pop[x], arr_name[x]):
end do:</lang>
{{Out|Output}}
<pre>#10:30 AM 10/05/2018
rank 1 1002 examples Kotlin
rank 2 977 examples Racket
rank 3 977 examples Python
rank 4 949 examples Perl 6
rank 5 918 examples Tcl
rank 6 898 examples C
rank 7 891 examples J
rank 8 879 examples Zkl
rank 9 870 examples Java
rank 10 860 examples D
...
rank 680 0 examples Epigram
rank 681 0 examples LLP
rank 682 0 examples Lolli
rank 683 0 examples Leon
rank 684 0 examples Florid
rank 685 0 examples Loglan82</pre>
 
=={{header|Mathematica}}==
<lang Mathematica>Languages = Flatten[Import["http://rosettacode.org/wiki/Category:Programming_Languages","Data"][[1,1]]];
Languages = Most@StringReplace[Languages, {" " -> "_", "+" -> "%2B"}];
b = {#, If[# === {}, 0, #[[1]]]&@( StringCases[Import["http://rosettacode.org/wiki/Category:"<>#,"Plaintext"],
"category, out of " ~~ x:NumberString ~~ " total" ->x])} &/@ Languages;
For[i = 1, i < Length@b , i++ , Print[i, ". ", #[[2]], " - ", #[[1]] ]&@ Part[Reverse@SortBy[b, Last], i]]</lang>
{{out|Output : As of 29 February 2012}}
<pre>
1. 637 - Tcl
2. 576 - C
3. 558 - J
4. 538 - Go
5. 485 - Ada
6. 456 - D
7. 450 - Haskell
8. 441 - Mathematica
9. 432 - Java
10. 425 - Icon
...</pre>
 
=={{header|Nim}}==
<lang nim>import httpclient, json, re, strformat, strutils, algorithm
 
const
LangSite = "http://www.rosettacode.org/mw/api.php?action=query&list=categorymembers&cmtitle=Category:Programming_Languages&cmlimit=500&format=json"
CatSite = "http://www.rosettacode.org/mw/index.php?title=Special:Categories&limit=5000"
let regex = re"title=""Category:(.*?)"">.+?</a>.*\((.*) members\)"
 
type Rank = tuple[lang: string, count: int]
 
proc cmp(a, b: Rank): int =
result = cmp(b.count, a.count)
if result == 0: result = cmp(a.lang, b.lang)
 
proc add(langs: var seq[string]; fromJson: JsonNode) =
for entry in fromJson{"query", "categorymembers"}:
langs.add entry["title"].getStr.split("Category:")[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(cmp)
for i, rank in ranks:
echo &"{i + 1:3} {rank.count:4} - {rank.lang}"
</lang>
Output:
<pre>1 1344 - Go
2 1329 - Phix
3 1323 - Julia
4 1303 - Raku
5 1252 - Perl
6 1224 - Python
7 1120 - Kotlin
8 1109 - C
9 1095 - Java
10 1066 - Wren
11 1064 - REXX
12 1061 - Racket
13 1021 - J
14 1012 - Zkl
15 1007 - Ruby
16 1001 - C++
17 993 - Nim
18 989 - Haskell
19 966 - D
20 961 - Tcl
21 915 - Scala
22 877 - C sharp
23 870 - Sidef
24 852 - Factor
25 830 - PicoLisp
26 792 - Lua
27 780 - Ada
28 778 - Rust
29 761 - Mathematica
30 721 - Common Lisp
...</pre>
 
=={{header|Objeck}}==
<lang objeck>use HTTP;
use RegEx;
use XML;
use Collection;
 
class RosettaRank {
function : Main(args : String[]) ~ Nil {
langs_xml := "";
client := HttpClient->New();
in := client->Get("http://rosettacode.org/mw/api.php?action=query&list=categorymembers&cmtitle=Category:Programming_Languages&cmlimit=5000&format=xml");
each(i : in) {
langs_xml += in->Get(i)->As(String);
};
langs := StringSet->New();
parser := XmlParser->New(langs_xml);
if(parser->Parse()) {
# get first item
results := parser->FindElements("/api/query/categorymembers/cm");
each(i : results) {
element := results->Get(i)->As(XmlElement);
name := element->GetAttribute("title")->GetValue();
offset := name->Find(':');
if(offset > -1) {
lang := name->SubString(offset + 1, name->Size() - offset - 1);
langs->Insert(lang->ReplaceAll("&#x20;", " "));
};
};
};
langs_counts := IntMap->New();
client := HttpClient->New();
html := client->Get("http://rosettacode.org/mw/index.php?title=Special:Categories&limit=5000");
each(i : html) {
lines := html->Get(i)->As(String);
html_elements := lines->Split("\n");
each(j : html_elements) {
element := html_elements[j];
name : String; count : String;
regex := RegEx->New("<li><a href=\"(\\w|\\s|/|\\?|\\&|;|:|#)+\"\\stitle=\"Category:(\\w|\\s|#)+\">");
found := regex->FindFirst(element);
if(found <> Nil) {
group1 := found->Size();
regex := RegEx->New("(\\w|\\s)+");
found := regex->Match(element, group1);
if(found <> Nil & found->Size() > 0) {
name := found;
# skip over some junk characters
group2 := group1 + found->Size() + 10;
regex := RegEx->New("\\s\\(");
found := regex->Match(element, group2);
if(found <> Nil) {
group3 := group2 + found->Size();
regex := RegEx->New("\\d+");
found := regex->Match(element, group3);
if(found <> Nil & found->Size() > 0) {
count := found;
};
};
};
};
if(name <> Nil & count <> Nil) {
if(langs->Has(name)) {
langs_counts->Insert(count->ToInt(), name);
};
name := Nil; count := Nil;
};
};
};
keys := langs_counts->GetKeys();
count := 1;
for(i := keys->Size() - 1; i >= 0; i -=1;) {
key := keys->Get(i);
IO.Console->Print(count)->Print(". ")->Print(key)->Print(" - ")->PrintLine(langs_counts->Find(key)->As(String));
count += 1;
};
}
}</lang>
 
<pre>1. 849 - Tcl
2. 826 - Racket
3. 821 - Python
4. 759 - J
5. 757 - Ruby
6. 751 - Perl 6
7. 743 - C
8. 736 - D
9. 728 - Go
10. 696 - Perl
...</pre>
 
=={{header|ooRexx}}==
{{trans|REXX}}
<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
* rearranged to my taste and utilizing the array class of ooRexx
* which offers a neat way of sorting as desired, see :CLASS mycmp below
* For the input to this program open these links:
* http://rosettacode.org/wiki/Category:Programming_Languages
* http://www.rosettacode.org/mw/index.php?title=Special:Categories&limit=5000
* and save the pages as LAN.txt and CAT.txt, respectively
* Output: RC_POP.txt list of languages sorted by popularity
* If test=1, additionally:
* RC_LNG.txt list of languages alphabetically sorted
* RC_TRN.txt list language name translations (debug)
*--------------------------------------------------------------------*/
test=1
name.='??'
l.=0
safe=''
x00='00'x
linfid='RC_LAN.txt'
linfid='LAN.txt' /* language file */
cinfid='CAT.txt' /* category file */
oid='RC_POP.txt'; 'erase' oid
If test Then Do
tid='RC.TRN.txt'; 'erase' tid
tia='RC_LNG.txt'; 'erase' tia
End
Call init
 
call read_lang /* process language file */
 
Call read_cat /* process category file */
 
Call ot words(lang_list) 'possible languages'
Call ot words(lang_listr) 'relevant languages'
llrn=words(lang_listr)
 
If test Then
Call no_member
 
a=.array~new /* create array object */
cnt.=0
Do i=1 By 1 While lang_listr<>''
Parse Var lang_listr ddu0 lang_listr
ddu=translate(ddu0,' ',x00)
a[i]=right(mem.ddu,3) name.ddu /* fill array element */
z=mem.ddu /* number of members */
cnt.z=cnt.z+1 /* number of such languages */
End
n=i-1 /* number of output lines */
 
a~sortWith(.mycmp~new) /* sort the array elements */
/* see :CLASS mycmp below */
/*---------------------------------------------------------------------
* and now create the output
*--------------------------------------------------------------------*/
Call o ' '
Call o center('timestamp: ' date() time('Civil'),79,'-')
Call o ' '
Call o right(lrecs,9) 'records read from file: ' linfid
Call o right(crecs,9) 'records read from file: ' cinfid
Call o right(llrn,9) 'relevant languages'
Call o ' '
 
rank=0
rank.=0
Do i=1 To n
rank=rank+1
Parse Value a[i] With o . 6 lang
ol=' rank: 'right(rank,3)' '||,
'('right(o,3) 'entries) 'lang
If cnt.o>1 Then Do
If rank.o=0 Then
rank.o=rank
ol=overlay(right(rank.o,3),ol,17)
ol=overlay('[tied]',ol,22)
End
Call o ol
End
 
Call o ' '
Call o center('+ end of list +',72)
Say 'Output in' oid
 
If test Then Do
b=.array~new /* create array object */
cnt.=0
Do i=1 By 1 While lang_list<>''
Parse Var lang_list ddu0 lang_list
ddu=translate(ddu0,' ',x00)
b[i]=right(mem.ddu,3) name.ddu /* fill array element */
End
n=i-1 /* number of output lines */
 
b~sortWith(.alpha~new) /* sort the array elements */
Call oa n 'languages'
Do i=1 To n
Call oa b[i]
End
Say 'Sorted list of languages in' tia
End
Exit
 
o:
Return lineout(oid,arg(1))
ot:
If test Then Call lineout tid,arg(1)
Return
oa:
If test Then Call lineout tia,arg(1)
Return
 
read_lang:
/*---------------------------------------------------------------------
* Read the language page to determine the list of possible languages
* Output: l.lang>0 for all languages found
* name.lang original name of uppercased language name
* lang_list list of uppercased language names
* lrecs number of records read from language file
*--------------------------------------------------------------------*/
l.=0
name.='??'
lang_list=''
Do lrecs=0 While lines(linfid)\==0
l=linein(linfid) /* read from language file */
l=translate(l,' ','9'x) /* turn tabs to blanks */
dd=space(l) /* remove extra blanks */
ddu=translate(dd)
If pos('AUTOMATED ADMINISTRATION',ddu)>0 Then /* ignore this */
Iterate
If pos('RETRIEVED FROM',ddu)\==0 Then /* this indicates the end */
Leave
If dd=='' Then /* ignore all blank lines. */
Iterate
If left(dd,1)\=='*' Then /* ignore lines w/o * */
Iterate
ddo=fix_lang(dd) /* replace odd language names */
If ddo<>dd Then Do /* show those that we found */
Call ot ' ' dd
Call ot '>' ddo
dd=ddo
End
Parse Var dd '*' dd "<" /* extract the language name */
ddu=strip(translate(dd)) /* translate to uppercase */
If name.ddu='??' Then
name.ddu=dd /* remember 1st original name */
l.ddu=l.ddu+1
ddu_=translate(ddu,x00,' ')
If wordpos(ddu_,lang_list)=0 Then
lang_list=lang_list ddu_
End
Return
 
read_cat:
/*---------------------------------------------------------------------
* Read the category page to get language names and number of members
* Output: mem.ddu number of members for (uppercase) Language ddu
* lang_listr the list of relevant languages
*--------------------------------------------------------------------*/
mem.=0
lang_listr=''
Do crecs=0 While lines(cinfid)\==0
l=get_cat(cinfid) /* read from category file */
l=translate(l,' ','9'x) /* turn tabs to blanks */
dd=space(l) /* remove extra blanks */
If dd=='' Then /* ignore all blank lines. */
Iterate
ddu=translate(dd)
ddo=fix_lang(dd) /* replace odd language names */
If ddo<>dd Then Do /* show those that we found */
Call ot ' ' dd
Call ot '>' ddo
dd=ddo
End
du=translate(dd) /* get an uppercase version. */
If pos('RETRIEVED FROM',du)\==0 Then /* this indicates the end */
Leave
Parse Var dd dd '<' "(" mems . /* extract the language name */
/* and the number of members */
dd=space(substr(dd,3))
_=translate(dd)
If \l._ Then /* not a known language */
Iterate /* ignore */
if pos(',', mems)\==0 then
mems=changestr(",", mems, '') /* remove commas. */
If\datatype(mems,'W') Then /* not a number of members */
Iterate /* ignore */
ddu=space(translate(dd))
mem.ddu=mem.ddu+mems /* set o add number of members*/
Call memory ddu /* list of relevant languages */
End
Return
 
get_cat:
/*---------------------------------------------------------------------
* get a (logical) line from the category file
* 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)
* we need language name and number of members in one line
*--------------------------------------------------------------------*/
Parse Arg fid
If safe<>'' Then
ol=safe
Else Do
If lines(fid)=0 Then
Return ''
ol=linein(fid)
safe=''
End
If left(ol,3)=' *' Then Do
Do Until left(r,3)==' *' | lines(fid)=0
r=linein(fid)
If left(r,3)==' *' Then Do
safe=r
Return ol
End
Else
ol=ol r
End
End
Return ol
 
memory:
ddu0=translate(ddu,x00,' ')
If wordpos(ddu0,lang_listr)=0 Then
lang_listr=lang_listr ddu0
Return
 
fix_lang: Procedure Expose old. new.
Parse Arg s
Do k=1 While old.k\=='' /* translate Unicode variations. */
If pos(old.k,s)\==0 Then
s=changestr(old.k,s,new.k)
End
Return s
 
init:
old.=''
old.1='UC++' /* '55432B2B'X */
new.1="µC++" /* old UC++ --?ASCII-8: µC++ */
old.2='МК-61/52' /* 'D09CD09A2D36312F3532'X */
new.2='MK-61/52' /* somewhere a mistranslated: MK- */
old.3='Déjà Vu' /* '44C3A96AC3A0205675'X */
new.3='Déjà Vu' /* Unicode +¬j+á --?ASCII-8: Déjá */
old.4='Caché' /* '43616368C3A9'X */
new.4='Caché' /* Unicode ach+¬ --?ASCII-8: Caché */
old.5='ÎœC++' /* 'CE9C432B2B'X */
new.5="MC++" /* Unicode +£C++ --?ASCII-8: µC++ */
/*-----------------------------------------------------------------*/
Call ot 'Language replacements:'
Do ii=1 To 5
Call ot ' ' left(old.ii,10) left(c2x(old.ii),20) '->' new.ii
End
Call ot ' '
Return
 
no_member: Procedure Expose lang_list lang_listr tid x00 test
/*---------------------------------------------------------------------
* show languages found in language file that are not referred to
* in the category file
*--------------------------------------------------------------------*/
ll =wordsort(lang_list ) /* languages in language file */
llr=wordsort(lang_listr) /* languages in category file */
Parse Var ll l1 ll
Parse Var llr l2 llr
nn.=0
Do Forever
Select
When l1=l2 Then Do
If l1='' Then /* both lists empty */
Leave
Parse Var ll l1 ll /* get the next language */
Parse Var llr l2 llr /* -"- */
End
When l1<l2 Then Do /* in language file */
/* and not in category file */
z=nn.0+1
nn.z=' 'translate(l1,' ',x00) /* show in test output */
nn.0=z
Parse Var ll l1 ll /* next from language file */
End
Otherwise Do
Call ot '?? 'translate(l2,' ',x00) /* show in test output */
Say 'In category file but not in language file:'
Say '?? 'translate(l2,' ',x00)
Say 'Hit enter to proceed'
Pull .
Parse Var llr l2 llr /* next from category file */
End
End
End
Call ot nn.0 'Languages without members:' /* heading */
Do ii=1 To nn.0
Call ot nn.ii
End
Return
 
::CLASS mycmp MIXINCLASS Comparator
::METHOD compare
/**********************************************************************
* smaller number is considered higher
* numbers equal: higher language considered higher
* otherwise return lower
**********************************************************************/
Parse Upper Arg a,b
Parse Var a na +4 ta
Parse Var b nb +4 tb
Select
When na<<nb THEN res=1
When na==nb Then Do
If ta<<tb Then res=-1
Else res=1
End
Otherwise res=-1
End
Return res
 
::CLASS alpha MIXINCLASS Comparator
::METHOD compare
/**********************************************************************
* higher language considered higher
* otherwise return lower
**********************************************************************/
Parse Upper Arg a,b
Parse Var a na +4 ta
Parse Var b nb +4 tb
If ta<<tb Then res=-1
Else res=1
Return res</lang>
 
Output (the beginning):
<pre>
------------------------timestamp: 24 Nov 2013 9:48am-------------------------
 
706 records read from file: LAN.txt
2204 records read from file: CAT.txt
502 relevant languages
 
rank: 1 (760 entries) Tcl
rank: 2 (724 entries) Racket
rank: 3 (708 entries) Python
rank: 4 (681 entries) C
</pre>
Note: If MC++ and µC++ are the same, they should/could be added together to get 501 languages.
 
=={{header|Oz}}==
{{libheader|OzHttpClient}}
Using web scraping. Does not filter non-language categories.
<lang oz>declare
[HTTPClient] = {Module.link ['x-ozlib://mesaros/net/HTTPClient.ozf']}
[Regex] = {Module.link ['x-oz://contrib/regex']}
fun {GetPage RawUrl}
Client = {New HTTPClient.urlGET init(inPrms(toFile:false toStrm:true) _)}
Url = {VirtualString.toString RawUrl}
OutParams
HttpResponseParams
in
{Client getService(Url ?OutParams ?HttpResponseParams)}
{Client closeAll(true)}
OutParams.sOut
end
fun {GetCategories Doc}
{Map {Regex.allMatches "<li><a[^>]+>([^<]+)</a> \\(([0-9]+) member" Doc}
fun {$ Match}
Category = {Regex.group 1 Match Doc}
Count = {String.toInt {ByteString.toString {Regex.group 2 Match Doc}}}
in
Category#Count
end
}
end
Url = "http://www.rosettacode.org/mw/index.php?title=Special:Categories&limit=5000"
 
{System.showInfo "Retrieving..."}
Doc = {GetPage Url}
 
{System.showInfo "Parsing..."}
Cs = {GetCategories Doc}
in
for
Cat#Count in {Sort Cs fun {$ _#C1 _#C2} C1 > C2 end}
I in 1..20
do
{System.showInfo I#". "#Count#" - "#Cat}
end</lang>
{{out}}
<pre>
1. 371 - Tcl
2. 369 - Programming Tasks
3. 338 - Python
4. 324 - Ruby
5. 306 - Haskell
...
17. 225 - Oz
18. 214 - C++
19. 209 - JavaScript
20. 208 - ALGOL 68
</pre>
 
=={{header|Perl}}==
===By using the API===
<lang perl>use 5.010;
use MediaWiki::API;
 
my $api =
MediaWiki::API->new( { api_url => 'http://rosettacode.org/mw/api.php' } );
 
my @languages;
my $gcmcontinue;
while (1) {
my $apih = $api->api(
{
action => 'query',
generator => 'categorymembers',
gcmtitle => 'Category:Programming Languages',
gcmlimit => 250,
prop => 'categoryinfo',
gcmcontinue => $gcmcontinue
}
);
push @languages, values %{ $apih->{'query'}{'pages'} };
 
last if not $gcmcontinue = $apih->{'continue'}{'gcmcontinue'};
}
 
for (@languages) {
$_->{'title'} =~ s/Category://;
$_->{'categoryinfo'}{'size'} //= 0;
}
 
my @sorted_languages =
reverse sort { $a->{'categoryinfo'}{'size'} <=> $b->{'categoryinfo'}{'size'} }
@languages;
 
binmode STDOUT, ':encoding(utf8)';
my $n = 1;
for (@sorted_languages) {
printf "%3d. %20s - %3d\n", $n++, $_->{'title'},
$_->{'categoryinfo'}{'size'};
}
</lang>
{{out}}
<pre> 1. Go - 1177
2. Phix - 1116
3. Perl 6 - 1107
4. Julia - 1103
5. Python - 1080
6. Kotlin - 1053
7. Racket - 1045
8. Perl - 1045
9. C - 969
10. Zkl - 960
...</pre>
 
=={{header|Phix}}==
The distributed version also has an output_html option.
{{libheader|Phix/libcurl}}
<lang Phix>-- demo\rosetta\Rank_Languages.exw
include builtins\timedate.e
include builtins\libcurl.e
 
constant output_users = false,
limit = 20, -- 0 to list all
refresh_cache = timedelta(days:=1), -- 0 for always
languages = "http://rosettacode.org/wiki/Category:Programming_Languages",
categories = "http://www.rosettacode.org/mw/index.php?title=Special:Categories&limit=5000"
 
function open_download(string filename, url)
bool refetch = true
if file_exists(filename) then
-- use existing file if <= refresh_cache (1 day) old
sequence last_mod = get_file_date(filename) -- (0.8.1+)
atom delta = timedate_diff(last_mod,date())
refetch = (delta>refresh_cache)
end if
if refetch then
printf(1,"Downloading %s...\n",{filename})
CURLcode res = curl_easy_get_file(url,"",filename) -- (no proxy)
if res!=CURLE_OK then
string error = sprintf("%d",res)
if res=CURLE_COULDNT_RESOLVE_HOST then
error &= " [CURLE_COULDNT_RESOLVE_HOST]"
end if
printf(1, "Error %s downloading file\n", error)
{} = wait_key()
abort(0)
end if
end if
return get_text(filename)
end function
 
constant cat_title = "title=\"Category:"
 
function extract_names()
sequence results = {} -- {rank,count,name}
 
-- 1) extract languages from eg title="Category:Phix"
sequence language_names = {}
string langs = open_download("languages.htm",languages),
language_name
langs = langs[1..match("<div class=\"printfooter\">",langs)-1]
integer start = match("<h2>Subcategories</h2>",langs), k
while true do
k = match(cat_title,langs,start)
if k=0 then exit end if
k += length(cat_title)
start = find('"',langs,k)
language_name = langs[k..start-1]
language_names = append(language_names,language_name)
end while
 
-- 2) extract results from eg title="Category:Phix">Phix</a>?? (997 members)</li>
-- but obviously only when we have found that language in the phase above.
-- (note there is / ignore some wierd uncode-like stuff after the </a>...)
string cats = open_download("categories.htm",categories)
start = 1
while true do
k = match(cat_title,cats,start)
if k=0 then exit end if
k += length(cat_title)
start = find('"',cats,k)
language_name = cats[k..start-1]
start = match("</a>",cats,start)+4
if output_users then
if length(language_name)>5
and language_name[-5..-1] = " User" then
language_name = language_name[1..-6]
else
language_name = ""
end if
end if
if length(language_name)
and find(language_name,language_names) then
while not find(cats[start],"(<") do start += 1 end while -- (ignore)
string members = cats[start..find('<',cats,start+1)]
members = substitute(members,",","")
sequence res = scanf(members,"(%d member%s)<")
results = append(results,{0,res[1][1],language_name})
end if
end while
results = sort_columns(results,{-2,3}) -- (descending 2nd column, then asc 3rd)
 
--3) assign rank
integer count, prev = 0, rank
for i=1 to length(results) do
count = results[i][2]
if count!=prev then rank = i end if
prev = count
results[i][1] = rank
end for
 
return results
end function
 
procedure show(sequence results)
for i=1 to iff(limit?limit:length(results)) do
printf(1,"%3d: %,d - %s\n",results[i])
end for
end procedure
 
show(extract_names())</lang>
{{out}}
As of July 31st, 2019
<pre>
Downloading rc_cache\languages.htm...
Downloading rc_cache\categories.htm...
1: 1,156 - Go
2: 1,092 - Phix
3: 1,090 - Perl 6
4: 1,074 - Julia
5: 1,066 - Python
6: 1,046 - Kotlin
7: 1,026 - Perl
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}}==
<lang PicoLisp>(load "@lib/http.l")
 
(for (I . X)
(flip
(sort
(make
(client "rosettacode.org" 80
"mw/index.php?title=Special:Categories&limit=5000"
(while (from "<li><a href=\"/wiki/Category:")
(let Cat (till "\"")
(from "(")
(when (format (till " " T))
(link (cons @ (ht:Pack Cat))) ) ) ) ) ) ) )
(prinl (align 3 I) ". " (car X) " - " (cdr X)) )</lang>
{{out|Output (dec15)}}
<pre> 1. 903 - Racket
2. 897 - Tcl
3. 863 - Python
4. 821 - J
5. 796 - Perl_6
6. 780 - Programming_Tasks
7. 778 - Ruby
8. 767 - C
9. 751 - Go
10. 745 - D
...</pre>
 
=={{header|PowerShell}}==
{{trans|C#}}
<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")
$match1 = [regex]::matches($get1, "`"title`":`"Category:(.+?)`"")
$match2 = [regex]::matches($get2, "title=`"Category:([^`"]+?)`">[^<]+?</a>[^\(]*\((\d+) members\)")
$r = 1
$langs = $match1 | foreach { $_.Groups[1].Value.Replace("\","") }
$res = $match2 | sort -Descending {[Int]$($_.Groups[2].Value)} | foreach {
if ($langs.Contains($_.Groups[1].Value))
{
[pscustomobject]@{
Rank = "$r"
Members = "$($_.Groups[2].Value)"
Language = "$($_.Groups[1].Value)"
}
$r++
}
}
1..30 | foreach{
[pscustomobject]@{
"Rank 1..30" = "$($_)"
"Members 1..30" = "$($res[$_-1].Members)"
"Language 1..30" = "$($res[$_-1].Language)"
"Rank 31..60" = "$($_+30)"
"Members 31..60" = "$($res[$_+30].Members)"
"Language 31..60" = "$($res[$_+30].Language)"
}
}| Format-Table -AutoSize
</lang>
<b>Output: August 04, 2015</b>
<pre>
Rank 1..30 Members 1..30 Language 1..30 Rank 31..60 Members 31..60 Language 31..60
---------- ------------- -------------- ----------- -------------- ---------------
1 887 Tcl 31 405 Seed7
2 877 Racket 32 397 Julia
3 853 Python 33 389 PL/I
4 798 J 34 387 Fortran
5 775 Ruby 35 386 ALGOL 68
6 766 Perl 6 36 376 Lua
7 758 C 37 369 Pascal
8 746 Go 38 367 R
9 740 D 39 364 Groovy
10 710 Perl 40 363 F Sharp
11 701 REXX 41 363 Forth
12 692 PicoLisp 42 358 PHP
13 682 Haskell 43 342 AWK
14 675 Mathematica 44 340 Sidef
15 652 Java 45 335 MATLAB
16 623 Ada 46 325 Liberty BASIC
17 591 AutoHotkey 47 297 Octave
18 562 C++ 48 287 Factor
19 551 Common Lisp 49 286 Scheme
20 548 Scala 50 285 NetRexx
21 532 BBC BASIC 51 284 Oforth
22 523 Icon 52 280 Oz
23 516 C sharp 53 274 Run BASIC
24 508 OCaml 54 272 E
25 502 Nim 55 271 Bracmat
26 488 PureBasic 56 268 PowerShell
27 487 Clojure 57 263 Prolog
28 455 Erlang 58 260 Lasso
29 441 PARI/GP 59 249 Delphi
30 434 JavaScript 60 239 Smalltalk
</pre>
===PowerShell: Using web scraping===
{{trans|Python}}
<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/mw/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)
}
</lang>
{{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>
 
=={{header|PureBasic}}==
===Using MediaWiki API method===
<lang purebasic>Procedure handleError(value, msg.s)
If value = 0
MessageRequester("Error", msg)
End
EndIf
EndProcedure
 
Structure languageInfo
name.s
pageCount.i
EndStructure
 
#JSON_web_data = 0 ;ID# for our parsed JSON web data object
 
Define NewList languages.languageInfo()
 
Define blah.s, object_val, allPages_mem, title_mem, page_mem, categoryInfo_mem, continue_mem
Define url$, title$, currentPage$, language$, langPageCount, gcmcontinue$, *bufferPtr
 
handleError(InitNetwork(), "Unable to initialize network functions.")
 
Repeat
url$ = "http://www.rosettacode.org/mw/api.php?action=query" +
"&generator=categorymembers&gcmtitle=Category:Programming%20Languages" +
"&gcmlimit=500" + "&gcmcontinue=" + gcmcontinue$ +
"&prop=categoryinfo&format=json"
*bufferPtr = ReceiveHTTPMemory(url$)
handleError(*bufferPtr, "Unable to receive web page data.")
If CatchJSON(#JSON_web_data, *bufferPtr, MemorySize(*bufferPtr)) = 0
MessageRequester("Error", JSONErrorMessage() + " at position " +
JSONErrorPosition() + " in line " +
JSONErrorLine() + " of JSON web Data")
End
EndIf
FreeMemory(*bufferPtr)
 
object_val = JSONValue(#JSON_web_data)
allPages_mem = GetJSONMember(GetJSONMember(object_val, "query"), "pages")
If ExamineJSONMembers(allPages_mem)
While NextJSONMember(allPages_mem)
page_mem = JSONMemberValue(allPages_mem)
title_mem = GetJSONMember(page_mem, "title")
If title_mem
title$ = GetJSONString(title_mem)
If Left(title$, 9) = "Category:"
language$ = Mid(title$, 10)
categoryInfo_mem = GetJSONMember(page_mem, "categoryinfo")
If categoryInfo_mem
langPageCount = GetJSONInteger(GetJSONMember(categoryInfo_mem, "pages"))
Else
langPageCount = 0
EndIf
AddElement(languages())
languages()\name = language$
languages()\pageCount = langPageCount
EndIf
EndIf
Wend
EndIf
 
;check for continue
continue_mem = GetJSONMember(object_val, "continue")
If continue_mem
gcmcontinue$ = GetJSONString(GetJSONMember(continue_mem, "gcmcontinue"))
Else
gcmcontinue$ = ""
EndIf
FreeJSON(#JSON_web_data)
Until gcmcontinue$ = ""
 
;all data has been aquired, now process and display it
SortStructuredList(languages(), #PB_Sort_Descending, OffsetOf(languageInfo\pageCount), #PB_Integer)
 
If OpenConsole()
If ListSize(languages())
Define i, *startOfGroupPtr.languageInfo, *lastElementPtr, groupSize, rank
Define outputSize = 100, outputLine
PrintN(Str(ListSize(languages())) + " languages." + #CRLF$)
LastElement(languages())
*lastElementPtr = @languages() ;pointer to last element
FirstElement(languages())
*startOfGroupPtr = @languages() ;pointer to first element
groupSize = 1
rank = 1
While NextElement(languages())
If languages()\pageCount <> *startOfGroupPtr\pageCount Or *lastElementPtr = @languages()
;display a group of languages at the same rank
ChangeCurrentElement(languages(), *startOfGroupPtr)
For i = 1 To groupSize
;display output in groups to allow viewing of all entries
If outputLine = 0
PrintN(" Rank Tasks Language")
PrintN(" ------ ----- --------")
EndIf
PrintN(RSet(Str(rank), 6) + ". " +
RSet(Str(languages()\pageCount), 4) + " " +
languages()\name)
outputLine + 1
If outputLine >= outputSize
Print(#CRLF$ + #CRLF$ + "Press ENTER to continue" + #CRLF$): Input()
outputLine = 0
EndIf
NextElement(languages())
Next
rank + groupSize
groupSize = 1
*startOfGroupPtr = @languages()
Else
groupSize + 1
EndIf
Wend
Else
PrintN("No language categories found.")
EndIf
Print(#CRLF$ + #CRLF$ + "Press ENTER to exit"): Input()
CloseConsole()
EndIf</lang>
Sample output:
<pre>608 languages.
 
Rank Tasks Language
------ ----- --------
1. 904 Racket
2. 894 Tcl
3. 852 Python
4. 836 J
5. 803 Perl 6
6. 787 Ruby
7. 772 C
8. 752 Go
9. 743 D
10. 728 Perl
11. 726 REXX
12. 702 Haskell
13. 697 Java
14. 696 PicoLisp
15. 693 Zkl
16. 687 Mathematica
17. 625 Ada
18. 603 C++
18. 603 Sidef
18. 603 AutoHotkey
21. 578 Unicon
22. 574 Common Lisp
23. 558 Scala
24. 530 BBC BASIC
25. 527 C sharp
26. 520 Icon
27. 507 OCaml
28. 503 Nim
29. 497 PureBasic
.....
514. 0 Rubylog
514. 0 Refal
514. 0 QuakeC
514. 0 Mirelle
514. 0 .QL
514. 0 M680x0
514. 0 Datalog
514. 0 Cilk++
514. 0 Cecil
514. 0 AspectC++
514. 0 8080 Assembly
514. 0 OpenC++
514. 0 AMPL
514. 0 UserRPL
514. 0 TeLa
514. 0 UScript
514. 0 TAL
514. 0 Zonnon
514. 0 Superbase BASIC
514. 0 VAX Assembly
514. 0 Star
514. 0 VRML
514. 0 WML
514. 0 X10
514. 0 XS
514. 0 XBase
514. 0 UC++
514. 0 True BASIC
514. 0 Thistle
</pre>
 
===Using web scraping method===
<lang purebasic>
;Uses a web scraping method.
 
;It is limited to only retrieving 5000 language categories and the counts contain
;some slight inaccuracies.
 
Structure Language
count.i
Name.s
EndStructure
 
Dim Row.Language(5000)
 
Procedure handleError(value, msg.s)
If value = 0
MessageRequester("Error", msg)
End
EndIf
EndProcedure
 
handleError(InitNetwork(), "Unable to initialize network functions.")
; Lines have been split to fit RC's 80 char preferences
ignore$ = "Basic language learning Encyclopedia Implementations " +
"Language Implementations Language users " +
"Maintenance/OmitCategoriesCreated Programming Languages " +
"Programming Tasks RCTemplates Solutions by Library Solutions by " +
"Programming Language Solutions by Programming Task Unimplemented " +
"tasks by language WikiStubs Examples needing attention " +
"Impl needed"
 
url$ = "http://www.rosettacode.org/mw/index.php?" +
"title=Special:Categories&limit=5000"
 
ReceiveHTTPFile(url$, "special.htm")
ReadFile(0, "special.htm", #PB_UTF8)
While Not Eof(0)
i + 1
x1$ = ReadString(0)
x2$ = Mid(x1$, FindString(x1$, "member", 1) - 4 , 3)
Row(i)\count = Val(Trim(RemoveString(x2$, "(")))
x3$ = Mid(x1$, FindString(x1$, Chr(34) + ">", 1) + 2, 30)
Row(i)\Name = Left(x3$, FindString(x3$, "<", 1) - 1)
If FindString(ignore$, Row(i)\Name, 1) Or Row(i)\Name = ""
Row(i)\count = 0
EndIf
Wend
 
 
offset=OffsetOf(Language\count)
SortStructuredArray(Row(), #PB_Sort_Descending, offset, #PB_Integer)
OpenConsole()
For i = 0 To 29
PrintN( Str(i + 1) + ". " + Str(Row(i)\count) + " - " + Row(i)\Name)
Next
Input()</lang>
Sample output:
<pre>1. 907 - Racket
2. 898 - Tcl
3. 868 - Python
4. 839 - J
5. 807 - Perl 6
6. 790 - Ruby
7. 756 - Go
8. 746 - D
9. 732 - Perl
10. 729 - REXX
11. 705 - Haskell
12. 700 - Java
13. 699 - PicoLisp
14. 694 - Zkl
15. 690 - Mathematica
16. 629 - Ada
17. 606 - C++
18. 606 - AutoHotkey
19. 604 - Sidef
20. 581 - Unicon
21. 577 - Common Lisp
22. 561 - Scala
23. 533 - BBC BASIC
24. 530 - C sharp
25. 523 - Icon
26. 510 - OCaml
27. 504 - Nim
28. 500 - PureBasic
29. 494 - Clojure
30. 491 - JavaScript</pre>
 
=={{header|Python}}==
 
===Python: Using web scraping===
Using <code>requests</code> library.
 
<lang python>import requests
import re
 
response = requests.get("http://rosettacode.org/wiki/Category:Programming_Languages").text
languages = re.findall('title="Category:(.*?)">',response)[:-3] # strip last 3
 
response = requests.get("http://rosettacode.org/mw/index.php?title=Special:Categories&limit=5000").text
response = re.sub('(\d+),(\d+)',r'\1'+r'\2',response) # strip ',' from popular languages above 999 members
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
if language in languages:
print("{:4d} {:4d} - {}".format(cnt+1, int(members), language))
 
</lang>
{{out|Output (as of Dec 21, 2020)}}
1 1306 - Go
2 1275 - Phix
3 1265 - Julia
4 1257 - Raku
5 1196 - Python
6 1182 - Perl
7 1107 - Kotlin
8 1080 - C
9 1074 - Java
10 1061 - Racket
11 1022 - REXX
12 1012 - Zkl
13 1002 - J
14 983 - Ruby
15 972 - Haskell
 
===Python: Using MediaWiki API method===
<lang python>
import requests
import operator
import re
 
api_url = 'http://rosettacode.org/mw/api.php'
languages = {}
 
parameters = {
'format': 'json',
'action': 'query',
'generator': 'categorymembers',
'gcmtitle': 'Category:Programming Languages',
'gcmlimit': '200',
'gcmcontinue': '',
'continue': '',
'prop': 'categoryinfo'
}
 
while(True):
response = requests.get(api_url, params=parameters).json()
for k,v in response['query']['pages'].items():
if 'title' in v and 'categoryinfo' in v:
languages[v['title']]=v['categoryinfo']['size']
if 'continue' in response:
gcmcontinue = response['continue']['gcmcontinue']
# print(gcmcontinue)
parameters.update({'gcmcontinue': gcmcontinue})
else:
break
 
# report top 15 languages
for i, (language, size) in enumerate(sorted(languages.items(), key=operator.itemgetter(1), reverse=True)[:15]):
print("{:4d} {:4d} - {}".format(i+1, size, re.sub('Category:','',language))) # strip Category: from language
 
 
</lang>
{{out|Output (as of Dec 21, 2020)}}
1 1306 - Go
2 1275 - Phix
3 1265 - Julia
4 1257 - Raku
5 1196 - Python
6 1182 - Perl
7 1107 - Kotlin
8 1080 - C
9 1074 - Java
10 1061 - Racket
11 1022 - REXX
12 1012 - Zkl
13 1002 - J
14 983 - Ruby
15 972 - Haskell
 
=={{header|R}}==
{{incorrect|R|I believe you need to use <tt>continue gcmcontinue</tt> to get complete results.}}
<lang rsplus>
library(rvest)
library(plyr)
library(dplyr)
options(stringsAsFactors=FALSE)
 
langUrl <- "http://rosettacode.org/mw/api.php?format=xml&action=query&generator=categorymembers&gcmtitle=Category:Programming%20Languages&prop=categoryinfo&gcmlimit=5000"
langs <- html(langUrl) %>%
html_nodes('page')
 
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 March, 23, 2019)}}
<pre>
language n
1 Go 1114
2 Perl 6 1059
3 Kotlin 1029
4 Phix 993
5 Julia 992
6 Perl 978
</pre>
 
=={{header|Racket}}==
 
{{trans|Python}}
 
<lang racket>#lang racket
(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 @ hash-ref)
 
(define table (make-hash))
(let loop ([gcmcontinue ""])
(define resp (read-json (get-pure-port (make-complete-url gcmcontinue))))
(hash-union! table
(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))</lang>
 
Output on September 4, 2019:
 
<pre>
Rank: 1 (1176 entries) Go
Rank: 2 (1112 entries) Phix
Rank: 3 (1107 entries) Perl 6
Rank: 4 (1099 entries) Julia
Rank: 5 (1079 entries) Python
Rank: 6 (1053 entries) Kotlin
Rank: 7 (1038 entries) Racket
Rank: 8 (1037 entries) Perl
Rank: 9 (968 entries) C
Rank: 10 (960 entries) Zkl
Rank: 11 (945 entries) J
Rank: 12 (935 entries) REXX
Rank: 13 (930 entries) Tcl
Rank: 14 (910 entries) Java
Rank: 15 (904 entries) Ruby
</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++)
 
<lang perl6>use HTTP::UserAgent;
use URI::Escape;
use JSON::Fast;
use Sort::Naturally;
 
my $client = HTTP::UserAgent.new;
 
my $url = 'http://rosettacode.org/mw';
 
my $tablefile = './RC_Popularity.txt';
 
my %cat = (
'Programming_Tasks' => 'Task',
'Draft_Programming_Tasks' => 'Draft'
);
my %tasks;
 
for %cat.keys.sort -> $cat {
mediawiki-query(
$url, 'pages',
:generator<categorymembers>,
:gcmtitle("Category:$cat"),
:gcmlimit<350>,
:rawcontinue(),
:prop<title>
).map({ %tasks{%cat{$cat}}++ });
}
 
my %counts =
mediawiki-query(
$url, 'pages',
:generator<categorymembers>,
:gcmtitle<Category:Programming Languages>,
:gcmlimit<350>,
:rawcontinue(),
:prop<categoryinfo>
)
.map({
my $title = .<title>.subst(/^'Category:'/, '');
my $tasks = (.<categoryinfo><pages> || 0);
my $categories = (.<categoryinfo><subcats> || 0);
my $total = (.<categoryinfo><size> || 0);
$title => [$tasks ,$categories, $total]
});
 
my $out = open($tablefile, :w) or die "$!\n";
 
# Add table boilerplate and header
$out.say:
"\{|class=\"wikitable sortable\"\n",
"|+ As of { Date.today } :: {+%counts} Languages\n",
'!Rank!!Language!!Task<br>Entries!!Tasks<br>done %!!Non-task<br>Subcate-<br>gories!!Total<br>Categories'
;
 
my @bg = <#fff; #ccc;>;
my $ff = 0;
my $rank = 1;
my $ties = 0;
 
# Get sorted unique task counts
for %counts.values»[0].unique.sort: -* -> $count {
$ff++;
# Get list of tasks with this count
my @these = %counts.grep( *.value[0] == $count )».keys.sort: *.&naturally;
 
for @these {
$ties++;
$out.say:
"|- style=\"background-color: { @bg[$ff % 2] }\"\n"~
"|$rank\n"~
"|[[:Category:$_|]]\n"~
"|$count\n"~
"|{(100 * $count/%tasks<Draft Task>.sum).round(.01)} %\n"~
"|{%counts{$_}[1]}\n"~
"|{%counts{$_}[2]}"
}
$rank += $ties;
$ties = 0;
}
$out.say( "|}" );
$out.say('=' x 5, " query, download & processing: {(now - INIT now).round(.01)} seconds ", '=' x 5);
$out.close;
 
sub mediawiki-query ($site, $type, *%query) {
my $url = "$site/api.php?" ~ uri-query-string(
:action<query>, :format<json>, :formatversion<2>, |%query);
my $continue = '';
 
gather loop {
my $response = $client.get("$url&$continue");
my $data = from-json($response.content);
take $_ for $data.<query>.{$type}.values;
$continue = uri-query-string |($data.<query-continue>{*}».hash.hash or last);
}
}
 
sub uri-query-string (*%fields) {
join '&', %fields.map: { "{.key}={uri-escape .value}" }
}</lang>
 
{{out|Abridged output}} See [[Rosetta_Code/Rank_languages_by_popularity/Full_list|full output here]].
{|class="wikitable sortable"
|+ As of 2019-02-10 :: 715 Languages
!Rank!!Language!!Task<br>Entries!!Tasks<br>done %!!Non-task<br>Subcate-<br>gories!!Total<br>Categories
|- style="background-color: #ccc;"
|1
|[[:Category:Go|Go]]
|1100
|96.15 %
|4
|1104
|- style="background-color: #fff;"
|2
|[[:Category:Perl 6|Perl 6]]
|1046
|91.43 %
|4
|1050
|- style="background-color: #ccc;"
|3
|[[:Category:Kotlin|Kotlin]]
|1029
|89.95 %
|1
|1030
|- style="background-color: #fff;"
|4
|[[:Category:Python|Python]]
|1017
|88.9 %
|17
|1034
|- style="background-color: #ccc;"
|5
|[[:Category:Phix|Phix]]
|991
|86.63 %
|3
|994
|- style="background-color: #fff;"
|6
|[[:Category:Racket|Racket]]
|986
|86.19 %
|3
|989
|- style="background-color: #ccc;"
|7
|[[:Category:Perl|Perl]]
|963
|84.18 %
|5
|968
|- style="background-color: #fff;"
|8
|[[:Category:Julia|Julia]]
|958
|83.74 %
|3
|961
|- style="background-color: #ccc;"
|9
|[[:Category:C|C]]
|940
|82.17 %
|3
|943
|- style="background-color: #fff;"
|10
|[[:Category:Tcl|Tcl]]
|925
|80.86 %
|4
|929
|- style="background-color: #ccc;"
|11
|[[:Category:Zkl|Zkl]]
|918
|80.24 %
|1
|919
|- style="background-color: #fff;"
|12
|[[:Category:J|J]]
|901
|78.76 %
|3
|904
|- style="background-color: #ccc;"
|13
|[[:Category:Java|Java]]
|897
|78.41 %
|3
|900
|- style="background-color: #fff;"
|14
|[[:Category:REXX|REXX]]
|886
|77.45 %
|4
|890
|- style="background-color: #ccc;"
|15
|[[:Category:D|D]]
|871
|76.14 %
|3
|874
|- style="background-color: #fff;"
|16
|[[:Category:Ruby|Ruby]]
|866
|75.7 %
|3
|869
|- style="background-color: #ccc;"
|17
|[[:Category:Haskell|Haskell]]
|849
|74.21 %
|3
|852
|- style="background-color: #fff;"
|18
|[[:Category:Scala|Scala]]
|789
|68.97 %
|3
|792
|- style="background-color: #ccc;"
|19
|[[:Category:Sidef|Sidef]]
|787
|68.79 %
|1
|788
|- style="background-color: #fff;"
|20
|[[:Category:PicoLisp|PicoLisp]]
|772
|67.48 %
|3
|775
|}
 
===Raku: Using web scraping===
 
Scraping the languages and categories pages. Raku 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'};
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;
}</lang>
{{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
<lang Red>Red []
 
data: read http://www.rosettacode.org/mw/index.php?title=Special:Categories&limit=5000
lb: make block! 500
;;data: read %data.html ;; for testing save html and use flat file
arr: split data newline
 
k: "Category:"
;; exclude list:
exrule: [thru ["programming"
| "users"
| "Implementations"
| "Solutions by "
| "Members"
| "WikipediaSourced"
| "Typing/Strong"
| "Impl needed"
]
to end
]
foreach line arr [
unless find line k [continue]
parse line [ thru k thru ">" copy lang to "<" to end ] ;; extract/parse language
if 20 < length? lang [continue]
if parse lang [exrule] [continue] ;; exclude invalid
cnt: 0
;; parse number of entries
parse line [thru "</a>" thru "(" copy cnt to " member" (cnt: to-integer cnt ) to end]
if cnt > 25 [ append lb reduce [to-string lang cnt] ] ;; only process lang with > 25 entries
]
 
lb: sort/skip/compare lb 2 2 ;; sort series by entries
 
print reduce [ "Rank Entries Language" ] ;; header
 
last: 0
rank: 0
 
lb: tail lb ;; process the series backwards
 
until [
lb: skip lb -2
cnt: second lb
if cnt <> last [
rank: rank + 1
]
print rejoin [ pad/left rank 4 "." pad/left cnt 5 " - " first lb ]
last: cnt
head? lb ;; until head reached
]
</lang>
Output: (30.12.2017)
<pre>
Rank Entries Language
1. 961 - Racket
2. 959 - Python
3. 926 - Perl 6
4. 918 - Tcl
5. 900 - Kotlin
6. 883 - J
7. 875 - C
8. 859 - Zkl
9. 846 - Ruby
10. 833 - D
11. 828 - Go
12. 812 - REXX
13. 809 - Haskell
14. 802 - Java
15. 785 - Perl
16. 768 - PicoLisp
17. 733 - Sidef
18. 723 - Mathematica
19. 702 - Julia
20. 683 - Phix
21. 668 - C++
22. 648 - Ada
23. 647 - Common Lisp
24. 637 - C sharp
25. 621 - AutoHotkey
</pre>
 
=={{header|REXX}}==
(Native) REXX doesn't support web-page reading, so the mentioned &nbsp; ''Rosetta Code categories'' &nbsp; and
<br>''Rosetta Code Languages'' &nbsp; 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
<br>the &nbsp; ''categories'' &nbsp; file. &nbsp; This essentially is a perfect filter for the &nbsp; ''Rosetta Code categories'' &nbsp; file.
 
The &nbsp; '''catHeap''' &nbsp; variable in the REXX program is just a long string of all the records in the web-file of the
<br>Rosetta Code categories, with a special character ('''sep''') that separates each language entry (name).
 
The mechanism is to use a (sparse) stemmed array which holds only the names of languages which
<br>(for most REXXes) uses a hashing algorithm to locate the entry &nbsp; (which is very fast).
 
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 version now sorts the tied languages by language name (thanks to Walter Pachl's suggestion).
===REXX program===
<lang rexx>/*REXX program reads two files and displays a ranked list of Rosetta Code languages.*/
parse arg catFID lanFID outFID . /*obtain optional arguments from the CL*/
call init /*initialize some REXX variables. */
call get /*obtain data from two separate files. */
call eSort #,0 /*sort languages along with members. */
call tSort /* " " that are tied in rank.*/
call eSort #,1 /* " " along with members. */
call out /*create the RC_POP.OUT (output) file.*/
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
commas: parse arg _; do jc=length(_)-3 to 1 by -3; _= insert(",",_,jc); end; return _
s: if arg(1)==1 then return arg(3); return word(arg(2) 's',1) /*pluralizer.*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
eSort: procedure expose #. @. !tr.; arg N,p2; h= N /*sort: number of members*/
do while h>1; h= h % 2 /*halve number of records*/
do i=1 for N-h; j= i; k= h + 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<···*/
end /*i*/ /*hard swaps needed for embedded blanks.*/
end /*while h>1*/; return
/*──────────────────────────────────────────────────────────────────────────────────────*/
get: langs= 0; call rdr 'languages' /*assign languages ───► L.ααα */
call rdr 'categories' /*append categories ───► catHeap */
#= 0
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= space(translate(mems,,","), 0) /*¬commas.*/
if \datatype(mems, 'W') then iterate /*is the "members" number not numeric? */
#.0= #.0 + mems /*bump the number of members found. */
if u.?\==0 then do; do f=1 for # until ?==@u.f
end /*f*/
#.f= #.f + mems; iterate j /*languages 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*/
 
!.=; @tno= '(total) number of' /*array holds indication of TIED langs.*/
call tell right(commas(#), 9) @tno 'languages detected in the category file'
call tell right(commas(langs),9) ' " " " " " " " language "
call tell right(commas(#.0), 9) @tno 'entries (solutions) detected', , 1; term= 0
return /*don't show any more msgs──►term. [↑] */
/*──────────────────────────────────────────────────────────────────────────────────────*/
init: sep= '█'; L.=0; #.=0; u.=#.; catHeap=; term=1; old.= /*assign some REXX vars*/
if catFID=='' then catFID= "RC_POP.CAT" /*Not specified? Then use the default.*/
if lanFID=='' then lanFID= "RC_POP.LAN" /* " " " " " " */
if outFID=='' then outFID= "RC_POP.OUT" /* " " " " " " */
call tell center('timestamp: ' date() time("Civil"),79,'═'), 2, 1; return
/*──────────────────────────────────────────────────────────────────────────────────────*/
out: w= length( commas(#) ); rank= 0 /* [↓] show by ascending rank of lang.*/
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; 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) */
 
do recs=0 while lines(inFID) \== 0 /*read a file, a single line at a time.*/
$= translate( linein(inFID), , '9'x) /*handle any stray TAB ('09'x) chars.*/
$$= 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
/*──────────────────────────────────────────────────────────────────────────────────────*/
tell: do '0'arg(2); call lineout outFID," " ; if term then say ; 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.*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
tSort: tied=; r= 0 /*add true rank (tR) ───► the entries. */
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*/; return</lang>
 
===all ranked 798 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,
<br>as well as those that use Unicode characters in the name.] <br><br><br>
 
=={{header|Ring}}==
<lang ring>
# Project: Rosetta Code/Rank languages by popularity
load "stdlib.ring"
ros= download("http://rosettacode.org/wiki/Category:Programming_Languages")
pos = 1
totalros = 0
rosname = ""
rosnameold = ""
rostitle = ""
roslist = []
for n = 1 to len(ros)
nr = searchstring(ros,'<li><a href="/wiki/',pos)
if nr = 0
exit
else
pos = nr + 1
ok
nr = searchname(nr)
nr = searchtitle(nr)
next
roslist = sortfirst(roslist)
roslist = reverse(roslist)
 
see nl
for n = 1 to len(roslist)
see "rank: " + n + " (" + roslist[n][1] + " entries) " + roslist[n][2] + nl
next
 
func searchstring(str,substr,n)
newstr=right(str,len(str)-n+1)
nr = substr(newstr, substr)
if nr = 0
return 0
else
return n + nr -1
ok
func count(cstring,dstring)
sum = 0
while substr(cstring,dstring) > 0
sum = sum + 1
cstring = substr(cstring,substr(cstring,dstring)+len(string(sum)))
end
return sum
 
func searchname(sn)
nr2 = searchstring(ros,"/wiki/Category:",sn)
nr3 = searchstring(ros,"title=",sn)
nr4 = searchstring(ros,'">',sn)
nr5 = searchstring(ros,"</a></li>",sn)
rosname = substr(ros,nr2+15,nr3-nr2-17)
rosnameold = substr(ros,nr4+2,nr5-nr4-2)
return sn
func searchtitle(sn)
rostitle = "rosettacode.org/wiki/Category:" + rosname
rostitle = download(rostitle)
nr2 = 0
roscount = count(rostitle,"The following")
if roscount > 0
rp = 1
for rc = 1 to roscount
nr2 = searchstring(rostitle,"The following",rp)
rp = nr2 + 1
next
ok
nr3 = searchstring(rostitle,"pages are in this category",nr2)
if nr2 > 0 and nr3 > 0
rosnr = substr(rostitle,nr2+14,nr3-nr2-15)
rosnr = substr(rosnr,",","")
add(roslist,[rosnr,rosnameold])
ok
return sn
func sortfirst(alist)
for n = 1 to len(alist) - 1
for m = n + 1 to len(alist)
if alist[m][1] < alist[n][1]
swap(alist,m,n)
ok
if alist[m][1] = alist[n][1] and strcmp(alist[m][2],alist[n][2]) > 0
swap(alist,m,n)
ok
next
next
return alist
</lang>
Output:
<pre>
rank: 1 (1010 entries) Kotlin
rank: 2 (977 entries) Racket
rank: 3 (968 entries) Python
rank: 4 (962 entries) Perl 6
rank: 5 (931 entries) Go
rank: 6 (914 entries) Tcl
rank: 7 (905 entries) C
rank: 8 (888 entries) J
rank: 9 (882 entries) Zkl
rank: 10 (875 entries) Java
......
rank: 30 (580 entries) Ring
......
rank: 523 (2 entries) TechBASIC
rank: 524 (2 entries) Thyrd
rank: 525 (2 entries) ToffeeScript
rank: 526 (2 entries) Viua VM assembly
rank: 527 (2 entries) XL
rank: 528 (2 entries) XProc
rank: 529 (2 entries) XSLT 1.0
rank: 530 (2 entries) XTalk
rank: 531 (2 entries) XUL
rank: 532 (2 entries) ZPL
</pre>
 
=={{header|Ruby}}==
===By using the API===
{{works with|Ruby|1.8.7}}
Now that there are more than 500 categories, the URL given in the task description is insufficient. I use the RC API to grab the categories, and then count the members of each category.
 
Uses the <code>RosettaCode</code> module from [[Count programming examples#Ruby]]
<lang ruby>require 'rosettacode'
 
langs = []
RosettaCode.category_members("Programming Languages") {|lang| langs << lang}
 
# API has trouble with long titles= values.
# To prevent skipping languages, use short slices of 20 titles.
langcount = {}
langs.each_slice(20) do |sublist|
url = RosettaCode.get_api_url({
"action" => "query",
"prop" => "categoryinfo",
"format" => "xml",
"titles" => sublist.join("|"),
})
 
doc = REXML::Document.new open(url)
REXML::XPath.each(doc, "//page") do |page|
lang = page.attribute("title").value
info = REXML::XPath.first(page, "categoryinfo")
langcount[lang] = info.nil? ? 0 : info.attribute("pages").value.to_i
end
end
 
puts Time.now
puts "There are #{langcount.length} languages"
puts "the top 25:"
langcount.sort_by {|key,val| val}.reverse[0,25].each_with_index do |(lang, count), i|
puts "#{i+1}. #{count} - #{lang.sub(/Category:/, '')}"
end</lang>
{{out|Results}}
<pre style="height: 40ex; overflow: scroll">2010-07-08 14:52:46 -0500
There are 306 languages
the top 25:
1. 399 - Tcl
2. 370 - Python
3. 352 - Ruby
4. 338 - J
5. 337 - C
6. 333 - PicoLisp
7. 322 - OCaml
8. 322 - Haskell
9. 299 - Perl
10. 299 - AutoHotkey
11. 288 - Common Lisp
12. 280 - Java
13. 275 - Ada
14. 270 - D
15. 267 - Oz
16. 253 - R
17. 252 - PureBasic
18. 245 - E
19. 243 - C++
20. 241 - C sharp
21. 239 - ALGOL 68
22. 236 - JavaScript
23. 221 - Forth
24. 207 - Clojure
25. 201 - Fortran</pre>
 
=={{header|Run BASIC}}==
<lang runbasic>sqliteconnect #mem, ":memory:" ' make memory DB
#mem execute("CREATE TABLE stats(lang,cnt)")
a$ = httpGet$("http://rosettacode.org/wiki/Category:Programming_Languages")
aa$ = httpGet$("http://www.rosettacode.org/mw/index.php?title=Special:Categories&limit=5000")
i = instr(a$,"/wiki/Category:")
while i > 0 and lang$ <> "Languages"
j = instr(a$,"""",i)
lang$ = mid$(a$,i+15,j - i-15)
ii = instr(aa$,"Category:";lang$;"""")
jj = instr(aa$,"(",ii)
kk = instr(aa$," ",jj+1)
if ii = 0 then cnt = 0 else cnt = val(mid$(aa$,jj+1,kk-jj))
k = instr(lang$,"%") ' convert hex values to characters
while k > 0
lang$ = left$(lang$,k-1) + chr$(hexdec(mid$(lang$,k+1,2))) + mid$(lang$,k+3)
k = instr(lang$,"%")
wend
#mem execute("insert into stats values ('";lang$;"',";cnt;")")
i = instr(a$,"/wiki/Category:",i+10)
wend
html "<table border=2>"
#mem execute("SELECT * FROM stats ORDER BY cnt desc") ' order list by count descending
WHILE #mem hasanswer()
#row = #mem #nextrow()
rank = rank + 1
html "<TR><TD align=right>";rank;"</td><td>";#row lang$();"</td><td align=right>";#row cnt();"</td></tr>"
WEND
html "</table>"</lang>
<table border=2>
<TR><TD align=right>1</td><td>Tcl</td><td align=right>687</td></tr>
<TR><TD align=right>2</td><td>Python</td><td align=right>650</td></tr>
<TR><TD align=right>3</td><td>C</td><td align=right>638</td></tr>
<TR><TD align=right>4</td><td>PicoLisp</td><td align=right>626</td></tr>
<TR><TD align=right>5</td><td>J</td><td align=right>619</td></tr>
<TR><TD align=right>6</td><td>Go</td><td align=right>587</td></tr>
<TR><TD align=right>7</td><td>Ruby</td><td align=right>581</td></tr>
<TR><TD align=right>8</td><td>D</td><td align=right>571</td></tr>
<TR><TD align=right>9</td><td>Ada</td><td align=right>559</td></tr>
<TR><TD align=right>10</td><td>Mathematica</td><td align=right>551</td></tr>
<TR><TD align=right>11</td><td>Perl</td><td align=right>528</td></tr>
<TR><TD align=right>12</td><td>Perl_6</td><td align=right>528</td></tr>
<TR><TD align=right>13</td><td>Haskell</td><td align=right>526</td></tr>
<TR><TD align=right>14</td><td>BBC_BASIC</td><td align=right>513</td></tr>
<TR><TD align=right>15</td><td>REXX</td><td align=right>491</td></tr>
<TR><TD align=right>16</td><td>Java</td><td align=right>488</td></tr>
<TR><TD align=right>17</td><td>OCaml</td><td align=right>477</td></tr>
<TR><TD align=right>18</td><td>PureBasic</td><td align=right>469</td></tr>
<TR><TD align=right>19</td><td>Unicon</td><td align=right>462</td></tr>
<TR><TD align=right>20</td><td>AutoHotkey</td><td align=right>430</td></tr>
<TR><TD align=right>21</td><td>Icon</td><td align=right>429</td></tr>
<TR><TD align=right>22</td><td>Common_Lisp</td><td align=right>424</td></tr>
<TR><TD align=right>23</td><td>C_sharp</td><td align=right>416</td></tr>
<TR><TD align=right>24</td><td>C++</td><td align=right>400</td></tr>
<TR><TD align=right>25</td><td>JavaScript</td><td align=right>359</td></tr>
<TR><TD align=right>26</td><td>Scala</td><td align=right>339</td></tr>
<TR><TD align=right>27</td><td>PARI/GP</td><td align=right>338</td></tr>
<TR><TD align=right>28</td><td>Clojure</td><td align=right>335</td></tr>
<TR><TD align=right>29</td><td>R</td><td align=right>322</td></tr>
<TR><TD align=right>n</td><td>...</td><td align=right>...</td></tr></table>
 
=={{header|Scala}}==
===Parallel internet querying===
Entry point @ object <code>GhettoParserPar</code>
<lang scala>import akka.actor.{Actor, ActorSystem, Props}
import scala.collection.immutable.TreeSet
import scala.xml.XML
 
// Reports a list with all languages recorded in the Wiki
 
private object Acquisition {
val (endPoint, prefix) = ("http://rosettacode.org/mw/api.php", "Category:")
val (maxPlaces, correction) = (50, 2)
 
def convertPathArgsToURL(endPoint: String, pathArgs: Map[String, String]) = {
pathArgs.map(argPair => argPair._1 + "=" + argPair._2)
.mkString(endPoint + (if (pathArgs.nonEmpty) "?" else ""), "&", "")
}
 
/* The categories include a page for the language and a count of the pages
* linked therein, this count is the data we need to scrape.
* Reports a list with language, count pair recorded in the Wiki
* All strings starts with the prefixes "Category:"
*/
def mineCatos = {
val endPoint = "http://rosettacode.org/mw/index.php"
Concurrent.logInfo("Acquisition of categories started.")
val categories =
(XML.load(convertPathArgsToURL(endPoint,
Map("title" -> "Special:Categories", "limit" -> "5000"))) \\ "ul" \ "li")
.withFilter(p => (p \ "a" \ "@title").text.startsWith(prefix))
.map // Create a tuple pair, eg. ("Category:Erlang", 195)
{ cat =>
((cat \ "a" \ "@title").text, // Takes the sibling of "a" and extracts the number
"[0-9]+".r.findFirstIn(cat.child.drop(1).text).getOrElse("0").toInt)
}
Concurrent.logInfo(s"Got ${categories.size} categories..")
categories
}
 
// The languages
// All strings starts with the prefixes "Category:"
def mineLangs = {
Concurrent.logInfo("Acquisition of languages started...")
def getLangs(first: Boolean = true, continue: String = ""): TreeSet[String] = (first, continue) match {
case (false, "") => TreeSet[String]()
case _ => {
val xml = XML.load(convertPathArgsToURL(endPoint, Map(
"action" -> "query",
"list" -> "categorymembers",
"cmtitle" -> (prefix + "Programming_Languages"),
"cmlimit" -> "500",
"rawcontinue" -> "",
"format" -> "xml",
"cmcontinue" -> continue)))
getLangs(false, (xml \\ "query-continue" \ "categorymembers" \ "@cmcontinue").text) ++ (xml \\ "categorymembers" \ "cm").map(c => (c \ "@title").text)
}
}
val languages = getLangs()
Concurrent.logInfo(s"Got ${languages.size} languages..")
languages
}
 
def joinRosettaCodeWithLanguage(catos: Seq[(String, Int)],
langs: TreeSet[String]) =
for {
cato <- catos //Clean up the tuple pairs, eg ("Category:Erlang", 195) becomes ("Erlang", 192)
if langs.contains(cato._1)
} yield (cato._1.drop(prefix.length), cato._2 - correction max 0) // Correct count
 
def printScrape(languages: TreeSet[String], category: Seq[(String, Int)]) {
 
val join = joinRosettaCodeWithLanguage(category, languages)
val total = join.foldLeft(0)(_ + _._2)
 
Concurrent.logInfo("Data processed")
 
println(f"\nTop$maxPlaces%3d Rosetta Code Languages by Popularity as ${new java.util.Date}%tF:\n")
(join.groupBy(_._2).toSeq.sortBy(-_._1).take(maxPlaces) :+ (0, Seq(("...", 0))))
.zipWithIndex // Group the ex aequo
.foreach {
case ((score, langs), rank) =>
println(f"${rank + 1}%2d. $score%3d - ${langs.map(_._1).mkString(", ")}")
}
 
println(s"\nCross section yields ${join.size} languages, total of $total solutions")
println(s"Resulting average is ${total / join.size} solutions per language")
}
 
def printScrape(): Unit = printScrape(mineLangs, mineCatos)
} // object Acquisition
 
private object Concurrent extends AppCommons {
var (category: Option[Seq[(String, Int)]], language: Option[TreeSet[String]]) = (None, None)
 
class Worker extends Actor {
def receive = {
case 'Catalogue => sender ! Acquisition.mineCatos
case 'Language => sender ! Acquisition.mineLangs
}
}
 
class Listener extends Actor {
// Create and signal the worker actors
context.actorOf(Props[Worker], "worker0") ! 'Catalogue
context.actorOf(Props[Worker], "worker1") ! 'Language
 
def printCompleteScape() =
if (category.isDefined && language.isDefined) {
Acquisition.printScrape(language.get, category.get)
context.system.shutdown()
appEnd()
}
 
def receive = {
case content: TreeSet[String] =>
language = Some(content)
printCompleteScape()
case content: Seq[(String, Int)] =>
category = Some(content)
printCompleteScape()
case whatever => logInfo(whatever.toString)
} // def receive
}
} // object Concurrent
 
trait AppCommons {
val execStart = System.currentTimeMillis()
System.setProperty("http.agent", "*")
 
def logInfo(info: String) {
println(f"[Info][${System.currentTimeMillis() - execStart}%5d ms]" + info)
}
 
def appEnd() { logInfo("Run succesfully completed") }
}
 
// Main entry for sequential version (slower)
object GhettoParserSeq extends App with AppCommons {
Concurrent.logInfo("Sequential version started")
Acquisition.printScrape()
appEnd()
}
 
// Entry for parallel version (faster)
object GhettoParserPar extends App {
Concurrent.logInfo("Parallel version started")
ActorSystem("Main").actorOf(Props[Concurrent.Listener])
}</lang>
 
===Sequential internet querying===
The same code above but as entry point object <code>GhettoParserSeq</code>
{{Out|Output for both solutions}} but parallel run chosen. Notice the synchronous start time.
<pre>[Info][ 0 ms]Sequential version started
[Info][ 3 ms]Acquisition of languages started...
[Info][ 1458 ms]Got 642 languages..
[Info][ 1458 ms]Acquisition of categories started.
[Info][19385 ms]Got 2647 categories..
[Info][19389 ms]Data processed
 
Top 50 Rosetta Code Languages by Popularity as 2016-11-11:
 
1. 907 - Racket
2. 896 - Python, Tcl
3. 859 - J
4. 846 - Perl 6
5. 810 - Ruby
6. 807 - Zkl
7. 795 - C
8. 774 - Java
9. 773 - Go
10. 754 - Haskell
11. 753 - Perl
12. 751 - REXX
13. 750 - D
14. 729 - PicoLisp
15. 689 - Mathematica
16. 674 - Sidef
17. 634 - C++
18. 631 - Ada
19. 609 - AutoHotkey
20. 592 - Common Lisp
21. 583 - Unicon
22. 569 - Scala
23. 560 - C sharp
24. 546 - BBC BASIC
25. 526 - Icon
26. 522 - Clojure
27. 520 - JavaScript
28. 519 - OCaml
29. 517 - PureBasic
30. 513 - PARI/GP
31. 510 - Lua
32. 509 - Nim
33. 497 - ALGOL 68
34. 491 - Elixir
35. 488 - Fortran
36. 474 - Erlang
37. 430 - PowerShell
38. 428 - Julia
39. 414 - Jq
40. 413 - F Sharp
41. 409 - Phix
42. 407 - Pascal
43. 405 - Forth, Seed7
44. 398 - PL/I
45. 383 - R
46. 382 - PHP
47. 377 - Groovy
48. 370 - AWK
49. 340 - MATLAB
50. 333 - Liberty BASIC
51. 0 - ...
 
Cross section yields 619 languages, total of 50835 solutions
Resulting average is 82 solutions per language
[Info][19413 ms]Run succesfully completed</pre>
 
=={{header|Seed7}}==
<lang seed7>$ include "seed7_05.s7i";
include "gethttp.s7i";
include "scanstri.s7i";
 
const type: popularityHash is hash [string] integer;
const type: rankingHash is hash [integer] array string;
 
const func array string: getLangs (in string: buffer) is func
result
var array string: langs is 0 times "";
local
var integer: pos is 0;
begin
pos := pos(buffer, "Category:");
while pos <> 0 do
pos +:= 9;
langs &:= buffer[pos .. pred(pos(buffer, '"', pos))];
pos := pos(buffer, "Category:", pos);
end while;
end func;
 
const proc: main is func
local
var string: categories is "";
var popularityHash: popularity is popularityHash.value;
var rankingHash: ranking is rankingHash.value;
var array integer: numList is 0 times 0;
var string: lang is "";
var integer: pos is 0;
var string: numStri is "";
var integer: listIdx is 0;
var integer: index is 0;
var integer: place is 1;
begin
categories := getHttp("www.rosettacode.org/w/index.php?title=Special:Categories&limit=5000");
for lang range getLangs(getHttp("rosettacode.org/mw/api.php?action=query&list=categorymembers&\
\cmtitle=Category:Programming_Languages&cmlimit=500&format=json")) do
pos := pos(categories, "title=\"Category:" & lang);
if pos <> 0 then
pos := pos(categories, "</a>", succ(pos));
if pos <> 0 then
pos := pos(categories, "(", succ(pos));
if pos <> 0 then
numStri := categories[succ(pos) len 10];
popularity @:= [lang] integer parse getDigits(numStri);
end if;
end if;
end if;
end for;
ranking := flip(popularity);
numList := sort(keys(ranking));
for listIdx range maxIdx(numList) downto minIdx(numList) do
for key index range ranking[numList[listIdx]] do
writeln(place lpad 3 <& ". " <& numList[listIdx] <& " - " <& ranking[numList[listIdx]][index]);
end for;
place +:= length(ranking[numList[listIdx]]);
end for;
end func;</lang>
 
List of languages as of 2014-01-15:
<pre>
1. 772 - Tcl
2. 733 - Racket
3. 718 - Python
4. 685 - C
5. 657 - Perl 6
6. 654 - J
7. 645 - D
8. 643 - Ruby
9. 636 - PicoLisp
10. 624 - Go
11. 610 - Perl
12. 579 - REXX
13. 578 - Ada
14. 567 - Mathematica
14. 567 - Haskell
16. 532 - Unicon
17. 526 - Java
18. 523 - BBC BASIC
19. 489 - OCaml
20. 487 - Icon
21. 477 - C++
22. 470 - PureBasic
23. 448 - Common Lisp
24. 439 - Erlang
24. 439 - C sharp
26. 437 - AutoHotkey
27. 406 - Scala
28. 382 - JavaScript
29. 375 - Clojure
30. 356 - Seed7
...
</pre>
 
=={{header|Sidef}}==
{{trans|Perl}}
<lang ruby>require('MediaWiki::API')
 
var api = %O<MediaWiki::API>.new(
Hash(api_url => 'http://rosettacode.org/mw/api.php')
)
 
var languages = []
var gcmcontinue
loop {
var apih = api.api(
Hash(
action => 'query',
generator => 'categorymembers',
gcmtitle => 'Category:Programming Languages',
gcmlimit => 250,
prop => 'categoryinfo',
gcmcontinue => gcmcontinue,
)
)
 
languages.append(apih{:query}{:pages}.values...)
gcmcontinue = apih{:continue}{:gcmcontinue}
gcmcontinue || break
}
 
languages.each { |lang|
lang{:title} -= /^Category:/
lang{:categoryinfo}{:size} := 0
}
 
var sorted_languages = languages.sort_by { |lang|
-lang{:categoryinfo}{:size}
}
 
sorted_languages.each_kv { |i, lang|
printf("%3d. %20s - %3d\n", i+1, lang{:title}, lang{:categoryinfo}{:size})
}</lang>
{{out}}
<pre>
1. Racket - 938
2. Python - 930
3. Tcl - 904
4. Perl 6 - 877
5. J - 863
6. Zkl - 834
7. Ruby - 830
8. C - 805
9. Go - 793
10. Haskell - 785
11. Java - 783
12. REXX - 776
13. Perl - 765
14. D - 753
15. PicoLisp - 731
16. Mathematica - 702
17. Sidef - 696
...
</pre>
 
=={{header|SNOBOL4}}==
{{Works with|SNOBOL4|CSNOBOL4 CVS test}}
<lang SNOBOL4>-include "url.sno"
http.recl = "K,32767" ;* Read next 32767 characters
;* of very long lines.
 
rclangs = "http://rosettacode.org/mw/api.php?"
+ "format=xml&action=query&generator=categorymembers&"
+ "gcmtitle=Category:Programming%20Languages&"
+ "gcmlimit=500&prop=categoryinfo"
 
languagepat = arb "<page" arb 'title="Category:'
+ break('"') . lang arb 'pages="' break('"') . count
 
langtable = table(500, 20)
 
url.open(.fin, rclangs, http.recl) :s(read)
output = "Cannot open rosettacode site." :(end)
 
read line = line fin :f(done)
get line languagepat = :f(read)
langtable<lang> = langtable<lang> + count :(get)
done langarray = rsort(langtable,2) :s(write)
output = "No languages found." :(end)
 
write n = n + 1
output = lpad(n ". ", 5) lpad(langarray<n, 2>, 4)
+ " - " langarray<n,1> :s(write)
url.close(.fin)
end</lang>
 
'''Abridged output (top 30 languages as of August 25, 2015):'''
 
<pre> 1. 875 - Racket
2. 837 - Python
3. 799 - J
4. 772 - Ruby
5. 763 - Perl 6
6. 756 - C
7. 742 - Go
8. 737 - D
9. 707 - Perl
10. 699 - REXX
11. 689 - PicoLisp
12. 683 - Haskell
13. 672 - Mathematica
14. 650 - Java
15. 620 - Ada
16. 588 - AutoHotkey
17. 563 - C++
18. 553 - Common Lisp
19. 546 - Scala
20. 529 - BBC BASIC
21. 520 - Icon
22. 513 - C sharp
23. 505 - OCaml
24. 501 - Nim
25. 487 - PureBasic
26. 485 - Clojure
27. 455 - Epigram
28. 443 - PARI/GP
29. 431 - JavaScript
30. 410 - Jq</pre>
 
=={{header|Stata}}==
 
First we build the database:
 
<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:")
gen i = ustrpos(v1,"title=")
gen j = ustrpos(v1,char(34),i+1)
gen k = ustrpos(v1,char(34),j+1)
gen s = usubstr(v1,j,k-j+1)
keep if usubstr(s,2,9)=="Category:"
gen lang=usubstr(s,11,ustrlen(s)-11)
keep lang
save lang, replace
 
copy "http://rosettacode.org/mw/index.php?title=Special:Categories&limit=5000" categ.html, replace
import delimited categ.html, delim("@") enc("utf-8") clear
keep if ustrpos(v1,"/wiki/Category:") & ustrpos(v1,"member")
gen i = ustrpos(v1,"title=")
gen j = ustrpos(v1,char(34),i+1)
gen k = ustrpos(v1,char(34),j+1)
gen s = usubstr(v1,j,k-j+1)
keep if usubstr(s,2,9)=="Category:"
gen lang=usubstr(s,11,ustrlen(s)-11)
drop i j k s
gen i = ustrrpos(v1,"(")
gen j = ustrrpos(v1,")")
gen s = usubstr(v1,i,j-i+1)
gen k = ustrpos(s," ")
gen t = usubstr(s,2,k-1)
destring t, gen(count)
drop v1 i j k s t
merge 1:1 lang using lang, keep(2 3) nogen
replace count=0 if missing(count)
gsort -count lang
gen rank=1
replace rank=rank[_n-1]+(count[_n]!=count[_n-1]) in 2/l
save tasks, replace</lang>
 
Now some results, as of 2017-12-03:
 
<lang stata>* Total number of entries
qui sum n
di r(sum)
57211
 
* Number of languages
count
671
 
* Number of languages with at least one entry
count if count
650
 
* First 10 languages
list in 1/10, noobs
 
+-----------------------+
| lang count rank |
|-----------------------|
| Racket 961 1 |
| Python 958 2 |
| Perl 6 925 3 |
| Tcl 918 4 |
| J 883 5 |
|-----------------------|
| C 874 6 |
| Kotlin 868 7 |
| Zkl 857 8 |
| Ruby 845 9 |
| Go 828 10 |
+-----------------------+</lang>
 
=={{header|Tcl}}==
===By web scraping===
<lang tcl>package require Tcl 8.5
package require http
set response [http::geturl http://rosettacode.org/mw/index.php?title=Special:Categories&limit=8000]
array set ignore {
"Basic language learning" 1
"Encyclopedia" 1
"Implementations" 1
"Language Implementations" 1
"Language users" 1
"Maintenance/OmitCategoriesCreated" 1
"Programming Languages" 1
"Programming Tasks" 1
"RCTemplates" 1
"Solutions by Library" 1
"Solutions by Programming Language" 1
"Solutions by Programming Task" 1
"Unimplemented tasks by language" 1
"WikiStubs" 1
"Examples needing attention" 1
"Impl needed" 1
}
# need substring filter
proc filterLang {n} {
return [expr {[string first "User" $n] > 0}]
}
# (sorry the 1 double quote in the regexp kills highlighting)
foreach line [split [http::data $response] \n] {
if {[regexp {title..Category:([^"]+).* \((\d+) members\)} $line -> lang num]} {
if {![info exists ignore($lang)] && ![filterLang $lang]} {
lappend langs [list $num $lang]
}
}
}
foreach entry [lsort -integer -index 0 -decreasing $langs] {
lassign $entry num lang
puts [format "%d. %d - %s" [incr i] $num $lang]
}</lang>
{{out|Output on 29 July 2015 (top 20 entries only)}}
<pre>1. 887 - Tcl
2. 877 - Racket
3. 853 - Python
4. 795 - J
5. 775 - Ruby
6. 766 - Perl 6
7. 757 - C
8. 746 - Go
9. 740 - D
10. 710 - Perl
11. 697 - REXX
12. 692 - PicoLisp
13. 682 - Haskell
14. 675 - Mathematica
15. 652 - Java
16. 634 - Zkl
17. 623 - Ada
18. 591 - AutoHotkey
19. 581 - Unicon
20. 562 - C++
……</pre>
 
===By using the API===
{{trans|Ruby}}
{{works with|Tcl|8.5}}
{{libheader|tDOM}}
 
<lang tcl>package require Tcl 8.5
package require http
package require tdom
namespace eval rc {
### Utility function that handles the low-level querying ###
proc rcq {q xp vn b} {
upvar 1 $vn v
dict set q action "query"
# Loop to pick up all results out of a category query
while 1 {
set url "http://rosettacode.org/mw/api.php?[http::formatQuery {*}$q]"
puts -nonewline stderr . ;# Indicate query progress...
set token [http::geturl $url]
set doc [dom parse [http::data $token]]
http::cleanup $token
# Spoon out the DOM nodes that the caller wanted
foreach v [$doc selectNodes $xp] {
uplevel 1 $b
}
# See if we want to go round the loop again
set next [$doc selectNodes "//query-continue/categorymembers"]
if {![llength $next]} break
dict set q cmcontinue [[lindex $next 0] getAttribute "cmcontinue"]
}
}
### API function: Iterate over the members of a category ###
proc members {page varName script} {
upvar 1 $varName var
set query [dict create cmtitle "Category:$page" {*}{
list "categorymembers"
format "xml"
cmlimit "500"
}]
rcq $query "//cm" item {
# Tell the caller's script about the item
set var [$item getAttribute "title"]
uplevel 1 $script
}
}
### API function: Count the members of a list of categories ###
proc count {cats catVar countVar script} {
upvar 1 $catVar cat $countVar count
set query [dict create prop "categoryinfo" format "xml"]
for {set n 0} {$n<[llength $cats]} {incr n 20} { ;# limit fetch to 20 at a time
dict set query titles [join [lrange $cats $n $n+19] |]
rcq $query "//page" item {
# Get title and count
set cat [$item getAttribute "title"]
set info [$item getElementsByTagName "categoryinfo"]
if {[llength $info]} {
set count [[lindex $info 0] getAttribute "pages"]
} else {
set count 0
}
# Let the caller's script figure out what to do with them
uplevel 1 $script
}
}
}
### Assemble the bits into a whole API ###
namespace export members count
namespace ensemble create
}
# Get the list of programming languages
rc members "Programming Languages" lang {
lappend langs $lang
}
puts stderr "" ;# Because of the progress dots...
puts "There are [llength $langs] languages"
 
# Get the count of solutions for each, stripping "Category:" prefix
rc count $langs l c {
dict set langcounts [regsub {^Category:} $l {}] $c
}
puts stderr "" ;# Because of the progress dots...
 
# Print the output
puts "Here are the top fifteen:"
set langcounts [lsort -stride 2 -index 1 -integer -decreasing $langcounts]
set i 0
foreach {lang count} $langcounts {
puts [format "%1\$3d. %3\$3d - %2\$s" [incr n] $lang $count]
if {[incr i]>=15} break
}
 
# --- generate a full report, similar in format to REXX example
proc popreport {langcounts} {
set bycount {}
foreach {lang count} $langcounts {
dict lappend bycount $count $lang
}
set bycount [lsort -stride 2 -integer -decreasing $bycount]
set rank 1
foreach {count langs} $bycount {
set tied [expr {[llength $langs] > 1 ? "\[tied\]" : ""}]
foreach lang $langs {
puts [format {%15s:%4d %-12s %12s %s} rank $rank $tied "($count entries)" $lang]
}
incr rank [llength $langs]
}
}
 
popreport $langcounts</lang>
 
{{out}}
<pre>..
There are 582 languages
..............................
Here are the top fifteen:
1. 882 - Tcl
2. 874 - Racket
3. 837 - Python
4. 790 - J
5. 772 - Ruby
6. 762 - Perl 6
7. 754 - C
8. 739 - Go
9. 736 - D
10. 706 - Perl
11. 694 - REXX
12. 689 - PicoLisp
13. 679 - Haskell
14. 672 - Mathematica
15. 649 - Java</pre>
 
Full output is included at [[Rosetta_Code/Rank_languages_by_popularity/Tcl_API_full_output]].
 
=={{header|TUSCRIPT}}==
<lang tuscript>$$ MODE TUSCRIPT
remotedata = REQUEST ("http://www.rosettacode.org/mw/index.php?title=Special:Categories&limit=5000")
allmembers=allnames=""
COMPILE
LOOP d=remotedata
IF (d.sw."<li>") THEN
name=EXTRACT (d,":<<a<><%>>:"|,":<</a>>:")
IF (name.eq."Language users") CYCLE
IF (name.sw."Unimplemented tasks") CYCLE
IF (name.sw."Programming") CYCLE
IF (name.sw."Solutions") CYCLE
IF (name.sw."Garbage") CYCLE
IF (name.sw."Typing") CYCLE
IF (name.sw."BASIC LANG") CYCLE
IF (name.ew."USER") CYCLE
IF (name.ew."tasks") CYCLE
IF (name.ew."attention") CYCLE
IF (name.ew."related") CYCLE
IF (name.ct."*omit*") CYCLE
IF (name.ct.":*Categor*:") CYCLE
IF (name.ct.":WikiSTUBS:") CYCLE
IF (name.ct.":Impl needed:") CYCLE
IF (name.ct.":Implementations:") CYCLE
IF (name.ct.":':") name = EXCHANGE (name,":'::")
members = STRINGS (d,":><1<>>/><<> member:")
IF (members!="") THEN
allmembers=APPEND (allmembers,members)
allnames =APPEND (allnames,name)
ENDIF
ENDIF
ENDLOOP
index = DIGIT_INDEX (allmembers)
index = REVERSE (index)
allmembers = INDEX_SORT (allmembers,index)
allnames = INDEX_SORT (allnames, index)
ERROR/STOP CREATE ("list",SEQ-E,-std-)
time=time(),balt=nalt=""
FILE "list" = time
LOOP n, a=allnames,b=allmembers
IF (b==balt) THEN
nr=nalt
ELSE
nalt=nr=n
ENDIF
content=concat (nr,". ",a," --- ",b)
FILE "list" = CONTENT
balt=b
ENDLOOP
ENDCOMPILE</lang>
{{out}}
<pre style='height:30ex;overflow:scroll'>
2011-01-24 14:05:27
1. Tcl --- 472 member
2. PicoLisp --- 441 member
3. Python --- 432 member
4. J --- 414 member
5. C --- 394 member
6. Ruby --- 385 member
7. PureBasic --- 371 member
8. Haskell --- 369 member
9. Ada --- 364 member
10. OCaml --- 352 member
11. Perl --- 339 member
11. D --- 339 member
13. Java --- 325 member
14. AutoHotkey --- 308 member
15. Common Lisp --- 305 membe
16. C sharp --- 301 member
17. C++ --- 285 member
18. Oz --- 278 member
19. Clojure --- 272 member
20. R --- 266 member
21. ALGOL 68 --- 262 member
22. Perl 6 --- 258 member
23. JavaScript --- 257 member
24. E --- 254 member
25. REXX --- 253 member
26. Fortran --- 251 member
27. Forth --- 248 member
28. Lua --- 238 member
29. PHP --- 215 member
30. Unicon --- 211 member
31. Icon --- 210 member
32. Factor --- 207 member
33. Scala --- 197 member
34. PL/I --- 193 member
34. Go --- 193 member
36. Scheme --- 186 member
</pre>
 
=={{header|UnixPipes}}==
 
{{libheader|curl}}
<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}'</lang>
 
=={{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.
<lang vb> '''''''''''''''''''''''''''''''''''''''''''''
' Rosetta Code/Rank Languages by Popularity '
' VBScript Implementation '
'...........................................'
 
'API Links (From C Code)
URL1 = "http://www.rosettacode.org/mw/api.php?format=json&action=query&generator=categorymembers&gcmtitle=Category:Programming%20Languages&gcmlimit=500&prop=categoryinfo&rawcontinue"
URL2 = "http://www.rosettacode.org/mw/api.php?format=json&action=query&generator=categorymembers&gcmtitle=Category:Programming%20Languages&gcmlimit=500&prop=categoryinfo&gcmcontinue="
 
'Get Contents of the API from the Web...
Function ScrapeGoat(link)
On Error Resume Next
ScrapeGoat = ""
Err.Clear
Set objHttp = CreateObject("Msxml2.ServerXMLHTTP")
objHttp.Open "GET", link, False
objHttp.Send
If objHttp.Status = 200 And Err = 0 Then ScrapeGoat = objHttp.ResponseText
Set objHttp = Nothing
End Function
 
'HACK: Setup HTML for help of my partner/competitor that is better than me, JavaScript...
Set HTML = CreateObject("HtmlFile")
Set HTMLWindow = HTML.ParentWindow
 
 
''''''''''''''''''''
' Main code begins '
'..................'
 
On Error Resume Next
 
isComplete = 0 ' 1 -> Complete Already
cntLoop = 0 ' Counts Number of Loops Done
Set outputData = CreateObject("Scripting.Dictionary")
 
Do
'Scrape Data From API
If cntLoop = 0 Then strData = ScrapeGoat(URL1) Else strData = ScrapeGoat(URL2 & gcmCont)
If Len(strData) = 0 Then
Set HTML = Nothing
WScript.StdErr.WriteLine "Processing of data stopped because API query failed."
WScript.Quit(1)
End If
 
'Parse JSON HACK
HTMLWindow.ExecScript "var json = " & strData, "JavaScript"
Set ObjJS = HTMLWindow.json
 
Err.Clear 'Test if Query is Complete Already
batchCompl = ObjJS.BatchComplete
If Err.Number = 438 Then
'Query not yet complete. Get gcmContinue instead.
gcmCont = ObjJS.[Query-Continue].CategoryMembers.gcmContinue
Else
isComplete = 1 'Yes!
End If
 
'HACK #2: Put all language page ids into a JS array to be accessed by VBScript
HTMLWindow.ExecScript "var langs=new Array(); for(var lang in json.query.pages){langs.push(lang);}" & _
"var nums=langs.length;", "JavaScript"
Set arrLangs = HTMLWindow.langs
arrLength = HTMLWindow.nums
 
For i = 0 to arrLength - 1
BuffStr = "ObjJS.Query.Pages.[" & Eval("arrLangs.[" & i & "]") & "]"
EachStr = Eval(BuffStr & ".title")
 
Err.Clear
CntLang = Eval(BuffStr & ".CategoryInfo.Pages")
If InStr(EachStr, "Category:") = 1 And Err.Number = 0 Then
outputData.Add Replace(EachStr, "Category:", "", 1, 1), CntLang
End If
Next
 
cntLoop = cntLoop + 1
Loop While isComplete = 0
'The outputData now contains the data we need. We should now sort and print it!
 
'Make a 2D array with copy of outputData
arrRelease = Array()
ReDim arrRelease(UBound(outputData.Keys), 1)
 
outKeys = outputData.Keys
outItem = outputData.Items
For i = 0 To UBound(outKeys)
arrRelease(i, 0) = outKeys(i)
arrRelease(i, 1) = outItem(i)
Next
 
'Bubble Sort (Greatest to Least Number of Examples)
For i = 0 to UBound(arrRelease, 1)
For j = 0 to UBound(arrRelease, 1) - 1
If arrRelease(j, 1) < arrRelease(j + 1, 1) Then
temp1 = arrRelease(j + 1, 0)
temp2 = arrRelease(j + 1, 1)
arrRelease(j + 1, 0) = arrRelease(j, 0)
arrRelease(j + 1, 1) = arrRelease(j, 1)
arrRelease(j, 0) = temp1
arrRelease(j, 1) = temp2
End If
Next
Next
 
'Save contents to file instead to support Unicode Names
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set txtOut = objFSO.CreateTextFile(".\OutVBRC.txt", True, True)
 
txtOut.WriteLine "As of " & Now & ", RC has " & UBound(arrRelease) + 1 & " languages."
txtOut.WriteLine ""
For i = 0 to UBound(arrRelease)
txtOut.WriteLine arrRelease(i, 1) & " Examples - " & arrRelease(i, 0)
Next
 
'Successfully Done :)
Set HTML = Nothing
Set objFSO = Nothing
WScript.Quit(0)</lang>
{{Out|Some Parts of Output as of December 31, 2016}}
<pre>As of 12/31/2016 11:52:05 PM, RC has 624 languages.
 
917 Examples - Racket
906 Examples - Python
894 Examples - Tcl
859 Examples - J
853 Examples - Perl 6
819 Examples - Zkl
813 Examples - Ruby
796 Examples - C
776 Examples - Java
774 Examples - Go
766 Examples - Haskell
760 Examples - REXX
755 Examples - Perl
750 Examples - D
 
.
.
.
 
0 Examples - SheerPower 4GL
0 Examples - Script Basic
0 Examples - VRML
0 Examples - Thistle
0 Examples - UserRPL
0 Examples - WML
0 Examples - VAX Assembly</pre>
 
=={{header|zkl}}==
Using cURL and YAJL (yet anothe JSON library) libraries.
 
This solution using the API as the web scraping URL is pretty slow.
I'm using JSON as format=txt has been deprecated.
<lang zkl>var [const] CURL=Import("zklCurl"), YAJL=Import("zklYAJL")[0];
 
fcn getLangCounts(language){ // -->( (count,lang), ...)
continueValue,tasks,curl := "",List(), CURL(); // "nm\0nm\0...."
do{ // eg 5 times
page:=curl.get(("http://rosettacode.org/mw/api.php?"
"format=json"
"&action=query"
"&generator=categorymembers"
"&gcmtitle=Category:Programming%%20Languages"
"&gcmlimit=500"
"&prop=categoryinfo"
"&rawcontinue" // remove warning
"&gcmcontinue=%s")
.fmt(continueValue));
page=page[0].del(0,page[1]); // get rid of HTML header
json:=YAJL().write(page).close();
 
json["query"]["pages"].howza(9).pump(tasks,fcn(d){ #dictionary values,only
// { title:Category:AWK,categoryinfo:{ pages:398,size:401,... },... }
// Gotta take care of no categoryinfo case
count:=d.find("categoryinfo",Dictionary).find("size",0); // or pages?
if(count<300) return(Void.Skip); // prune
T(count,d["title"].del(0,9)); // "Category:RPL" --> "RPL"
});
 
if(continueValue=json.find("query-continue"))
// subcat|524558580a52455858|4331 or void
continueValue=continueValue["categorymembers"]["gcmcontinue"];
}while(continueValue);
tasks
}
 
langCounts:=getLangCounts() .sort(fcn(a,b){ a[0]>b[0] }); // reverse sort
 
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())) }</lang>
{{out}}
<pre>
Most popular Rosetta Code languages as of Saturday, the 23rd of September 2017
1: 957 Racket
2: 953 Python
3: 918 Tcl
4: 904 Perl 6
5: 877 J
6: 854 Zkl
7: 840 Ruby
8: 828 C
9: 812 Go
10: 805 Haskell
11: 801 REXX
12: 800 Kotlin
13: 788 Java
14: 776 Perl
15: 755 D
</pre>
 
 
{{omit from|Batch File}}
{{omit from|Brainf***}}
{{omit from|Lilypond}}
{{omit from|Maxima}}
{{omit from|PARI/GP}}
{{omit from|PostScript}}
{{omit from|TI-83 BASIC|Does not have network access.}}
{{omit from|TI-89 BASIC|Does not have network access.}}
{{omit from|Yorick|Does not have network access.}}
{{omit from|ZX Spectrum Basic|Does not have network access.}}
678

edits