Rosetta Code/Find bare lang tags: Difference between revisions

Rename Perl 6 -> Raku, alphabetize, minor clean-up
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 10:
 
<lang>Pseudocode</lang>
 
=={{header|C}}==
<lang C>printf("Hello world!\n");</lang>
 
=={{header|Perl}}==
<lang>print "Hello world!\n"</lang></nowiki>
</pre>
 
should display something like
<pre>
2 bare language tags.
 
1 in perl
1 in no language
</pre>
 
 
;Extra credit:
Allow multiple files to be read. &nbsp; Summarize all results by language:
<pre>
<nowiki>5 bare language tags.
 
2 in c ([[Foo]], [[Bar]])
1 in perl ([[Foo]])
2 in no language ([[Baz]])</nowiki>
</pre>
 
 
;Extra extra credit:
Use the &nbsp; [http://rosettacode.org/mw/api.php Media Wiki API] &nbsp; to test actual RC tasks.
<br><br>
 
=={{header|AutoHotkey}}==
Line 53 ⟶ 22:
 
=={{header|C}}==
<lang C>printf("Hello world!\n");</lang> =={{header|C}}==
<lang C>printf("Hello world!\n");</lang> =={{header|C}}==
<lang C>printf("Hello world!\n");</lang> =={{header|C}}==
<lang>printf("Hello again world!\n");</lang> =={{header|C}}==
<lang>printf("Hello once again world!\n");</lang>
 
=={{header|Perl}}==
<lang>print "Hello world!\n"</lang>
)
lang := "no language", out := Object(lang, 0), total := 0
Loop Parse, task, `r`n
If RegExMatch(A_LoopField, "==\s*{{\s*header\s*\|\s*([^\s\}]+)\s*}}\s*==", $)
lang := $1, out[lang] := 0
else if InStr(A_LoopField, "<lang>")
out[lang]++
For lang, num in Out
If num
total++, str .= "`n" num " in " lang
MsgBox % clipboard := total " bare lang tags.`n" . str</nowiki></pre>
Output:
<pre>2 bare lang tags.
 
Results:
1 in no language
 
1 in Perl</pre>
5 bare language tags.
 
2 in no language [example.txt example3.txt]
1 in perl [example.txt]
2 in c [example2.txt example3.txt]
</pre> =={{header|C}}==
<lang C>printf("Hello world!\n");</lang> =={{header|C}}==
<lang>printf("Hello world!\n");</lang> =={{header|C}}==
<lang C>printf("Hello world!\n");</lang>
 
=={{header|Erlang}}==
Line 221 ⟶ 188:
 
<lang>Pseudocode</lang>
 
=={{header|C}}==
<lang C>printf("Hello world!\n");</lang>
 
=={{header|Perl}}==
<lang>print "Hello world!\n"</lang>
 
 
Contents of example2.txt:
 
=={{header|C}}==
<lang>printf("Hello again world!\n");</lang>
 
=={{header|Perl}}==
<lang perl>print "Hello again world!\n"</lang>
 
 
Contents of example3.txt:
 
<lang>Some more pseudocode</lang>
 
=={{header|C}}==
<lang>printf("Hello once again world!\n");</lang>
 
 
Results:
 
5 bare language tags.
 
2 in no language [example.txt example3.txt]
1 in perl [example.txt]
2 in c [example2.txt example3.txt]
</pre>
 
=={{header|Haskell}}==
Line 348 ⟶ 282:
Description
 
<lang>Pseudocode</lang> =={{header|Haskell}}==
 
=={{header|C}}==
<lang C>printf("Hello world!\n");</lang>
 
 
 
=={{header|Perl}}==
<lang>print "Hello world!\n"</lang>
</nowiki></pre>
<pre><nowiki>
example2.wiki
-------------------------------------------------------------
Description
 
<lang>Pseudocode</lang>
 
=={{header|C}}==
<lang>printf("Hello world!\n");</lang>
 
=={{header|Perl}}==
<lang>print "Hello world!\n"</lang>
<lang Perl>print "Goodbye world!\n"</lang>
 
=={{header|Haskell}}==
<lang>hubris lang = "I'm so much better than a "++lang++" programmer because I program in Haskell."</lang>
</nowiki></pre>
Line 975 ⟶ 885:
 
=={{header|Perl}}==
<lang>print "Hello world!\n"</lang></nowiki>
</pre>
 
should display something like
<pre>
2 bare language tags.
 
1 in perl
1 in no language
</pre>
 
 
;Extra credit:
Allow multiple files to be read. &nbsp; Summarize all results by language:
<pre>
<nowiki>5 bare language tags.
 
2 in c ([[Foo]], [[Bar]])
1 in perl ([[Foo]])
2 in no language ([[Baz]])</nowiki>
</pre>
 
 
;Extra extra credit:
Use the &nbsp; [http://rosettacode.org/mw/api.php Media Wiki API] &nbsp; to test actual RC tasks.
<br><br> =={{header|Perl}}==
<lang>print "Hello world!\n"</lang>
)
lang := "no language", out := Object(lang, 0), total := 0
Loop Parse, task, `r`n
If RegExMatch(A_LoopField, "==\s*{{\s*header\s*\|\s*([^\s\}]+)\s*}}\s*==", $)
lang := $1, out[lang] := 0
else if InStr(A_LoopField, "<lang>")
out[lang]++
For lang, num in Out
If num
total++, str .= "`n" num " in " lang
MsgBox % clipboard := total " bare lang tags.`n" . str</nowiki></pre>
Output:
<pre>2 bare lang tags.
 
1 in no language
1 in Perl</pre> =={{header|Perl}}==
<lang>print "Hello world!\n"</lang>
 
 
Contents of example2.txt: =={{header|Perl}}==
<lang perl>print "Hello again world!\n"</lang>
 
 
Contents of example3.txt:
 
<lang>Some more pseudocode</lang> =={{header|Perl}}==
<lang>print "Hello world!\n"</lang>
</nowiki></pre>
<pre><nowiki>
example2.wiki
-------------------------------------------------------------
Description
 
<lang>Pseudocode</lang> =={{header|Perl}}==
<lang>print "Hello world!\n"</lang>
<lang Perl>print "Goodbye world!\n"</lang> =={{header|Perl}}==
This is a simple implementation that does not attempt either extra credit.
<lang perl>my $lang = 'no language';
Line 997 ⟶ 970:
print "$k in $v\n"
}
}</lang> =={{header|Perl}}==
<lang>print "Hello world!\n"</lang>
"""
 
println(BareLangFinder(scala.io.Source.fromString(test)).summary)
=={{header|Perl 6}}==
{{trans|Perl}}
The only tricky thing here is the use of the <tt>ms</tt> form of match, short for <tt>m:sigspace</tt>. This causes whitespace in the regex to be considered "significant", that is, it matches optional whitespace at those positions, as if you'd put <tt>\s*</tt> there. Of course, the regexes themselves are in Perl 6 syntax, which is quite different from Perl 5 regex syntax (and arguably much cleaner). Regex syntax is perhaps the area in which Perl 6 diverges most from Perl 5.
<lang perl6>my $lang = '(no language)';
my $total = 0;
my %blanks;
 
// System.setProperty("http.agent", "RosettaCode/1.0")
for lines() {
val tasks = List("Greatest_common_divisor", "Greatest_element_of_a_list", "Greatest_subsequential_sum")
when / '<lang>' / {
val inputs = for (task <- tasks; url = "http://rosettacode.org/wiki?action=raw&title=" + task)
%blanks{$lang}++;
yield BareLangFinder(scala.io.Source.fromURL(url), task)
$total++;
val bare = mapReduce(inputs)
}
println
when ms/ '==' '{{' 'header' '|' ( <-[}]>+? ) '}}' '==' / {
println(s"${count(bare)} bare language tags in ${tasks.size} tasks:")
$lang = $0.lc;
println(format(bare) mkString "\n")</pre>
}
}
 
say "$total bare language tag{ 's' if $total != 1 }\n";
say .value, ' in ', .key for %blanks.sort;</lang>
{{out}}
<pre>21 barein language tagsPerl
1 in no langauge
 
10 bare language tags in 3 tasks:
1 in (no language)
2 in Mathprog (Greatest_subsequential_sum)
1 in perl</pre>
1 in gnuplot (Greatest_common_divisor)
2 in МК-61/52 (Greatest_element_of_a_list)
1 in Bracmat (Greatest_element_of_a_list)
1 in PHP (Greatest_subsequential_sum)
2 in Euler Math Toolbox (Greatest_common_divisor,Greatest_element_of_a_list)
1 in ooRexx (Greatest_element_of_a_list)</pre>
 
=={{header|Phix}}==
Line 1,375 ⟶ 1,348:
(find-bare-tags page))
</lang>
 
=={{header|Raku}}==
(formerly Perl 6)
{{trans|Perl}}
The only tricky thing here is the use of the <tt>ms</tt> form of match, short for <tt>m:sigspace</tt>. This causes whitespace in the regex to be considered "significant", that is, it matches optional whitespace at those positions, as if you'd put <tt>\s*</tt> there. Of course, the regexes themselves are in Perl 6 syntax, which is quite different from Perl 5 regex syntax (and arguably much cleaner). Regex syntax is perhaps the area in which Perl 6 diverges most from Perl 5.
<lang perl6>my $lang = '(no language)';
my $total = 0;
my %blanks;
 
for lines() {
when / '<lang>' / {
%blanks{$lang}++;
$total++;
}
when ms/ '==' '{{' 'header' '|' ( <-[}]>+? ) '}}' '==' / {
$lang = $0.lc;
}
}
 
say "$total bare language tag{ 's' if $total != 1 }\n";
say .value, ' in ', .key for %blanks.sort;</lang>
{{out}}
<pre>2 bare language tags
 
1 in (no language)
1 in perl</pre>
 
=={{header|Ruby}}==
Line 1,417 ⟶ 1,416:
1 in PHP (["Greatest_subsequential_sum"])
</pre>
 
=={{header|Scala}}==
To analyse RosettaCode pages, invoke Java with <code>-Dhttp.agent=Anything</code> to work around CloudFlare blocking Java from accessing the RosettaCode site.
Line 1,457:
 
<lang>Pseudocode</lang>
 
=={{header|C}}==
<lang C>printf("Hello world!\n");</lang>
 
=={{header|Perl}}==
<lang>print "Hello world!\n"</lang>
"""
 
println(BareLangFinder(scala.io.Source.fromString(test)).summary)
 
// System.setProperty("http.agent", "RosettaCode/1.0")
val tasks = List("Greatest_common_divisor", "Greatest_element_of_a_list", "Greatest_subsequential_sum")
val inputs = for (task <- tasks; url = "http://rosettacode.org/wiki?action=raw&title=" + task)
yield BareLangFinder(scala.io.Source.fromURL(url), task)
val bare = mapReduce(inputs)
println
println(s"${count(bare)} bare language tags in ${tasks.size} tasks:")
println(format(bare) mkString "\n")</pre>
{{out}}
<pre>1 in Perl
1 in no langauge
 
10 bare language tags in 3 tasks:
2 in Mathprog (Greatest_subsequential_sum)
1 in gnuplot (Greatest_common_divisor)
2 in МК-61/52 (Greatest_element_of_a_list)
1 in Bracmat (Greatest_element_of_a_list)
1 in PHP (Greatest_subsequential_sum)
2 in Euler Math Toolbox (Greatest_common_divisor,Greatest_element_of_a_list)
1 in ooRexx (Greatest_element_of_a_list)</pre>
 
=={{header|Tcl}}==
10,333

edits