Debugging Sparrow

스칼라, 함수형 프로그래밍(4) - 조건과 값

2020/03/12 Scala 스칼라 함수형 프로그래밍 Functional Programming Conditional Expression

Martin Odersky의 Functional Programming Principles in Scala 강의를 공부하며 정리했습니다.

조건 표현식(Conditional Expressions)

스칼라에서도 두가지 항목을 선택할 수 있는 방법이 있습니다. 자바에서와 같이 if-else로 보이지만 주의해야 할 것은 statements가 아니라 표현식이라는 것입니다.

if-else
1
def abs(x: Int) = if (x >= 0) x else -x

Boolean 표현식(Boolean Expressions)

example
1
2
3
4
5
6
7
8
9
10
true false
!b
b && b
b || b
e <= e
e >= e
e < e
e > e
e == e
e != e

Rewrite rules for Booleans

example
1
2
3
4
5
6
!true       -->  false
!false --> true
true && e --> e
false && e --> false
true || e --> true
false || e --> e

Author: dbgsprw

Link: https://dbgsprw.github.io/2020/03/12/스칼라-함수형-프로그래밍4/

Copyright: All articles in this blog are licensed under CC BY-NC-SA 3.0 unless stating additionally.

< PreviousPost
Distributed Time Travel for Feature Generation
NextPost >
스칼라, 함수형 프로그래밍(3) - 평가 전략과 종료(Evaluation Strategies and Termination)
CATALOG
  1. 1. 조건 표현식(Conditional Expressions)
  2. 2. Boolean 표현식(Boolean Expressions)
    1. 2.1. Rewrite rules for Booleans