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) product | |
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
/* | |
* This source-code is based on | |
* source-code on http://blog.srinivasan.biz/software/if-you-have-to-learn-just-one-programming-language | |
* Using foldLeft often simplifies functional codes. | |
*/ | |
/* | |
* Question: Do you want to play this game? | |
* You put down some money and roll a die between 1 and 100 | |
* Depending on your roll: | |
* 1-50: I keep your money. |
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 StringDump{ | |
implicit def enrichString(str: String) = new { | |
def dump:String={ | |
str.getBytes("UTF-8").map{ _.asInstanceOf[Char] match{ | |
case n @ ('"' | '\\') => "\\" + n | |
case n if ' ' <= n && n <= '~' => n | |
case n => "\\%03o" format (n&0xff) | |
}}.mkString("\"","","\"") | |
} | |
} |
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 scala.util.parsing.combinator._ | |
/** | |
* expr :: CREATE TABLE tbl_name ( create_definition,...) | |
* | |
* create_definition: | |
* col_name column_definition | |
* | |
* column_definition: | |
* data_type |
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
This program is a 2D shooting game written in Scala by | |
@h_sakurai(http://twitter.com/h_sakurai), | |
and has been originally hosted at https://gist.github.com/46448 . | |
@ymnk(http://twitter.com/ymnk) has slightly modified that code | |
to run it on scala 2.8 with sbt. | |
$ sbt | |
> run |
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
/* | |
* ftdop2.scala | |
* Functional Top Down Operator Precedence | |
*/ | |
package ftdop2 | |
import scala.util.matching.Regex | |
import scala.collection.mutable.HashMap | |
object main { | |
def main(argv:Array[String]) { |
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 pdr; | |
import javax.swing._; | |
import java.awt._ | |
import java.awt.geom._; | |
import java.awt.image._ | |
import java.io._ | |
import scala.collection.mutable.ArrayBuffer | |
import scala.collection.mutable.HashMap |
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 jp.takeda_soft.examples | |
/** | |
世界のナベアツに挑戦 | |
テーマ:implicitによるScalaAPIの拡張 | |
*/ | |
object Nabeatsu extends Application { | |
//Intがバカになるメソッド"!"を追加 | |
implicit def bakanize(n: Int) = new Bakanizer(n) |