Rosetta Code/Find bare lang tags: Difference between revisions

Fix up total mess I made of the page
m (Reverted edits by Thundergnat (talk) to last revision by SqrtNegInf)
(Fix up total mess I made of the page)
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 22 ⟶ 53:
 
=={{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.
 
1 in no language
Results:
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 188 ⟶ 221:
 
<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 282 ⟶ 348:
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 885 ⟶ 975:
 
=={{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 970 ⟶ 997:
print "$k in $v\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|Phix}}==
Line 1,352 ⟶ 1,354:
(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 Raku syntax, which is quite different from Perl  5 regex syntax (and arguably much cleaner). Regex syntax is perhaps the area in which Raku diverges most from Perl  5.
<lang perl6>my $lang = '(no language)';
my $total = 0;
Line 1,416 ⟶ 1,418:
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 ⟶ 1,458:
 
<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