4. 기계적인 방식만으론 사실인지 판정할 수 없는, 그런 명제가 존재한다.
참과 거짓을 판단할 수 있는 내용
1931
1936
강의 Max Newman
1945
Von Neumann
architecture
Princeton University
Turing machine
Type, Head, Table, State
register
Finite state machine = Lambda calculus
λ𝒙. 𝒕
추천
1930 1936 1940
8. 부수 효과(Side effects)
집합 X의 각 원소에 집합 Y의 원소가 오직 하나만 대응될 때,
이 대응관계를 X에서 Y로의 함수라고 하고,
f: X → Y 또는 y = f(x)로 나타낸다.
기대 값 외
Foo
null
입력
Foo
출력
Foo f(Foo x)int f(int x)
{
// 공유 변수
}
데이터 레이스
1
2
3
입력
...
1936
8
9
출력
...
예외, 응답 없음
1
2
3
입력
1936
8
?
출력
int f(int x)
{
// 예외
}
...
...
2
3
입력
1936
8
9
출력
1
입력 값 변경
int f(out int x)
...
...
2
3
입력
1936
8
9
출력
1
출력’
출력 외 변경
int f(int x)
{
// 외부 변경
}
...
...
1
2
3
입력
1936
8
9
출력
...
...
수학
9. 수학적
함수
=
함수는 입력과 출력이 있다.
모든 의존성
Read Only
단일 결과
Create
단일 책임
C
R
U
D
reate
ead
pdate
elete
Lock Free
불변
Single Responsibility Principle
10. 부수 효과
無
같은 값
다른 값
같은 값
같은 값
입력
출력
참조
투명성
참조
불투명성
1
2
3
입력
1936
8
9
출력
...
...
집합 X의 각 원소에 집합 Y의 원소가 오직 하나만 대응될 때,
이 대응관계를 X에서 Y로의 함수라고 하고,
f: X → Y 또는 y = f(x)로 나타낸다.
수학
함수의 출력 값은 그 함수에 입력된 인수에만 의존하므로
인수 x에 같은 값을 넣고 함수 f를 호출하면 항상 f(x)라는 결과가 나온다.
A function gives the same value for same arguments.
참조 투명성
Referential transparency
참조 불투명성
Referential opacity
11. 수학적
함수
=
명령형 함수 부수 효과
-
=
1
2
3
입력
1936
8
9
출력
...
...
+
참조 투명성
A function gives
the same value
for same arguments.
= 순수 함수
Pure Function
…
12. 정적 메소드
비순수 함수
DateTime impure = DateTime.Now;
pure1.AddDays(7);
DateTime pure2 = pure1.AddDays(7);
메소드
순수 함수
DateTime pure1 = new DateTime(2016, 9, 28);
15. 수학적
함수 = 명령형 함수 부수 효과- 참조 투명성+
값=
일급 시민
First-class citizen
순수 함수=
int x = f(1); = int x = 1936;
치환(Substitution)
변수 = 값;
함수(값);
함수( … ) { return 값; }
함수 (함수);
함수 ( … ) { return 함수; }
변수 = 함수;
일급 시민
함수를 받고/전달할 수 있는 함수?
(일급 시민)
These operations typically include being
passed as an argument,
returned from a function,
and assigned to a variable.
16. 일급 시민
First-class citizen
These operations typically include being
passed as an argument,
returned from a function,
and assigned to a variable. 변수 = 값;
함수(값);
함수( … ) { return 값; }
함수 (함수);
함수 ( … ) { return 함수; }
변수 = 함수;
람다 표현식
Lambada Expression
고차 함수
Higher-Order Function
함수를 받고/전달할 수 있는 함수?
(일급 시민)
17. double f(int x)
{
return …
}
double f(int x)
{
return …
}
f(int x)
{
return …
}
f(20);
f(x)
{
return …
}
함수는 입력과 출력이 있다.
f(x)
{
…
}
람다 대수는
함수를 단순하게 표현할 수 있도록 하여 '함수의 계산'이라는 개념을
더 깊이 이해할 수 있게 돕는다.
함수가 반드시 이름을 가질 필요는 없다.
(x)
{
…
}
반복
x =>
…
구분
X => …=
18. = 순수 함수 - 함수 이름람다 표현식
수학적
함수
= 명령형 함수 부수 효과- 참조 투명성+
순수 함수=
값=
일급 시민
First-class citizen
…
19. 수학적
함수
= 명령형 함수 부수 효과- 참조 투명성+
순수 함수=
값=
일급 시민
First-class citizen
함수 (함수);
함수 ( … ) { return 함수; }
변수 = 함수;
일급 시민
고차 함수 = 순수 함수 + 순수 함수 입력 || 순수 함수 출력
OR
20. the strategy pattern is a software design pattern
that enables an algorithm's behavior to be selected at runtime.
https://en.wikipedia.org/wiki/Strategy_pattern
23. f f
연결(Flow)할 수 있는 함수는?
int int xf( )
void f( )
void f( )int x
int f( )
f
f
f
f
f f
f
f
f
f
Fluent Interface프로그래밍 언어
함수 합성(Composition)수학
결합 법칙을 만족시킨다.
(2 + 3) + 5 = 2 + (3 + 5)
연산 순서를 따로 지정하지 않아도 모호함 없이 수식의 값이 결정된다.
24. The builder pattern is an object creation software design pattern.
Instead of using numerous constructors,
the builder pattern uses another object, a builder,
that receives each initialization parameter step by step
and then returns the resulting constructed object at once.
https://en.wikipedia.org/wiki/Builder_pattern
26. https://en.wikipedia.org/wiki/Fluent_interface
a fluent interface (as first coined by Eric Evans and Martin Fowler) is
an implementation of an object oriented API
that aims to provide more readable code.
Domain-Driven Design Refactoring
A fluent interface is normally implemented
by using method cascading (concretely method chaining)
to relay the instruction context of a subsequent call.
Self-Referential
Ex.
30. 조건도 함수다.
𝒇 𝒙 =
𝑥 + 1
𝑥 + 2
( 𝒙 > 𝟎 )
( 𝒙 < 𝟎 )
int output;
if (x > 0)
output = x + 1;
else if (x < 0)
output = x + 2;
int output = if (x > 0)
output = x + 1;
else if (x < 0)
output = x + 2;
int output = if (x > 0)
return x + 1;
else if (x < 0)
return x + 2;
C
R
U
D
reate
ead
pdate
elete
?
31. 𝒇 𝒙 =
𝑥 + 1
𝑥 + 2
( 𝑥 > 0 )
( 𝑥 < 0 )
With 라이브러리, …
https://github.com/wallymathieu/with
결과 값
조건