파이썬의 퍼스크 클래스 함수에 관한 글입니다. 


퍼스트 클래스 시민에 대한 글을 먼저 보고 오시면 좋을 듯 합니다.


In computer science, a programming language is said to have first-class functions if it treats functions as first-class citizens. Specifically, this means the language supports passing functions as arguments to other functions, returning them as the values from other functions, and assigning them to variables or storing them in data structures.
- 위키피디아


퍼스트 클래스 함수(First Class Function)란 함수를 퍼스트 클래스 시민(first-class citizens)으로 다루는 것을 의미합니다. 


즉, 변수에 담을 수 있고, 함수의 인자로 전달하고 함수의 리턴 값(return value)로 전달할 수 있는 함수입니다.



함수를 퍼스트 클래스 객체로 다룰 수 있게 지원하는 것은 함수형 언어의 특징이라고 합니다. 그렇다면 객체지향 언어인 파이썬(Everything is An Object)에서는 어째서 퍼스트 클래스 함수를 지원할까요?


그래서 주변에 물어봤는데 대부분의 답변은 다양하고 기발한 코딩이 가능하기 때문이라고 합니다. 그에 대한 예시로는 데코레이터, 익명 함수 등이 있을 것입니다.



퍼스트 클래스 함수는 후의 클로저(closure)라는 개념을 공부할 때 이어집니다.



출처


https://en.wikipedia.org/wiki/First-class_function


http://bestalign.github.io/2015/10/18/first-class-object/


http://schoolofweb.net/blog/posts/%ED%8C%8C%EC%9D%B4%EC%8D%AC-%ED%8D%BC%EC%8A%A4%ED%8A%B8%ED%81%B4%EB%9E%98%EC%8A%A4-%ED%95%A8%EC%88%98-first-class-function/


http://blog.doortts.com/135


http://stackoverflow.com/questions/245192/what-are-first-class-objects

블로그 이미지

NCookie

,

위키피디아에서는 first-class citizen을 다음과 같이 정의하고 있습니다.


In programming language design, a first-class citizen (also typeobjectentity, or value) in a given programming language is an entity which supports all the operations generally available to other entities. These operations typically include being passed as an argument, returned from a function, and assigned to a variable.

- Wikikpedia


  프로그래밍 언어 디자인에서 프로그래밍 언어의 first-class citizen는 다른 엔티티가 일반적으로 사용할 수 있는 모든 작업들을 지원하는 엔티티라고 합니다. 이러한 작업들에는 객체 등을 함수의 인자로 넘기거나, 함수에서 반환하고 변수에 할당할 수 있는 것들이 포함되어 있습니다.



first, second class 객체의 개념은 1960년대 Christopher Strachey에 의해 소개되었습니다. 그는 실제로 용어를 엄격하게 정의하지는 않았지만 ALGOL에서 실제 수와 프로시져를 비교하였습니다.


그는 직접 변수에 할당할 수 있는 실수(real number)가 first-class citizen인 것과 달리 그렇지 못한 프로시저는 second-class citizen이라고 하였습니다.



일반적으로 1급 시민의 조건은 다음과 같이 정의한다고 합니다. (참고)

  • 변수(variable)에 담을 수 있다
  • 인자(parameter)로 전달할 수 있다
  • 반환값(return value)으로 전달할 수 있다



블로그 이미지

NCookie

,