Rosetta Code/Rank languages by number of users: Difference between revisions

Content added Content deleted
m (→‎{{header|Stata}}: added zkl header)
(→‎{{header|zkl}}: added code)
Line 192: Line 192:


=={{header|zkl}}==
=={{header|zkl}}==
Uses libraries cURL and YAJL (yet another json library)
<lang zkl></lang>
<lang zkl></lang>
<lang zkl>const MIN_USERS=60;
var [const] CURL=Import("zklCurl"), YAJL=Import("zklYAJL")[0];

fcn rsGet{
continueValue,r,curl := "",List, CURL();
re:=RegExp(".*Category:(.+)"); // might have trailing " User"
do{ // eg 5 times
page:=("http://rosettacode.org/mw/api.php?action=query"
"&generator=categorymembers&prop=categoryinfo"
"&gcmtitle=Category%%3ALanguage%%20users"
"&rawcontinue=&format=json&gcmlimit=350"
"%s").fmt(continueValue);
page=curl.get(page);
page=page[0].del(0,page[1]); // get rid of HTML header
json:=YAJL().write(page).close();
json["query"]["pages"].pump(r.append,'wrap(x){ x=x[1];
//("2708",Dictionary(title:Category:C User,...,categoryinfo:D(pages:373,size:373,...)))
// or title:SmartBASIC
if((pgs:=x.find("categoryinfo")) and (pgs=pgs.find("pages")) and
pgs>=MIN_USERS)
return(pgs,x["title"].replace("Category:","").replace(" User",""));
return(Void.Skip);
});
if(continueValue=json.find("query-continue",""))
continueValue=String("&gcmcontinue=",
continueValue["categorymembers"]["gcmcontinue"]);
}while(continueValue);
r
}

allLangs:=rsGet();
allLangs=allLangs.sort(fcn(a,b){ a[0]>b[0] });
println("========== ",Time.Date.prettyDay()," ==========");
foreach n,pgnm in ([1..].zip(allLangs))
{ println("#%3d with %4s users: %s".fmt(n,pgnm.xplode())) }</lang>
{{out}}
{{out}}
<pre>
<pre>
========== Wednesday, the 20th of December 2017 ==========
# 1 with 373 users: C
# 2 with 261 users: C++
# 3 with 257 users: Java
# 4 with 243 users: Python
# 5 with 228 users: JavaScript
# 6 with 163 users: PHP
# 7 with 162 users: Perl
# 8 with 131 users: SQL
# 9 with 120 users: UNIX Shell
# 10 with 118 users: BASIC
# 11 with 113 users: C sharp
# 12 with 109 users: Pascal
# 13 with 98 users: Haskell
# 14 with 91 users: Ruby
# 15 with 71 users: Fortran
# 16 with 65 users: Visual Basic
# 17 with 60 users: Scheme
</pre>
</pre>