Rosetta Code/Count examples: Difference between revisions

(Added Bracmat example)
Line 1,787:
 
=={{header|Scala}}==
[[Category:Scala Implementations]]{{libheader|Scala}}<lang Scala>import scala.language.postfixOps
This was writen for Scala 2.8, but Scala 2.7
can be used with slight modifications to the
IO library.
 
object TaskCount extends App {
Different than the example for other languages,
<lang scala> import java.net.{ URL, URLEncoder }
it parallelizes the reading and counting, and
import scala.io.Source.fromURL
it also encode the URL, because some URLs are
now causing problems. These modifications are
minor, though.
 
System.setProperty("http.agent", "*")
It was written in script style.
val allTasksURL =
val allTasksURL = "http://www.rosettacode.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:Programming_Tasks&cmlimit=500&format=xml"
val allTasks = xml.parsing.XhtmlParser(fromURL(new URL(allTasksURL)))
 
val regexExpr = "(?i)==\\{\\{header\\|".r
<lang scala>import java.net.{URL, URLEncoder}
import scala.io.Source.fromURL
 
def oneTaskURL(title: String) = {
val allTasksURL = "http://www.rosettacode.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:Programming_Tasks&cmlimit=500&format=xml"
println(s"Check $title")
val allTasks = xml.parsing.XhtmlParser(fromURL(new URL(allTasksURL)))
def oneTaskURL(title: String) = "http://www.rosettacode.org/w/index.php?title=%s&action=raw" format URLEncoder.encode(title.replace(' ', '_'), "UTF-8")
}
 
def count(title: String) = regexExpr findAllIn fromURL(new URL(oneTaskURL(title)))(io.Codec.UTF8).mkString length
val regexExpr = "(?i)==\\{\\{header\\|".r
def oneTaskURL(title: String) = "http://www.rosettacode.org/w/index.php?title=%s&action=raw" format URLEncoder.encode(title.replace(' ', '_'), "UTF-8")
def count(title: String) = regexExpr findAllIn fromURL(new URL(oneTaskURL(title)))(io.Codec.UTF8).mkString length
 
val counts = for (task <- allTasks \\ "cm" \\ "@title" map (_.text)) yield scala.actors.Futures.future((task, count(task)))
 
counts map (_.apply) map Function.tupled("%s: %d examples." format (_, _)) foreach println
println("\nTotal: %d examples." format (counts map (_.apply._2) sum))
}</lang>
 
=={{header|Tcl}}==
Anonymous user