Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Function object
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Description == A typical use of a function object is in writing [[callback (computer science)|callback]] functions. A callback in [[procedural programming|procedural languages]], such as [[C (programming language)|C]], may be performed by using [[function pointer]]s.<ref>{{cite web | url = http://progtutorials.tripod.com/cpp1.htm#_Toc50820124 | title = C++ Tutorial Part I - Basic: 5.10 Function pointers are mainly used to achieve call back technique, which will be discussed right after. | author = Silan Liu | publisher = TRIPOD: Programming Tutorials Copyright © Silan Liu 2002 | quote = Function pointers are mainly used to achieve call back technique, which will be discussed right after. | access-date = 2012-09-07 }}</ref> However it can be difficult or awkward to pass a state into or out of the callback function. This restriction also inhibits more dynamic behavior of the function. A function object solves those problems since the function is really a [[facade pattern|façade]] for a full object, carrying its own state. Many modern (and some older) languages, e.g. [[C++]], [[Eiffel (programming language)|Eiffel]], [[Groovy (programming language)|Groovy]], [[Lisp (programming language)|Lisp]], [[Smalltalk]], [[Perl]], [[PHP]], [[Python (programming language)|Python]], [[Ruby (programming language)|Ruby]], [[Scala (programming language)|Scala]], and many others, support [[first-class function]] objects and may even make significant use of them.<ref>{{cite web | url = http://progtutorials.tripod.com/cpp1.htm#_Toc50820124 | title = C++ Tutorial Part I - Basic: 5.10 Function pointers are mainly used to achieve call back technique, which will be discussed right after. | author = Paweł Turlejski | date = 2009-10-02 | publisher = Just a Few Lines | quote = PHP 5.3, along with many other features, introduced closures. So now we can finally do all the cool stuff that Ruby / Groovy / Scala / any_modern_language guys can do, right? Well, we can, but we probably won’t… Here's why. | access-date = 2012-09-07 }}</ref> [[Functional programming]] languages additionally support [[closure (computer science)|closures]], i.e. first-class functions that can 'close over' variables in their surrounding environment at creation time. During compilation, a transformation known as [[lambda lifting]] converts the closures into function objects.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)