CloudFlare suffered a massive security issue affecting all of its customers, including Rosetta Code. All passwords not changed since February 19th 2017 have been expired, and session cookie longevity will be reduced until late March.--Michael Mol (talk) 05:15, 25 February 2017 (UTC)

Rosetta Code/Find bare lang tags

From Rosetta Code
Task
Rosetta Code/Find bare lang tags
You are encouraged to solve this task according to the task description, using any language you may know.
Task

Find all   <lang>   tags without a language specified in the text of a page.

Display counts by language section:

Description

<lang>Pseudocode</lang>

=={{header|C}}==
<lang C>printf("Hello world!\n");</lang>

=={{header|Perl}}==
<lang>print "Hello world!\n"</lang>

should display something like

2 bare language tags.

1 in perl
1 in no language


Extra credit

Allow multiple files to be read.   Summarize all results by language:

5 bare language tags.

2 in c ([[Foo]], [[Bar]])
1 in perl ([[Foo]])
2 in no language ([[Baz]])


Extra extra credit

Use the   Media Wiki API   to test actual RC tasks.

AutoHotkey[edit]

This code has no syntax highlighting, because Rosetta Code's highlighter fails with code that contains literal </lang> tags.

Stole RegEx Needle from Perl

task =
(
Description

<lang>Pseudocode</lang>

=={{header|C}}==
<lang C>printf("Hello 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

Output:

2 bare lang tags.

1 in no language
1 in Perl

Erlang[edit]

 
-module( find_bare_lang_tags ).
 
-export( [task/0] ).
 
task() ->
{ok, Binary} = file:read_file( "priv/find_bare_lang_tags_1" ),
Lines = string:tokens( erlang:binary_to_list(Binary), "\n" ),
{_Lang, Dict} = lists:foldl( fun count_empty_lang/2, {"no language", dict:new()}, Lines ),
Count_langs = [{dict:fetch(X, Dict), X} || X <- dict:fetch_keys(Dict)],
io:fwrite( "~p bare language tags.~n", [lists:sum([X || {X, _Y} <- Count_langs])] ),
[io:fwrite( "~p in ~p~n", [X, Y] ) || {X, Y} <- Count_langs].
 
 
 
count_empty_lang( Line, {Lang, Dict} ) ->
Empty_lang = string:str( Line, "<lang>" ),
New_dict = dict_update_counter( Empty_lang, Lang, Dict ),
New_lang = new_lang( string:str( Line,"=={{header|" ), Line, Lang ),
{New_lang, New_dict}.
 
dict_update_counter( 0, _Lang, Dict ) -> Dict;
dict_update_counter( _Start, Lang, Dict ) -> dict:update_counter( Lang, 1, Dict ).
 
new_lang( 0, _Line, Lang ) -> Lang;
new_lang( _Start, Line, _Lang ) ->
Start = string:str( Line, "|" ),
Stop = string:rstr( Line, "}}==" ),
string:sub_string( Line, Start+1, Stop-1 ).
 
Output:
60>  find_bare_lang_tags:task().
2 bare language tags.
1 in "no language"
1 in "Perl"

Haskell[edit]

There are actually many different Regex packages available for Haskell. For this example, I chose TDFA, a very fast POSIX ERE engine. To change engines, simply change the import statement. If you use a Perl-style RE engine, you'll have to modify the expressions slightly.

This solution can be compiled into a program that will either take space-delimited list of files as its argument, or take input from STDIN if no arguments are provided. Additionally, if you specify the -w flag in the first argument, it will take a list of Rosetta Code wiki pages and search them. Note that the page names must be as they appear in your URL bar -- underscores in place of spaces.

import System.Environment
import Network.HTTP
import Text.Printf
import Text.Regex.TDFA
import Data.List
import Data.Array
import qualified Data.Map as Map
 
{-| Takes a string and cuts out the text matched in the MatchText array. -}
splitByMatches :: String -> [MatchText String] -> [String]
splitByMatches str matches = foldr splitHead [str] matches
where splitHead match acc = before:after:(tail acc)
where before = take (matchOffset).head$ acc
after = drop (matchOffset + matchLen).head$ acc
matchOffset = fst.snd.(!0)$ match
matchLen = snd.snd.(!0)$ match
 
{-| Takes a string and counts the number of time a valid, but bare, lang tag
appears. It does not attempt to ignore valid tags inside lang blocks. -}

countBareLangTags :: String -> Int
countBareLangTags = matchCount (makeRegex "<lang[[:space:]]*>" :: Regex)
 
{-| Takes a string and counts the number of bare lang tags per section of the
text. All tags before the first section are put into the key "". -}

countByLanguage :: String -> Map.Map String Int
countByLanguage str = Map.fromList.filter ((>0).snd)$ zip langs counts
where counts = map countBareLangTags.splitByMatches str$ allMatches
langs = "":(map (fst.(!1)) allMatches)
allMatches = matchAllText (makeRegex headerRegex :: Regex) str
headerRegex = "==[[:space:]]*{{[[:space:]]*header[[:space:]]*\\|[[:space:]]*([^ }]*)[[:space:]]*}}[^=]*=="
 
main = do
args <- getArgs
(contents, files) <- if length args == 0 then do
-- If there aren't arguments, read from stdin
content <- getContents
return ([content],[""])
else if length args == 1 then do
-- If there's only one argument, read the file, but don't display
-- the filename in the results.
content <- readFile (head args)
return ([content],[""])
else if (args !! 0) == "-w" then do
-- If there's more than one argument and the first one is the -w option,
-- use the rest of the arguments as page titles and load them from the wiki.
contents <- mapM getPageContent.tail$ args
return (contents, if length args > 2 then tail args else [""])
else do
-- Otherwise, read all the files and display their file names.
contents <- mapM readFile args
return (contents, args)
let tagsPerLang = map countByLanguage contents
let tagsWithFiles = zipWith addFileToTags files tagsPerLang
let combinedFiles = Map.unionsWith combine tagsWithFiles
printBareTags combinedFiles
where addFileToTags file = Map.map (flip (,) [file])
combine cur next = (fst cur + fst next, snd cur ++ snd next)
 
printBareTags :: Map.Map String (Int,[String]) -> IO ()
printBareTags tags = do
let numBare = Map.foldr ((+).fst) 0 tags
printf "%d bare language tags:\n\n" numBare
mapM_ (\(lang,(count,files)) ->
printf "%d in %s%s\n" count
(if lang == "" then "no language" else lang)
(filesString files)
) (Map.toAscList tags)
 
filesString :: [String] -> String
filesString [] = ""
filesString ("":rest) = filesString rest
filesString files = " ("++listString files++")"
where listString [file] = "[["++file++"]]"
listString (file:files) = "[["++file++"]], "++listString files
 
getPageContent :: String -> IO String
getPageContent title = do
response <- simpleHTTP.getRequest$ url
getResponseBody response
where url = "http://rosettacode.org/mw/index.php?action=raw&title="++title

Here are the input files I used to test:

example1.wiki
-------------------------------------------------------------
Description

<lang>Pseudocode</lang>

=={{header|C}}==
<lang C>printf("Hello world!\n");</lang>



=={{header|Perl}}==
<lang>print "Hello world!\n"</lang>
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>

And the output:

6 bare language tags:

2 in no language ([[example1.wiki]], [[example2.wiki]])
1 in C ([[example2.wiki]])
1 in Haskell ([[example2.wiki]])
2 in Perl ([[example1.wiki]], [[example2.wiki]])

Additionally, I tested with 100_doors and Huffman_coding. The following resulted:

5 bare language tags:

1 in no language ([[100_doors]])
1 in C ([[Huffman_coding]])
1 in CoffeeScript ([[Huffman_coding]])
1 in Perl ([[Huffman_coding]])
1 in PostScript ([[100_doors]])

Icon and Unicon[edit]

The following is a Unicon-specific solution.

import Utils		# To get the FindFirst class
 
procedure main()
keys := ["{{header|","<lang>"]
lang := "No language"
tags := table(0)
total := 0
 
ff := FindFirst(keys)
f := reads(&input, -1)
 
f ? while tab(ff.locate()) do {
if "{{header|" == 1(ff.getMatch(), ff.moveMatch()) then lang := map(tab(upto("}}")))
else (tags[lang] +:= 1, total +:= 1)
}
 
write(total," bare language tags:\n")
every pair := !sort(tags) do write(pair[2]," in ",pair[1])
end

Sample run using example given in problem statement:

->rcfblt <rcfblt.in
2 bare language tags:

1 in No language
1 in perl
->

Mathematica[edit]

tasks[page_: ""] := 
Module[{res =
Import["http://rosettacode.org/mw/api.php?format=xml&action=\
query&list=categorymembers&cmtitle=Category:Programming_Tasks&cmlimit=\
500" <> page, "XML"]},
If[MemberQ[res[[2, 3]], XMLElement["query-continue", __]],
Join[res[[2, 3, 1, 3, 1, 3, All, 2, 3, 2]],
tasks["&cmcontinue=" <> res[[2, 3, 2, 3, 1, 2, 1, 2]]]],
res[[2, 3, 1, 3, 1, 3, All, 2, 3, 2]]]];
bareTags = # -> (# -> StringCount[#2, "<lang>"] &) @@@
Partition[
Prepend[StringSplit[
Import["http://rosettacode.org/wiki?action=raw&title=" <>
URLEncode[#], "Text"],
Shortest["=={{header|" ~~ x__ ~~ "}}=="] :> x],
"no language"] //. {a___,
multi_String?StringContainsQ["}}" ~~ ___ ~~ "{{header|"],
bare_Integer, b___} :> {a, StringSplit[multi, "}"][[1]],
bare, StringSplit[multi, "|"][[-1]], bare, b}, 2] & /@
tasks[];
Print[IntegerString[Total[Flatten[bareTags[[All, 2, All, 2]]]]] <>
" bare language tags.\n"];
langCounts =
Normal[Total /@
GroupBy[Flatten[bareTags[[All, 2]]], Keys -> Values]];
Print[IntegerString[#2] <> " in " <> # <> " ([[" <>
StringRiffle[
Keys[Select[bareTags,
Function[task, MemberQ[task[[2]], # -> _Integer?Positive]]]],
"]], [["] <> "]])"] & @@@
Select[SortBy[langCounts, Keys], #[[2]] > 0 &];

This script looks for all of the pages in Category:Programming Tasks, downloads them, and gets the bare tags per language. Then, it gets the total of all of them, prints it, and sums up the bare tags by language. Note that it doesn't check if the tags are in a block or even closed, so it picks up false positives (especially on this page.)

Output:

This the output on May 21, 2015.

686 bare language tags.

1 in 360 Assembly ([[FizzBuzz]])
1 in 4DOS Batch ([[100 doors]])
71 in МК-61/52 ([[Arithmetic-geometric mean]], [[Arithmetic-geometric mean/Calculate Pi]], [[Arithmetic/Complex]], [[Arithmetic/Integer]], [[Averages/Arithmetic mean]], [[Averages/Root mean square]], [[Balanced ternary]], [[Circles of given radius through two points]], [[Combinations and permutations]], [[Conditional structures]], [[Convert decimal number to rational]], [[Count in octal]], [[Day of the week]], [[Dot product]], [[Empty program]], [[Ethiopian multiplication]], [[Euler method]], [[Evaluate binomial coefficients]], [[Even or odd]], [[Execute a Markov algorithm]], [[Exponentiation operator]], [[Fibonacci sequence]], [[Find limit of recursion]], [[Greatest element of a list]], [[Haversine formula]], [[Higher-order functions]], [[Holidays related to Easter]], [[Horizontal sundial calculations]], [[Horner's rule for polynomial evaluation]], [[Integer comparison]], [[Integer sequence]], [[Jump anywhere]], [[Leap year]], [[Least common multiple]], [[Loops/Break]], [[Loops/Do-while]], [[Loops/Downward for]], [[Loops/For with a specified step]], [[Loops/Infinite]], [[Loops/While]], [[Main step of GOST 28147-89]], [[Middle three digits]], [[Modular inverse]], [[Monte Carlo methods]], [[Multifactorial]], [[Multiplication tables]], [[Nth root]], [[Pick random element]], [[Polynomial regression]], [[Primality by trial division]], [[Program termination]], [[Random numbers]], [[Real constants and functions]], [[Roots of a quadratic function]], [[Roots of unity]], [[Sequence of non-squares]], [[Standard deviation]], [[Sum and product of an array]], [[Sum digits of an integer]], [[Sum multiples of 3 and 5]], [[Sum of squares]], [[Ternary logic]], [[Towers of Hanoi]], [[Vector products]], [[Voronoi diagram]], [[Zero to the zero power]])
2 in 6502 Assembly ([[FizzBuzz]], [[String case]])
2 in 6800 Assembly ([[Hello world/Text]], [[Loops/Infinite]])
1 in ABAP ([[FizzBuzz]])
1 in ACL2 ([[Sorting algorithms/Quicksort]])
1 in Ada ([[Hofstadter Figure-Figure sequences]])
1 in ALGOL 60 ([[Trabb Pardo\[Dash]Knuth algorithm]])
1 in APL ([[Arithmetic/Complex]])
3 in AutoHotkey ([[Long multiplication]], [[Rosetta Code/Find bare lang tags]], [[Sorting algorithms/Strand sort]])
1 in AutoIt ([[Letter frequency]])
1 in BASIC256 ([[Greyscale bars/Display]])
2 in Batch File ([[Function definition]], [[Loops/For]])
1 in BBC BASIC ([[Loops/For]])
4 in Bracmat ([[Command-line arguments]], [[Greatest element of a list]], [[Integer sequence]], [[Runtime evaluation/In an environment]])
1 in Burlesque ([[Shell one-liner]])
46 in C ([[Atomic updates]], [[Balanced brackets]], [[Best shuffle]], [[Bulls and cows/Player]], [[Closures/Value capture]], [[Constrained random points on a circle]], [[Convert decimal number to rational]], [[Count the coins]], [[Cut a rectangle]], [[Deconvolution/2D+]], [[Distributed programming]], [[Entropy]], [[Euler method]], [[Evolutionary algorithm]], [[Execute a Markov algorithm]], [[Find common directory path]], [[First-class functions]], [[Fork]], [[Inverted index]], [[Last letter-first letter]], [[Longest string challenge]], [[Map range]], [[Multisplit]], [[Natural sorting]], [[Partial function application]], [[Permutation test]], [[Priority queue]], [[Probabilistic choice]], [[Pythagorean triples]], [[Roots of a quadratic function]], [[Rosetta Code/Find bare lang tags]], [[S-Expressions]], [[Self-describing numbers]], [[Sorting algorithms/Sleep sort]], [[Sorting algorithms/Strand sort]], [[Stem-and-leaf plot]], [[Strip control codes and extended characters from a string]], [[Text processing/Max licenses in use]], [[Thiele's interpolation formula]], [[Topological sort]], [[Truncatable primes]], [[Variable-length quantity]], [[Write float arrays to a text file]])
2 in Chapel ([[Associative array/Creation]], [[Numerical integration]])
15 in ChucK ([[Call an object method]], [[Factorial]], [[Function definition]], [[Hello world/Text]], [[Include a file]], [[Integer comparison]], [[Integer sequence]], [[Loops/Do-while]], [[Loops/Infinite]], [[Loops/While]], [[String concatenation]], [[Variables]])
8 in Clojure ([[Hello world/Newbie]], [[Hofstadter Q sequence]], [[Knuth's algorithm S]], [[Longest increasing subsequence]], [[One of n lines in a file]], [[Show the epoch]])
3 in COBOL ([[Hello world/Newbie]])
32 in CoffeeScript ([[Align columns]], [[Balanced brackets]], [[Bitwise operations]], [[Case-sensitivity of identifiers]], [[Constrained random points on a circle]], [[CRC-32]], [[Date format]], [[Delegates]], [[Flatten a list]], [[Integer sequence]], [[Inverted index]], [[Knight's tour]], [[Knuth's algorithm S]], [[Langton's ant]], [[Last Friday of each month]], [[Mutual recursion]], [[Nth root]], [[Numerical integration]], [[Ordered words]], [[Partial function application]], [[Power set]], [[Priority queue]], [[Problem of Apollonius]], [[Queue/Usage]], [[Roots of a function]], [[S-Expressions]], [[Sorting algorithms/Permutation sort]], [[Sorting algorithms/Sleep sort]], [[Spiral matrix]], [[Tree traversal]], [[Truncatable primes]], [[URL decoding]])
17 in Common Lisp ([[Balanced ternary]], [[Cut a rectangle]], [[Equilibrium index]], [[Evolutionary algorithm]], [[Execute a Markov algorithm]], [[Hofstadter Figure-Figure sequences]], [[Knuth's algorithm S]], [[Last letter-first letter]], [[One of n lines in a file]], [[Permutation test]], [[Pig the dice game/Player]], [[Pythagorean triples]], [[Rate counter]], [[Self-describing numbers]], [[Self-referential sequence]], [[Sorting algorithms/Strand sort]], [[Thiele's interpolation formula]])
1 in C sharp ([[Break OO privacy]])
16 in C sharp|C# ([[Closures/Value capture]], [[Color of a screen pixel]], [[Conway's Game of Life]], [[Equilibrium index]], [[Heronian triangles]], [[Infinity]], [[Inverted index]], [[Non-decimal radices/Input]], [[Numerical integration]], [[Pi]], [[Polymorphic copy]], [[Roots of a quadratic function]], [[Short-circuit evaluation]], [[Stack traces]], [[Variable-length quantity]])
2 in Cubescript ([[Caesar cipher]], [[FizzBuzz]])
1 in Dart ([[Mandelbrot set]])
2 in ÐÐ-61/52 ([[Ackermann function]], [[Sum of a series]])
1 in DEC BASIC-PLUS ([[Mandelbrot set]])
2 in Delphi ([[Polymorphic copy]], [[XML/XPath]])
1 in E ([[Shell one-liner]])
7 in ECL ([[Array concatenation]], [[Assertions]], [[CSV data manipulation]], [[Higher-order functions]], [[Repeat a string]], [[Return multiple values]])
1 in Eiffel ([[Hamming numbers]])
1 in Elixir ([[Sparkline in unicode]])
4 in Erlang ([[Apply a callback to an array]], [[Comma quibbling]], [[Fibonacci n-step number sequences]], [[Rosetta Code/Find bare lang tags]])
26 in ERRE ([[Address of a variable]], [[Apply a callback to an array]], [[Arithmetic-geometric mean]], [[Arithmetic/Complex]], [[Arithmetic/Integer]], [[Array concatenation]], [[Averages/Median]], [[Averages/Pythagorean means]], [[Averages/Root mean square]], [[Catalan numbers]], [[Circles of given radius through two points]], [[Create a two-dimensional array at runtime]], [[Empty program]], [[Evaluate binomial coefficients]], [[Execute a system command]], [[Greatest subsequential sum]], [[Increment a numerical string]], [[Integer sequence]], [[Jump anywhere]], [[Look-and-say sequence]], [[N-queens problem]], [[Random numbers]], [[Roots of a quadratic function]], [[Roots of unity]], [[Semiprime]])
10 in Euler Math Toolbox ([[Bitmap/Flood fill]], [[Grayscale image]], [[Greatest common divisor]], [[Greatest element of a list]], [[Identity matrix]], [[Resistor mesh]], [[Verify distribution uniformity/Naive]])
1 in Euphoria ([[Loops/Foreach]])
10 in Excel ([[A+B]], [[Arithmetic/Complex]], [[Averages/Median]], [[Boolean values]], [[Least common multiple]], [[Roman numerals/Encode]], [[String case]], [[String concatenation]], [[Sum of squares]], [[Temperature conversion]])
1 in F# ([[Comma quibbling]])
5 in Factor ([[Inverted index]], [[Mutual recursion]], [[Probabilistic choice]], [[Singly-linked list/Element definition]])
2 in Forth ([[Generate lower case ASCII alphabet]], [[String append]])
9 in Fortran ([[Bitwise operations]], [[Command-line arguments]], [[Dutch national flag problem]], [[Evolutionary algorithm]], [[Pascal matrix generation]], [[Price fraction]], [[Rot-13]], [[Sieve of Eratosthenes]])
1 in GAP ([[Sequence of non-squares]])
1 in gnuplot ([[Greatest common divisor]])
3 in Go ([[Address of a variable]], [[Bitmap/Midpoint circle algorithm]], [[Call a function]])
1 in Gri ([[Comments]])
9 in Haskell ([[Empty directory]], [[Hello world/Newbie]], [[Hough transform]], [[Rosetta Code/Find bare lang tags]])
4 in Icon}} and {{header|Unicon ([[Arithmetic-geometric mean]], [[Averages/Mean time of day]], [[Averages/Median]], [[Left factorials]])
24 in J ([[Calendar - for "REAL" programmers]], [[Discordian date]], [[First-class functions]], [[First-class functions/Use numbers analogously]], [[Galton box animation]], [[Guess the number]], [[Guess the number/With feedback]], [[Guess the number/With feedback (player)]], [[GUI enabling/disabling of controls]], [[JSON]], [[Morse code]], [[Narcissist]], [[Numeric error propagation]], [[Permutation test]], [[Pig the dice game]], [[Pythagorean triples]], [[Quaternion type]], [[Semordnilap]], [[Sorting algorithms/Bead sort]], [[XML/Output]], [[Yin and yang]])
5 in Java ([[A+B]], [[Balanced brackets]], [[Heronian triangles]], [[Parse an IP Address]], [[Y combinator]])
2 in JavaScript ([[Best shuffle]], [[Heronian triangles]])
2 in Julia ([[Show the epoch]], [[Sorting algorithms/Counting sort]])
2 in Korn Shell ([[Bitmap/Bresenham's line algorithm]])
1 in Lasso ([[Take notes on the command line]])
1 in Liberty BASIC ([[LZW compression]])
1 in Limbo ([[Hailstone sequence]])
1 in Logo ([[Dutch national flag problem]])
1 in LOLCODE ([[The Twelve Days of Christmas]])
2 in Lua ([[First-class functions]], [[Guess the number/With feedback (player)]])
1 in M4 ([[Dragon curve]])
1 in Maple ([[Case-sensitivity of identifiers]])
31 in Mathematica ([[Check Machin-like formulas]], [[Compile-time calculation]], [[Execute Brain****]], [[Execute HQ9+]], [[Find largest left truncatable prime in a given base]], [[Find limit of recursion]], [[Four bit adder]], [[Guess the number/With feedback (player)]], [[GUI component interaction]], [[Introspection]], [[K-means++ clustering]], [[LZW compression]], [[Number names]], [[Number reversal game]], [[Permutations by swapping]], [[Pig the dice game]], [[Rate counter]], [[Rep-string]], [[RSA code]], [[Send an unknown method call]], [[SHA-256]], [[Sudoku]], [[Take notes on the command line]], [[Tic-tac-toe]], [[Word wrap]], [[Yahoo! search interface]])
9 in Mathprog ([[Averages/Arithmetic mean]], [[Greatest subsequential sum]], [[Knapsack problem/Continuous]], [[Knight's tour]])
5 in Maxima ([[A+B]], [[Array concatenation]], [[Circles of given radius through two points]], [[Execute a system command]], [[Set]])
1 in MAXScript ([[Bulls and cows]])
21 in Mercury ([[A+B]], [[Arithmetic/Integer]], [[Command-line arguments]], [[Concurrent computing]], [[Count in octal]], [[Execute a system command]], [[Formatted numeric output]], [[Hello world/Standard error]], [[Input loop]], [[Loop over multiple arrays simultaneously]], [[Loops/Downward for]], [[Loops/For]], [[Mutual recursion]], [[OpenGL]], [[Real constants and functions]], [[SEDOLs]], [[Sort an integer array]], [[String case]], [[Sum of squares]], [[Tokenize a string]], [[Vector products]])
1 in Modula-2 ([[Hello world/Web server]])
2 in MUMPS ([[Copy a string]], [[Integer comparison]])
1 in Nemerle ([[Short-circuit evaluation]])
3 in Nim ([[LZW compression]], [[Metaprogramming]])
2 in no language ([[Rosetta Code/Find bare lang tags]])
1 in OCaml ([[99 Bottles of Beer]])
2 in Octave ([[Quaternion type]])
2 in ooRexx ([[Greatest element of a list]], [[String comparison]])
3 in Order ([[First class environments]], [[Hailstone sequence]], [[Luhn test of credit card numbers]])
1 in OS/8 BASIC ([[Mandelbrot set]])
1 in PARI/GP ([[Conjugate transpose]])
18 in Perl ([[Box the compass]], [[Extend your language]], [[History variables]], [[Linear congruential generator]], [[Narcissist]], [[Numeric error propagation]], [[Parse an IP Address]], [[Priority queue]], [[Queue/Usage]], [[Rosetta Code/Find bare lang tags]], [[Set of real numbers]])
13 in Perl 6 ([[Concurrent computing]], [[Constrained genericity]], [[Create a two-dimensional array at runtime]], [[Dutch national flag problem]], [[Empty program]], [[Hofstadter-Conway $10,000 sequence]], [[Morse code]], [[Numerical integration]], [[Queue/Usage]], [[Rosetta Code/Find bare lang tags]], [[Write language name in 3D ASCII]])
1 in PHL ([[String concatenation]])
2 in PHP ([[Greatest subsequential sum]], [[Power set]])
5 in PicoLisp ([[ABC Problem]], [[AKS test for primes]], [[Generate lower case ASCII alphabet]], [[Left factorials]], [[Zeckendorf arithmetic]])
38 in PL/I ([[Array concatenation]], [[Assertions]], [[Bitmap/Bresenham's line algorithm]], [[Bitmap/Flood fill]], [[Call a foreign-language function]], [[Closest-pair problem]], [[Compile-time calculation]], [[Convert decimal number to rational]], [[Create a two-dimensional array at runtime]], [[Exceptions]], [[Formatted numeric output]], [[Generate lower case ASCII alphabet]], [[Handle a signal]], [[Hofstadter Figure-Figure sequences]], [[Hofstadter Q sequence]], [[Holidays related to Easter]], [[Image noise]], [[Linear congruential generator]], [[Multifactorial]], [[Multiplication tables]], [[N'th]], [[Narcissistic decimal number]], [[Palindrome detection]], [[Parsing/Shunting-yard algorithm]], [[Pascal's triangle]], [[Queue/Usage]], [[Range extraction]], [[Sequence of non-squares]], [[Sorting algorithms/Pancake sort]], [[Sorting algorithms/Selection sort]], [[Truncate a file]], [[Van der Corput sequence]], [[Zhang-Suen thinning algorithm]])
15 in PostScript ([[100 doors]], [[Arithmetic/Complex]], [[Arrays]], [[Averages/Arithmetic mean]], [[Averages/Pythagorean means]], [[Comments]], [[Flatten a list]], [[Higher-order functions]], [[Mutual recursion]], [[Sequence of non-squares]], [[String length]], [[Sum and product of an array]], [[Sum of a series]], [[Sum of squares]])
3 in PowerShell ([[Find common directory path]], [[Find limit of recursion]], [[Heronian triangles]])
2 in ProDOS ([[Dynamic variable names]], [[Menu]])
7 in Python ([[History variables]], [[Hofstadter Figure-Figure sequences]], [[Odd word problem]], [[Pythagorean triples]], [[Quine]], [[Sorting algorithms/Strand sort]], [[Strip control codes and extended characters from a string]])
6 in R ([[Find the missing permutation]], [[Heronian triangles]], [[Knapsack problem/0-1]], [[Number reversal game]], [[Power set]])
5 in Racket ([[Bernoulli numbers]], [[First-class functions]], [[Flipping bits game]], [[Heronian triangles]], [[Pi]])
1 in Raven ([[System time]])
8 in REXX ([[24 game]], [[Bitmap/Bresenham's line algorithm]], [[Forward difference]], [[Handle a signal]], [[Haversine formula]], [[Non-decimal radices/Convert]], [[Program termination]], [[Variables]])
2 in Ruby ([[FizzBuzz]], [[Rosetta Code/Find bare lang tags]])
2 in Rust ([[Command-line arguments]], [[Fibonacci n-step number sequences]])
1 in Scala ([[Rosetta Code/Find bare lang tags]])
15 in Scheme ([[Averages/Pythagorean means]], [[Bitmap]], [[Bitwise operations]], [[Conditional structures]], [[Function composition]], [[Horner's rule for polynomial evaluation]], [[Interactive programming]], [[Pascal's triangle]], [[Reduced row echelon form]], [[Sieve of Eratosthenes]])
27 in Scilab ([[Ackermann function]], [[AKS test for primes]], [[Catalan numbers/Pascal's triangle]], [[Comments]], [[Factorial]], [[Fibonacci sequence]], [[Gamma function]], [[Hailstone sequence]], [[Loops/Break]], [[Loops/Continue]], [[Loops/Do-while]], [[Loops/Downward for]], [[Loops/For]], [[Loops/For with a specified step]], [[Loops/Foreach]], [[Loops/Infinite]], [[Loops/N plus one half]], [[Loops/Nested]], [[Loops/While]], [[Lucas-Lehmer test]], [[Monty Hall problem]], [[Multiplication tables]], [[Sorting algorithms/Bubble sort]], [[Spiral matrix]], [[Standard deviation]], [[String concatenation]])
1 in Simula ([[Comments]])
5 in Swift ([[Create a two-dimensional array at runtime]], [[Guess the number/With feedback (player)]], [[Repeat a string]], [[Sierpinski triangle]], [[Sum of a series]])
1 in Tcl ([[Rosetta Code/Find bare lang tags]])
19 in uBasic/4tH ([[AKS test for primes]], [[Box the compass]], [[Calendar]], [[Chinese remainder theorem]], [[Dinesman's multiple-dwelling problem]], [[Hamming numbers]], [[Linear congruential generator]], [[Mandelbrot set]], [[N'th]], [[Pascal's triangle]], [[Primality by trial division]], [[Rock-paper-scissors]], [[Roman numerals/Encode]], [[Sierpinski triangle]], [[Stem-and-leaf plot]], [[Subtractive generator]], [[Twelve statements]], [[Zeckendorf number representation]])
2 in UNIX Shell ([[Factors of an integer]], [[Simple database]])
1 in Wart ([[Loops/Downward for]])
1 in XSLT ([[N-queens problem]])
6 in XSLT 2.0 ([[CSV to HTML translation]], [[Longest string challenge]], [[Stable marriage problem]])
4 in XSLT 3.0 ([[Knight's tour]])
5 in zkl ([[Carmichael 3 strong pseudoprimes]], [[Hamming numbers]], [[Introspection]], [[Lucas-Lehmer test]], [[Non-continuous subsequences]])

Perl[edit]

This is a simple implementation that does not attempt either extra credit.

my $lang = 'no language';
my $total = 0;
my %blanks = ();
while (<>) {
if (m/<lang>/) {
if (exists $blanks{lc $lang}) {
$blanks{lc $lang}++
} else {
$blanks{lc $lang} = 1
}
$total++
} elsif (m/==\s*{{\s*header\s*\|\s*([^\s\}]+)\s*}}\s*==/) {
$lang = lc $1
}
}
 
if ($total) {
print "$total bare language tag" . ($total > 1 ? 's' : '') . ".\n\n";
while ( my ($k, $v) = each(%blanks) ) {
print "$k in $v\n"
}
}

Perl 6[edit]

Translation of: Perl

The only tricky thing here is the use of the ms form of match, short for m:sigspace. This causes whitespace in the regex to be considered "significant", that is, it matches optional whitespace at those positions, as if you'd put \s* 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.

my $lang = '(no language)';
my $total = 0;
my %blanks;
 
for lines() {
when / '<lang>' / {
%blanks{$lang}++;
$total++;
}
when ms/ '==' '{{' 'header' '|' ( \S+? ) '}}' '==' / {
$lang = $0.lc;
}
}
 
say "$total bare language tag{ 's' if $total != 1 }\n";
say .value, ' in ', .key for %blanks.sort;
Output:
2 bare language tags

1 in (no language)
1 in perl

Racket[edit]

Note that this follows the task, but the output is completely bogus since the actual <lang> tags that it finds are in <pre> and in code...

 
#lang racket
 
(require net/url net/uri-codec json)
 
(define (get-text page)
(define ((get k) x) (dict-ref x k))
((compose1 (get '*) car (get 'revisions) cdar hash->list (get 'pages)
(get 'query) read-json get-pure-port string->url format)
"http://rosettacode.org/mw/api.php?~a"
(alist->form-urlencoded
`([titles . ,page] [prop . "revisions"] [rvprop . "content"]
[format . "json"] [action . "query"]))))
 
(define (find-bare-tags page)
(define in (open-input-string (get-text page)))
(define rx
((compose1 pregexp string-append)
"<\\s*lang\\s*>|"
"==\\s*\\{\\{\\s*header\\s*\\|\\s*([^{}]*?)\\s*\\}\\}\\s*=="))
(let loop ([lang "no language"] [bare '()])
(match (regexp-match rx in)
[(list _ #f) (loop lang (dict-update bare lang add1 0))]
[(list _ lang) (loop lang bare)]
[#f (if (null? bare) (printf "no bare language tags\n")
(begin (printf "~a bare language tags\n" (apply + (map cdr bare)))
(for ([b bare]) (printf " ~a in ~a\n" (cdr b) (car b)))))])))
 
(find-bare-tags "Rosetta Code/Find bare lang tags")
 
Output:
8 bare language tags
  2 in no language
  4 in Perl
  1 in AutoHotkey
  1 in Tcl

More-extra credit[edit]

Add the following code at the bottom, run, watch results.

 
(define (get-category cat)
(let loop ([c #f])
(define t
((compose1 read-json get-pure-port string->url format)
"http://rosettacode.org/mw/api.php?~a"
(alist->form-urlencoded
`([list . "categorymembers"] [cmtitle . ,(format "Category:~a" cat)]
[cmcontinue . ,(and c (dict-ref c 'cmcontinue))]
[cmlimit . "500"] [format . "json"] [action . "query"]))))
(define (c-m key) (dict-ref (dict-ref t key '()) 'categorymembers #f))
(append (for/list ([page (c-m 'query)]) (dict-ref page 'title))
(cond [(c-m 'query-continue) => loop] [else '()]))))
 
(for ([page (get-category "Programming Tasks")])
(printf "Page: ~a " page)
(find-bare-tags page))
 

Ruby[edit]

Quoting from the FAQ: "If you just want the raw wikitext without any other information whatsoever, it's best to use index.php's action=raw mode instead of the API"

require "open-uri"
require "cgi"
 
tasks = ["Greatest_common_divisor", "Greatest_element_of_a_list", "Greatest_subsequential_sum"]
part_uri = "http://rosettacode.org/wiki?action=raw&title="
Report = Struct.new(:count, :tasks)
result = Hash.new{|h,k| h[k] = Report.new(0, [])}
 
tasks.each do |task|
puts "processing #{task}"
current_lang = "no language"
open(part_uri + CGI.escape(task)).each_line do |line|
current_lang = Regexp.last_match["lang"] if /==\{\{header\|(?<lang>.+)\}\}==/ =~ line
num_no_langs = line.scan(/<lang\s*>/).size
if num_no_langs > 0 then
result[current_lang].count += num_no_langs
result[current_lang].tasks << task
end
end
end
 
puts "\n#{result.values.map(&:count).inject(&:+)} bare language tags.\n\n"
result.each{|k,v| puts "#{v.count} in #{k} (#{v.tasks})"}
Output:
processing Greatest_common_divisor
processing Greatest_element_of_a_list
processing Greatest_subsequential_sum

10 bare language tags.

2 in Euler Math Toolbox (["Greatest_common_divisor", "Greatest_element_of_a_list"])
1 in gnuplot (["Greatest_common_divisor"])
1 in Bracmat (["Greatest_element_of_a_list"])
2 in МК-61/52 (["Greatest_element_of_a_list", "Greatest_element_of_a_list"])
1 in ooRexx (["Greatest_element_of_a_list"])
2 in Mathprog (["Greatest_subsequential_sum", "Greatest_subsequential_sum"])
1 in PHP (["Greatest_subsequential_sum"])

Scala[edit]

To analyse RosettaCode pages, invoke Java with -Dhttp.agent=Anything to work around CloudFlare blocking Java from accessing the RosettaCode site.

// Map lines to a list of Option(heading -> task) for each bare lang tag found.
val headerFormat = "==[{]+header[|]([^}]*)[}]+==".r
val langFormat = "<lang([^>]*)>".r
def mapped(lines: Seq[String], taskName: String = "") = {
var heading = ""
for (line <- lines;
head = headerFormat.findFirstMatchIn(line).map(_ group 1);
lang = langFormat.findFirstMatchIn(line).map(_ group 1)) yield {
if (head.isDefined) heading = head.get
lang.map(_.trim).filter(_ == "").map(_ => heading -> taskName)
}
}
// Group results as a Map(heading -> task1, task2, ...)
def reduced(results: Seq[Option[(String,String)]]) =
results.flatten.groupBy(_._1).mapValues(_.unzip._2)
 
// Format each heading as "tasklist.size in heading (tasklist)"
def format(results: Map[String,Seq[String]]) = results.map{case (heading, tasks) =>
val h = if (heading.length > 0) heading else "no langauge"
val hmsg = s"${tasks.size} in $h"
val t = tasks.filterNot(_ == "")
val tmsg = if (t.isEmpty) "" else t.distinct.mkString(" (", ",", ")")
hmsg + tmsg
}
def count(results: Map[String,Seq[String]]) = results.values.map(_.size).sum
 
// Single and multi-source support
case class BareLangFinder(source: scala.io.Source, taskName: String = "") {
def map = mapped(source.getLines.toSeq, taskName)
def mapReduce = reduced(map)
def summary = format(mapReduce) mkString "\n"
}
def mapReduce(inputs: Seq[BareLangFinder]) = reduced(inputs.flatMap(_.map))

Examples:

val test = """
Description

<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")
Output:
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)

Tcl[edit]

For all the extra credit (note, takes a substantial amount of time due to number of HTTP requests):

Library: Tcllib (Package: json)
Library: Tcllib (Package: textutil::split)
Library: Tcllib (Package: uri)
package require Tcl 8.5
package require http
package require json
package require textutil::split
package require uri
 
proc getUrlWithRedirect {base args} {
set url $base?[http::formatQuery {*}$args]
while 1 {
set t [http::geturl $url]
if {[http::status $t] ne "ok"} {
error "Oops: url=$url\nstatus=$s\nhttp code=[http::code $token]"
}
if {[string match 2?? [http::ncode $t]]} {
return $t
}
# OK, but not 200? Must be a redirect...
set url [uri::resolve $url [dict get [http::meta $t] Location]]
http::cleanup $t
}
}
 
proc get_tasks {category} {
global cache
if {[info exists cache($category)]} {
return $cache($category)
}
set query [dict create cmtitle Category:$category]
set tasks [list]
 
while {1} {
set response [getUrlWithRedirect http://rosettacode.org/mw/api.php \
action query list categorymembers format json cmlimit 500 {*}$query]
 
# Get the data out of the message
set data [json::json2dict [http::data $response]]
http::cleanup $response
 
# add tasks to list
foreach task [dict get $data query categorymembers] {
lappend tasks [dict get [dict create {*}$task] title]
}
 
if {[catch {
dict get $data query-continue categorymembers cmcontinue
} continue_task]} then {
# no more continuations, we're done
break
}
dict set query cmcontinue $continue_task
}
return [set cache($category) $tasks]
}
proc getTaskContent task {
set token [getUrlWithRedirect http://rosettacode.org/mw/index.php \
title $task action raw]
set content [http::data $token]
http::cleanup $token
return $content
}
 
proc init {} {
global total count found
set total 0
array set count {}
array set found {}
}
proc findBareTags {pageName pageContent} {
global total count found
set t {{}}
lappend t {*}[textutil::split::splitx $pageContent \
{==\s*\{\{\s*header\s*\|\s*([^{}]+?)\s*\}\}\s*==}]
foreach {sectionName sectionText} $t {
set n [regexp -all {<lang>} $sectionText]
if {!$n} continue
incr count($sectionName) $n
lappend found($sectionName) $pageName
incr total $n
}
}
proc printResults {} {
global total count found
puts "$total bare language tags."
if {$total} {
puts ""
if {[info exists found()]} {
puts "$count() in task descriptions\
(\[\[[join $found() {]], [[}]\]\])"

unset found()
}
foreach sectionName [lsort -dictionary [array names found]] {
puts "$count($sectionName) in $sectionName\
(\[\[[join $found($sectionName) {]], [[}]\]\])"

}
}
}
 
init
set tasks [get_tasks Programming_Tasks]
#puts stderr "querying over [llength $tasks] tasks..."
foreach task [get_tasks Programming_Tasks] {
#puts stderr "$task..."
findBareTags $task [getTaskContent $task]
}
printResults

zkl[edit]

Translation of: Ruby

Uses shared library cURL.

var [const] CURL=Import("zklCurl"),
partURI="http://rosettacode.org/wiki?action=raw&title=%s",
langRE=RegExp(0'!\s*==\s*{{\s*header\s*|(.+)}}!), // == {{ header | zkl }}
emptyRE=RegExp(0'!<lang\s*>!);
 
fcn findEmptyTags(a,b,c,etc){ // -->[lang:(task,task...)]
results:=Dictionary();
foreach task in (vm.arglist){
println("processing ",task);
currentLang:="";
page:=CURL().get(partURI.fmt(CURL.urlEncode(task)));
foreach line in (page[0]){
if(langRE.search(line,True)){
lang:=langRE.matched[1].strip();
if(lang) currentLang=lang;
}
if(emptyRE.matches(line,True)) results.appendV(currentLang,task);
}
}
results
}
results:=findEmptyTags("Greatest_common_divisor", "Greatest_element_of_a_list", 
"Greatest_subsequential_sum");
println("\n%d bare language tags:".fmt(results.values.apply("len").sum(0)));
foreach lang in (results.keys.sort()){
tasks:=results[lang];
println("%d in %s: %s".fmt(tasks.len(),lang,tasks.concat(",")));
}
Output:
processing Greatest_common_divisor
processing Greatest_element_of_a_list
processing Greatest_subsequential_sum

14 bare language tags:
1 in Bracmat: Greatest_element_of_a_list
1 in ERRE: Greatest_subsequential_sum
2 in Euler Math Toolbox: Greatest_common_divisor,Greatest_element_of_a_list
2 in Mathprog: Greatest_subsequential_sum,Greatest_subsequential_sum
1 in PHP: Greatest_subsequential_sum
1 in Ring: Greatest_common_divisor
1 in gnuplot: Greatest_common_divisor
1 in ooRexx: Greatest_element_of_a_list
2 in uBasic/4tH: Greatest_common_divisor,Greatest_element_of_a_list
2 in МК-61/52: Greatest_element_of_a_list,Greatest_element_of_a_list