-> "Eval",! | 'P' -> "Print", 'L' -> "Loop")! ! scala> for ((k, v) <- repl) println(k + " is for " + v)! R is for Read! E is for Eval! P is for Print! L is for Loop
LET (’a := 5)! 20 IF ‘a === 5 THEN 40! 30 PRINT "This will never execute"! 40 PRINT "They were equal!"! 50 IF ‘a === 6 THEN 70! 60 PRINT "This will execute 1st..."! 70 PRINT "...then this!"! 80 END! ! RUN! }
public final String name;! public final int age;! ! public Person(String name, int age) {! this.name = name;! this.age = age;! }! }! ! // IIS.scala! object IIS extends App {! val p = new Person("John", 20)! println(p.name + " is " + p.age + " years old")! }
feathers = println("The duck has white and gray feathers.")! }! ! class Person {! def quack = println("The person imitates a duck.")! def feathers = println("The person takes a feather! from the ground and shows it.")! }! ! def inTheForest(duck: { def quack; def feathers }) = {! duck.quack! duck.feathers! }
and gray feathers.! ! scala> inTheForest(new Person)! The person imitates a duck.! The person takes a feather from the ground and shows it.! ! ! scala> inTheForest("Duck")! error: type mismatch;! found : String("Duck")! required: AnyRef{def quack: Unit; def feathers: Unit}! inTheForest("Duck")
case 1 =>! str = "one"! case 2 =>! str = "two"! case _ =>! str = "many"! }! println(str) ! val str = num match {! case 1 => "one"! case 2 => "two"! case _ => "many"! }! println(str)
extends Element! case class Num(value: Int) extends Element! case class Neg(arg: Element) extends Element! case class Add(arg1: Element, arg2: Element) extends Element! ! def optimize(elem: Element): Element = elem match {! case Neg(Neg(x)) => optimize(x)! case Add(x, Num(0)) => optimize(x)! case Neg(Num(x)) => Num(-x)! case Add(x, Neg(y)) if x == y => Num(0)! case Add(Num(x), Num(y)) => Num(x + y)! case Neg(x) => Neg(optimize(x))! case Add(x, y) => Add(optimize(x), optimize(y))! case _ => elem! }
null, "IIS")! val found = set find { _ == null }! ! if (found != null) {! // huh, we've found it or not? ! println("Found " + found + "!") ! } else {! println("Not found.")! }
Option[A]! case object None extends Option[Nothing]! ! val set = Set(42, null, "IIS")! val found = set find { _ == null }! ! found match {! case Some(elem) =>! println("Found " + elem + "!")! case None =>! println("Not found.")! }
guides & tutorials • Programming in Scala: Second Edition – книжка для начала • http://scala-ide.org – Scala IDE for Eclipse • http://plugins.intellij.net/plugin/?id=1347 – IntelliJ IDEA plugin