This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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))} | |
} | |
} |
NewerOlder