스칼라 콘솔에서 테스트하고 싶은 예제 코드가 있을 때 실행 라인이 아닌
전체 예제 코드를 실행하고 싶을 때 :paste를 사용하면 된다.
스칼라 콘솔(REPL)을 실행한다.
scala>
:paste를 입력하고 엔터를 입력한다.
scala> :paste
// Entering paste mode (ctrl-D to finish)
그리고 코드를 입력 한 후 Ctrl+D 키를 함께 누른다.
그러면 결과가 실행된다.
scala> :paste
// Entering paste mode (ctrl-D to finish)
def max(xs: List[Int]): Int = xs match {
case List() => throw new java.util.NoSuchElementException
case x :: Nil => x
case _ => val t: Int = max(xs.tail); if (t > xs.head) t else xs.head
}
val m = max(List(3,2,1,100))
print(m)
// Exiting paste mode, now interpreting.
m: Int = 100
'scala' 카테고리의 다른 글
[scala] foldLeft, fodRight, reduceLeft, reduceRight, scanLeft, scanRight 함수 예제 (0) | 2017.07.24 |
---|---|
[scala] 마이크로 벤치마킹 툴 - scala meter 예제 (0) | 2017.07.21 |
[scala] DynamicVariable 예제 (0) | 2017.07.07 |
[scala] 변수를 사용하기 위한 underscore (0) | 2017.07.05 |
[scala] Church Rosser 이론 (Lambda calculus)에 대한 링크 펌질 (0) | 2017.07.04 |