Anonymous user
Rosetta Code/Count examples: Difference between revisions
→{{header|Oz}}: url-encode task names; update output (currently 14099 examples)
m (→{{header|OCaml}}: handle 404) |
(→{{header|Oz}}: url-encode task names; update output (currently 14099 examples)) |
||
Line 486:
[StringX] = {Module.link ['x-oz://system/String.ozf']}
[Regex] = {Module.link ['x-oz://contrib/regex']}
AllTasksUrl = "http://rosettacode.org/mw/api.php?action=query&list="#
"categorymembers&cmtitle=Category:Programming_Tasks&cmlimit=500&format=xml"
proc {Main}
AllTasks = {Parse {GetPage AllTasksUrl}}
Line 496:
in
for Task in TaskTitles do
in
end
{System.showInfo "Total: "#@Total#" examples."}
end
fun {TaskUrl Task}
"http://rosettacode.org/mw/index.php?"#
"title="#{PercentEncode {StringX.replace Task " " "_"}}#
"&action=raw"
end
%% GetPage
local
Line 525:
end
end
%% Parse
local
Line 532:
fun {Parse Xs} {Parser parseVS(Xs $)} end
end
fun {GetTitles Doc}
CMs = Doc.2.1.children.1.children.1.children
Line 540:
{Map {Filter {Flatten {Map CMs Attributes}} IsTitle}
fun {$ A} {Atom.toString A.value} end}
end
fun {PercentEncode Xs}
case Xs of nil then nil
[] X|Xr then
if {Char.isDigit X} orelse {Member X [&- &_ &. &~]}
orelse X >= &a andthen X =< &z
orelse X >= &z andthen X =< &Z then
X|{PercentEncode Xr}
else
{Append &%|{ToHex2 X} {PercentEncode Xr}}
end
end
end
fun {ToHex2 X}
[{ToHex1 X div 16} {ToHex1 X mod 16}]
end
fun {ToHex1 X}
if X >= 0 andthen X =< 9 then &0 + X
elseif X >= 10 andthen X =< 15 then &A + X - 10
end
end
in
Line 546 ⟶ 569:
Example output:
<pre>
100 doors:
24 game:
24 game/Solve: 15 examples.
99 Bottles of Beer: 108 examples.
A+B: 59 examples.
...
Zig-zag matrix: 43 examples.
Total: 14099 examples.
</pre>
|