This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>() = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
~ | |
% 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object OverloadSample { | |
implicit class B2I(f: Boolean => Int) | |
implicit class I2I(f: Int => Int) | |
def foo(func: B2I): Unit = { | |
println("test") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def foo(func: Boolean => Int) = ??? | |
def foo(func: Int => Int) = ??? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> object Label extends Enumeration{ | |
| val ga, o, ni, none = Value | |
| } | |
defined object Label | |
scala> Label.values | |
res0: Label.ValueSet = Label.ValueSet(ga, o, ni, none) | |
scala> Label.values.map(_.toString) | |
res1: scala.collection.immutable.SortedSet[String] = TreeSet(ga, ni, none, o) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package yuima.funcpearls | |
import scala.annotation.tailrec | |
/** Scala implementation of "Solving the Snake Cube Puzzle in Haskel." | |
* http://web.cecs.pdx.edu/~mpj/snakecube/revised-SnakeCube.pdf | |
* | |
* Note: No implementation for a function "advance" in section 9. | |
* | |
* @author Yuichiroh Matsubayashi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.PrintWriter | |
import scala.io.Source | |
implicit class Using[T <: AutoCloseable](resource: T) { | |
def foreach[R](op: T => R): R = { | |
try op(resource) | |
catch { case e: Exception => throw e } | |
finally resource.close() | |
} |
OlderNewer