Rosetta Code/Tasks without examples: Difference between revisions
Content added Content deleted
m (→{{header|Phix}}: syntax coloured, use common code) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 13: | Line 13: | ||
=={{header|D}}== |
=={{header|D}}== |
||
< |
<syntaxhighlight lang="d">import std.algorithm; |
||
import std.net.curl; |
import std.net.curl; |
||
import std.range; |
import std.range; |
||
Line 47: | Line 47: | ||
auto base = "http://rosettacode.org/wiki/"; |
auto base = "http://rosettacode.org/wiki/"; |
||
tasks.take(3).each!(task => process(base, task)); |
tasks.take(3).each!(task => process(base, task)); |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>There are 100 doors in a row that are all initially closed. |
<pre>There are 100 doors in a row that are all initially closed. |
||
Line 134: | Line 134: | ||
=={{header|Go}}== |
=={{header|Go}}== |
||
< |
<syntaxhighlight lang="go">package main |
||
import ( |
import ( |
||
Line 177: | Line 177: | ||
time.Sleep(5 * time.Second) // wait 5 seconds before processing next task |
time.Sleep(5 * time.Second) // wait 5 seconds before processing next task |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 270: | Line 270: | ||
=={{header|Java}}== |
=={{header|Java}}== |
||
{{trans|Kotlin}} |
{{trans|Kotlin}} |
||
< |
<syntaxhighlight lang="java">import java.io.IOException; |
||
import java.net.URI; |
import java.net.URI; |
||
import java.net.URISyntaxException; |
import java.net.URISyntaxException; |
||
Line 336: | Line 336: | ||
tasks.stream().limit(limit).forEach(task -> process(client, base, task)); |
tasks.stream().limit(limit).forEach(task -> process(client, base, task)); |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
{{trans|Go}} |
{{trans|Go}} |
||
< |
<syntaxhighlight lang="julia">using HTTP |
||
function gettaskdescriptions(numtoprint = 3) |
function gettaskdescriptions(numtoprint = 3) |
||
Line 358: | Line 358: | ||
gettaskdescriptions() |
gettaskdescriptions() |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Kotlin}}== |
=={{header|Kotlin}}== |
||
< |
<syntaxhighlight lang="scala">import java.net.URI |
||
import java.net.http.HttpClient |
import java.net.http.HttpClient |
||
import java.net.http.HttpRequest |
import java.net.http.HttpRequest |
||
Line 414: | Line 414: | ||
} |
} |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
{{trans|Go}} |
{{trans|Go}} |
||
< |
<syntaxhighlight lang="nim">import htmlparser, httpclient, os, re, strutils, xmltree |
||
let re1 = re("""<li><a href="/wiki/(.*?)"""") |
let re1 = re("""<li><a href="/wiki/(.*?)"""") |
||
Line 448: | Line 448: | ||
echo xmlnode.innerText() # Echo the tree as text. |
echo xmlnode.innerText() # Echo the tree as text. |
||
if i == Limit - 1: break |
if i == Limit - 1: break |
||
os.sleep(5000) # Wait 5 seconds before processing next task.</ |
os.sleep(5000) # Wait 5 seconds before processing next task.</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 537: | Line 537: | ||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
Slice and dice the HTML. Output is as for the other examples. |
Slice and dice the HTML. Output is as for the other examples. |
||
< |
<syntaxhighlight lang="perl">use strict; |
||
use warnings; |
use warnings; |
||
Line 553: | Line 553: | ||
print "$title\n$task_at_hand\n\n"; |
print "$title\n$task_at_hand\n\n"; |
||
sleep 10; # so you have time to read each task... |
sleep 10; # so you have time to read each task... |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
Line 559: | Line 559: | ||
Output similar to zkl, I assume the first four constants are self-explanatory. |
Output similar to zkl, I assume the first four constants are self-explanatory. |
||
{{libheader|Phix/libcurl}} |
{{libheader|Phix/libcurl}} |
||
<!--< |
<!--<syntaxhighlight lang="phix">(notonline)--> |
||
<span style="color: #000080;font-style:italic;">-- demo\rosetta\Tasks_without_examples.exw</span> |
<span style="color: #000080;font-style:italic;">-- demo\rosetta\Tasks_without_examples.exw</span> |
||
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span> <span style="color: #000080;font-style:italic;">-- (libcurl, file i/o, peek, progress..)</span> |
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span> <span style="color: #000080;font-style:italic;">-- (libcurl, file i/o, peek, progress..)</span> |
||
Line 658: | Line 658: | ||
<span style="color: #0000FF;">?</span><span style="color: #008000;">"done"</span> |
<span style="color: #0000FF;">?</span><span style="color: #008000;">"done"</span> |
||
<span style="color: #0000FF;">{}</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">wait_key</span><span style="color: #0000FF;">()</span> |
<span style="color: #0000FF;">{}</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">wait_key</span><span style="color: #0000FF;">()</span> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
=={{header|Raku}}== |
=={{header|Raku}}== |
||
Line 664: | Line 664: | ||
{{works with|Rakudo|2017.10}} |
{{works with|Rakudo|2017.10}} |
||
<lang |
<syntaxhighlight lang="raku" line>use HTTP::UserAgent; |
||
use Gumbo; |
use Gumbo; |
||
Line 715: | Line 715: | ||
sub cleanup ( $string ) { |
sub cleanup ( $string ) { |
||
$string.subst( /^.+ '</div>'/, '' ) |
$string.subst( /^.+ '</div>'/, '' ) |
||
}</ |
}</syntaxhighlight> |
||
{{out|Abridged sample output}} |
{{out|Abridged sample output}} |
||
<div style="border-style: groove; margin: 50px; padding: 25px;"> |
<div style="border-style: groove; margin: 50px; padding: 25px;"> |
||
Line 801: | Line 801: | ||
Could output text by retrieving innerText instead of innerHTML in Slurp(). |
Could output text by retrieving innerText instead of innerHTML in Slurp(). |
||
< |
<syntaxhighlight lang="vbscript">Option Explicit |
||
Dim oIE : Set oIE = CreateObject("InternetExplorer.Application") |
Dim oIE : Set oIE = CreateObject("InternetExplorer.Application") |
||
Line 876: | Line 876: | ||
End Function |
End Function |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Wren}}== |
=={{header|Wren}}== |
||
Line 882: | Line 882: | ||
{{libheader|Wren-pattern}} |
{{libheader|Wren-pattern}} |
||
An embedded program so we can use the libcurl library. |
An embedded program so we can use the libcurl library. |
||
< |
<syntaxhighlight lang="ecmascript">/* rc_tasks_without_examples.wren */ |
||
import "./pattern" for Pattern |
import "./pattern" for Pattern |
||
Line 954: | Line 954: | ||
System.print("\n****** %(title) ******\n") |
System.print("\n****** %(title) ******\n") |
||
System.print(text) |
System.print(text) |
||
}</ |
}</syntaxhighlight> |
||
<br> |
<br> |
||
which we embed in the following C program, build and run. |
which we embed in the following C program, build and run. |
||
< |
<syntaxhighlight lang="c">/* gcc rc_tasks_without_examples.c -o rc_tasks_without_examples -lcurl -lwren -lm */ |
||
#include <stdio.h> |
#include <stdio.h> |
||
Line 1,147: | Line 1,147: | ||
free(script); |
free(script); |
||
return 0; |
return 0; |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,231: | Line 1,231: | ||
Uses libraries cURL and YAJL (yet another json library). |
Uses libraries cURL and YAJL (yet another json library). |
||
< |
<syntaxhighlight lang="zkl">var [const] CURL=Import("zklCurl"), YAJL=Import("zklYAJL")[0]; |
||
fcn getTasks(language){ |
fcn getTasks(language){ |
||
Line 1,276: | Line 1,276: | ||
} |
} |
||
newTasks();</ |
newTasks();</syntaxhighlight> |
||
{{out|Concise Output}} |
{{out|Concise Output}} |
||
<pre> |
<pre> |