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
use std::fmt; | |
use List::{Cons, Nil}; | |
use std::sync::Arc; | |
#[derive(PartialEq, Clone)] | |
enum List<T> { | |
Cons(T, Arc<List<T>>), | |
Nil | |
} | |
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
use lists::{filter, new_list}; | |
mod lists { | |
use std::fmt; | |
use lists::List::{Cons, Nil}; | |
use std::sync::Arc; | |
#[derive(PartialEq, Clone)] | |
pub enum List<T> { | |
Cons(T, Arc<List<T>>), |
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
use lists::{contains, new_list}; | |
mod lists { | |
use std::fmt; | |
use lists::List::{Cons, Nil}; | |
use std::sync::Arc; | |
#[derive(PartialEq, Clone)] | |
pub enum List<T> { | |
Cons(T, Arc<List<T>>), |
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
use lists::{count, new_list}; | |
mod lists { | |
use std::fmt; | |
use lists::List::{Cons, Nil}; | |
use std::sync::Arc; | |
#[derive(PartialEq, Clone)] | |
pub enum List<T> { | |
Cons(T, Arc<List<T>>), |
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 NullAsInstanceOfInt { | |
def main(args: Array[String]): Unit = { | |
println { null.asInstanceOf[Int] == 0 } // true | |
println{ null.asInstanceOf[Int] + 1 } // 1 | |
println{ null.asInstanceOf[Int] } // null | |
println{ val x = null.asInstanceOf[Int]; x } // 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
package controllers | |
import play.api.mvc._ | |
object Application extends Controller { | |
def upload = Action(parse.multipartFormData) { | |
request => | |
if (request.body.files.isEmpty) BadRequest("Invalid file!") | |
else if (request.body.asFormUrlEncoded.isEmpty) BadRequest("Invalid data!") | |
else Ok("Everything is okay!") |
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 Hello { | |
def main(args: Array[String]): Unit = { | |
foo() | |
} | |
@inline def foo() = println("Foo") | |
} |
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 TLambda { | |
trait Lambda { type apply[a <: Lambda] <: Lambda } | |
type Y = Lambda { | |
type apply[f <: Lambda] = (Lambda { | |
type apply[proc <: Lambda] = f#apply[Lambda { | |
type apply[arg <: Lambda] = proc#apply[proc]#apply[arg] | |
}] | |
})#apply[Lambda { | |
type apply[proc <: Lambda] = f#apply[Lambda { | |
type apply[arg <: Lambda] = proc#apply[proc]#apply[arg] |
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.io._ | |
import scala.util.parsing.combinator.syntactical._ | |
import org.objectweb.asm.ClassWriter | |
import org.objectweb.asm.MethodVisitor | |
import org.objectweb.asm.Label | |
import org.objectweb.asm.Opcodes._ | |
object Calculator extends StandardTokenParsers { | |
lexical.delimiters ++= List( | |
"(", ")","+","-","*","/", ">", "<", ">=", "<=", "=", ";" |
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.xml._ | |
object Attrs { | |
def unapplySeq(data: MetaData): Option[Seq[(String, String)]] = { | |
Some(data.map{(m:MetaData) => (m.key, m.value(0).text)}.toList) | |
} | |
def main(args: Array[String]) { | |
val foo = <foo a="1" b="2" c="3"/> | |
//困ったことに、XMLリテラルは属性の順番を保存してくれないので、 | |
//ファイルから読み込むとか別の方法が必要 | |
//XML.loadStringとかだと属性が逆順で読み込まれるっぽい |