함수형 프로그래밍 언어에서 중요한 개념이며,
JavaScript와 Python등에서 Closure와 같은 다양한 디자인패턴을 응용 및 구현하는데 중요한 역할을 한다.
함수형 언어 관련 참고 자료 :
[summary] imperative language, declarative language...
Imperative language란? 프로그래밍 언어는 컴퓨터의 연산을 모방하고 추상화하는 것에서 출발. 때문에 컴퓨터의 구조가 언어 설계에 영향을 미치게 됨. Von noemmen 구조, 튜링머신을 반영한 프로그래밍
ds31x.blogspot.com
first-class object 정의
일단 정의를 살펴보면 다음과 같음.
first-class object는 다음과 같은 성질을 가진 entity (독립체)임.
- expression 내에서 사용가능해야함. (expression을 구성하는데 사용될 수 있어야 함)
- variable에 assignment가 가능해야함. *
- function 이나 method 호출 등에서 argument로 사용가능해야함. *
- function call의 return value로 사용가능해야함.
위의 네가지 성질의 주요 알파벳을 따서 EVAC
라는 acronym으로도 불림.
First-class objects can be used in
Expressions, as Variables, and as Arguments, and can be returned by function Calls.
프로그래밍 언어에서의 int
나 float
, string
등의 기본적인 data type이 대표적인 firt-class object이다.
- 특정 type, object, entity, value가 first-class object라면
이들 기본적인 data type과 비교하여 어떤 차이점 없이 사용가능하다는 점을 강조하면서
first-class object라고 불림 (Christopher Strachey 의 정의). - 위의 4가지 성질들로 구체적 나타낸 것은 Robin Popplestone 의 정의에 기반함.
Python에서 function은 first-class object.
주의할 점은 imperative programming language에서는 보통 function은 first-class object가 아닌 반면,
functional programming language에서는 function 도 first-class object이다.
Python은 imperative language로 분류되기도 하지만,
function이 first-class object이다.
- Python에서
map
이나filter
등에서 - iterator와 해당 iterator의 각 iteration마다
- 적용할 function을 argument로 받던 걸 기억할것.
References
https://isaaccomputerscience.org/concepts/prog_func_first_class_objects?examBoard=all&stage=all
Isaac Computer Science
The free online learning platform for GCSE and A level Computer Science students and teachers. Discover our computer science revision and homework questions today.
isaaccomputerscience.org
함수형 프로그래밍이란 ? functional programming?
함수형 프로그래밍 프로그래밍의 여러 종류 중 하나이며, 함수(function)을 이용해 프로그래밍을 하는 것 입니다. => 함수로만 이수어진 프로그램이라고 생각하면 편할 것 같습니다. 함수형 프로그
99geo.tistory.com
1급 객체(first-class object)란?
일급 객체라는 말이 요새는 많이 보편화가 된 것 같습니다. 제가 이 말을 처음 들었던 건 자바스크립트에서였는데, 단순히 자바스크립트에 국한된 개념은 아니더군요. 프로그래밍 언어론 수업
jcsoohwancho.github.io
'Python' 카테고리의 다른 글
[Python] scope와 키워드 global, nonlocal (0) | 2023.07.15 |
---|---|
[Python] Nested Function (0) | 2023.07.15 |
[Python] Callback function (0) | 2023.07.13 |
[Python] overloading, overriding, and special methods (0) | 2023.07.13 |
[Python] special methods and operator overloading (0) | 2023.07.13 |