Function object: Difference between revisions

Content deleted Content added
DonAByrd (talk | contribs)
m Distinguish this sense of the term from its meaning in _mathematics_; readers may not know what category theory is.
Rescuing 6 sources and tagging 0 as dead. #IABot (v1.5.5)
Line 599:
 
== In Ruby ==
In [[Ruby (programming language)|Ruby]], several objects can be considered function objects, in particular Method and Proc objects. Ruby also has two kinds of objects that can be thought of as semi-function objects: UnboundMethod and block. UnboundMethods must first be bound to an object (thus becoming a Method) before they can be used as a function object. Blocks can be called like function objects, but to be used in any other capacity as an object (e.g. passed as an argument) they must first be converted to a Proc. More recently, symbols (accessed via the literal unary indicator <code>:</code>) can also be converted to <code>Proc</code>s. Using Ruby's unary <code>&</code> operator&mdash;equivalent to calling <code>to_proc</code> on an object, and [[duck typing|assuming that method exists]]&mdash;the [[Ruby Extensions Project]] [https://web.archive.org/web/20060425104650/http://blogs.pragprog.com:80/cgi-bin/pragdave.cgi/Tech/Ruby/ToProc.rdoc created a simple hack.]
 
<source lang=Ruby>
Line 609:
</source>
 
Now, method <code>foo</code> can be a function object, i.e. a <code>Proc</code>, via <code>&:foo</code> and used via <code>takes_a_functor(&:foo)</code>. <code>Symbol.to_proc</code> was officially added to Ruby on June 11, 2006 during RubyKaiga2006. [https://web.archive.org/web/20060820025032/http://redhanded.hobix.com:80/cult/symbolTo_procExonerated.html]
 
Because of the variety of forms, the term Functor is not generally used in Ruby to mean a Function object.
Just a type of dispatch [[delegation (programming)|delegation]] introduced by the [https://web.archive.org/web/20070107205748/http://facets.rubyforge.org:80/ Ruby Facets] project is named as Functor. The most basic definition of which is:
 
<source lang=Ruby>
Line 656:
* [http://www.two-sdg.demon.co.uk/curbralan/papers/AsynchronousC++.pdf C++ Advanced Design Issues - Asynchronous C++] by [[Kevlin Henney]]
* [http://www.newty.de/fpt/index.html The Function Pointer Tutorials] by Lars Haendel (2000/2001)
* Article "[https://web.archive.org/web/20041009232434/http://www.cuj.com:80/documents/s=8464%3D8464/cujcexp0308sutter/ Generalized Function Pointers]" by [[Herb Sutter]]
* [http://jga.sourceforge.net/ Generic Algorithms for Java]
* [https://web.archive.org/web/20100330073950/http://www.amcgowan.ca:80/blog/computer-science/php-functors-function-objects-in-php/ PHP Functors - Function Objects in PHP]
* [https://web.archive.org/web/20041013202445/http://www.parashift.com:80/c++-faq-lite/pointers-to-members.html#faq-33.10 What the heck is a functionoid, and why would I use one?] (C++ FAQ)
 
{{DEFAULTSORT:Function Object}}