- JDKがinstall済みであること
- java コマンドに環境変数Pathが通っていること
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 Factorial { | |
def fact(n: Int) = (1 to n).foldLeft(1)(_*_) | |
def main(args: Array[String]) = { | |
val n = if(args.length == 0) 1 else args(0).toInt | |
1 to n foreach {i => println(i + "! = " + fact(i))} | |
} | |
} |
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
class Foo { | |
import scala.collection.mutable.ArrayBuffer | |
val elements = List(1,2,3) | |
//ClassManifest is needed | |
def map[T:ClassManifest](block: Int => T) = { | |
val vals = ArrayBuffer[T]() | |
elements foreach{ i => vals += block(i) } | |
vals.toArray | |
} | |
} |
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 miniparser | |
import scala.util.parsing.combinator.RegexParsers | |
object Main { | |
def main(args: Array[String]): Unit = { | |
val expr = """ | |
println("result: "+(3+(if ({ | |
println("cond"); |
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 miniparser | |
import scala.util.parsing.combinator.RegexParsers | |
import scala.collection.mutable.Map | |
object Main { | |
def main(args: Array[String]): Unit = { | |
val expr = """ | |
val aa = 23; |
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 factorial = (n) => { | |
if(n < 2) 1 else (n * factorial(n - 1)); | |
}; | |
println("factorial(3) = " + factorial(3)); | |
def mkcounter(n) = () => { | |
n = n + 1; | |
n | |
}; | |
val counter = mkcounter(6); |
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 eith[R](arg: Either[Throwable, R] ) : R = { | |
/* Right(o:Either[Throwable, R]) パターンは | |
* erasureのせいで警告が出る点に注意 */ | |
arg match { | |
case Left(e) => throw e | |
case Right(o:Either[Throwable, R]) => eith(o) | |
case Right(o:R) => o | |
} | |
} | |
println(eith(Right(1))) |
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 hexToStr(s:String):String = { | |
s.grouped(2).map{xx => Integer.parseInt(xx, 16).toChar}.mkString("") | |
} | |
val target = 'a' to 'z' mkString | |
val hexTarget = target map {"%02x" format _.toInt} mkString | |
assert(target == hexToStr(hexTarget)) |
Scala公式ページの論文一覧のページのhtmlをパースして、自動でpdfのファイルっぽいものを全部ダウンロードするだけのものです
OlderNewer