Skip to content

Instantly share code, notes, and snippets.

View gist:e1119736ec541bf4785b
def withPrintWriter(file: String)(op: PrintWriter => Unit) {
val writer = new PrintWriter(file)
try op(writer)
finally writer.close
}
withPrintWriter("out.txt") { w =>
w.println("anything you want to write")
}
View gist:810d292276d6d87bd79b
val scores = Array(
Array(1, 2, 3, 4, 5),
Array(1, 2, 3, 4, 5),
Array(1, 2, 3, 4, 5),
Array(1, 2, 3, 4, 5),
Array(1, 2, 3, 4, 5)
)
val bests = Array.fill(5)(Array.fill(5)(0))
View gist:06f1aef644b52740d8d1
~
% scala -Xshow-phases
phase name id description
---------- -- -----------
parser 1 parse source into ASTs, perform simple desugaring
namer 2 resolve names, attach symbols to named trees
packageobjects 3 load package objects
typer 4 the meat and potatoes: type the trees
patmat 5 translate match expressions
superaccessors 6 add super accessors in traits and nested classes
View gist:a4b8c3c7603aef4ab7dd
scala> for(i <- 0 to 5) yield { i + 1 }
[[syntax trees at end of parser]] // <console>
package $line3 {
object $read extends scala.AnyRef {
def <init>() = {
super.<init>();
()
};
object $iw extends scala.AnyRef {
def <init>() = {
View gist:c0057381a596aa2f0256
~
% scala -Xprint:parser
Welcome to Scala version 2.11.4 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_25).
Type in expressions to have them evaluated.
Type :help for more information.
scala> [[syntax trees at end of parser]] // <init>
package <empty> {
class $repl_$init extends scala.AnyRef {
def <init>() = {
View gist:8e30e924eaaefc20801c
println("This is what I want to say.")
Console.err.println("standard error")
Console.withOut(new PrintStream("out.txt")) {
println("anything you want to write")
Console.out.close()
}
Console.out.println("Hi. I'm stdin again!")
You can’t perform that action at this time.