Anonymous user
Rosetta Code/Rank languages by popularity: Difference between revisions
Rosetta Code/Rank languages by popularity (view source)
Revision as of 20:18, 1 April 2021
, 3 years agoUpdated to work with Nim 1.4: changed the way to get data from an URL. Major changes to take in account "continue" and "cmcontinue".
m (Updated the number of computer programming languages that are used on Rosetta Code based on the number of members..) |
(Updated to work with Nim 1.4: changed the way to get data from an URL. Major changes to take in account "continue" and "cmcontinue".) |
||
Line 3,137:
=={{header|Nim}}==
<lang nim>import httpclient, json, re, strformat, strutils, algorithm
const
let regex = re"title=""Category:(.*?)"">.+?</a>.*\((.*) members\)"
for l in parseJson(getContent(langSite))["query"]["categorymembers"]:▼
langs.add(l["title"].str.split("Category:")[1])▼
result = cmp(b.count, a.count)
for line in getContent(catSize).findAll(regex):▼
if result == 0: result = cmp(a.lang, b.lang)
proc add(langs: var seq[string]; fromJson: JsonNode) =
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]
let lang = line.replacef(regex, "$1")
if lang in langs:
let count = parseInt(line.replacef(regex, "$2").replace(",", "").strip())
ranks.add
ranks.sort(
for i,
echo
</lang>
Output:
<pre>
2
3
4
5
6
7
8
9
10
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>
|