Talk:Function object

Comment
The Generator link (on the Python section) references to "Electric Generator", may be there must be a dissambiguate page.

Isn't the CL section a little ... fanboyish? Don't get me wrong, I love closures as much as the next FP freak, but saying they are the 'true' form of function objects seems a little absurd. 202.180.83.6 05:29, 15 December 2005 (UTC)

C++ section too verbose?
I think the subsection on C++ functors is getting a bit out of hand. It is becoming much less like an encyclopedia article and more like a text book (a confusing one at that). Also the latest changes made on 22 Jan 2005 are written in a rather informal grammatical style and need some editing.

May I suggest that either the C/C++ section be trimmed back, or a different article be created specifically to discuss all the detailed nuances and advanced techniques of C++ functors and leave this article to just give the flavor as a comparison to a few other major languages. -- Dmeranda 04:32, 28 Jan 2005 (UTC)


 * I was the one who added the CFunctor C++ stuff. I will agree that it does not flow as well as the rest of the article. I want to also post it on freedevs.net, we are trying to create some tutorials.
 * If you guys want to change it or delete it that is fine with me. A different article would be nice, but I do not know what it should be called. -- Trailcode


 * I'm not exactly a Wikipedia expert, but I think in keeping with the Wikipedia goals, information about the subject should be kept here, but perhaps more tutorial-like information is best left someplace else. Perhaps if your tutorial site is better, you can link to it (assuming the content is free and not likely to be seen as spamming Wikipedia).  You might walso want to check out Wikibooks (http://wikibooks.org/) and see if there's a place for content there.
 * However I'm sure some of your new content is useful and valuable and should not be lost. And since C++ tends to have rather complex and many varied forms of functors (moreso than most languages), it warrants having it's own advanced-usage page so as not to overwhelm this article.  Maybe a page named Functors in C Plus Plus?  (see also Naming conventions (technical_restrictions))- Dmeranda 17:53, 31 Jan 2005 (UTC)


 * I posted that CFunctors tutorial at www.freedevs.net and got some constructive criticism. I removed the stuff I added but it is still on the net. When I have time I will make it better. In the previous functors tutorial there is something like "other functors", I will put a link there when it is done. -- Trailcode

I would like to suggest the following C++ code : void sort_ints(int* begin_items, int num_items, ComparisonFunctor& c) { ... }; This has two changes: the { ... } suggest that this function needs to be implemented by the user ( otherwise a linker error occurs ). Furthermore, the functor can be passed by reference, so as to minimize overhead. If large functors are passed by value, the whole function object gets copied to the stack, which can, for large functors, be an expensive operation. Passing by reference avoids this. —The preceding unsigned comment was added by 143.129.78.43 (talk • contribs).


 * As far as {...}, I think a brief comment would be better. And as for pass-by-reference, I think it is best to not show that here.  It really doesn't help explain the concept of functor any better, and in an article we should strive for clarity of ideas first, not code optimization. - Dmeranda 20:08, 30 March 2007 (UTC)

Merger?
The proposed merger with Closure (Computer Science) is absurd and insulting. Wouter Lievens 10:17, 8 Jun 2005 (UTC)


 * We are having a discussion of this at Talk:Closure (computer science). -- Taku 11:43, Jun 8, 2005 (UTC)


 * Allright, sorry :-) Wouter Lievens 12:36, 8 Jun 2005 (UTC)


 * No, no, I just wanted to consolidate the discussion. -- Taku 22:58, Jun 8, 2005 (UTC)


 * OK, so as per the discussion you two had on the other page and the Wouter's persuasive arguments, can we remove the merger tag here?--Hooperbloob 06:36, 25 July 2005 (UTC)


 * Sorry I forgot to remove the tag. -- Taku 23:23, July 25, 2005 (UTC)


 * To me (not a C++ programmer) what this article discusses is a function pointer, function reference, delegate (in .NET), and in one place, an anonymous function; they are not an innovation from the Smalltalk days, Algol 68 had them, too.  Who calls this concept "functor" or "function object"?  Whence the duplication of information from, e.g. first-class function. ? Rp (talk) 19:39, 22 March 2009 (UTC)

Python generators
The mention of Python generators as being a special case of a functor does deserve mention here, and so I'm reverting the deletion of material made by User:Eurleif Agreed, he is correct in that it is just a functor, but in this language it does have special prominance. There is in fact an entire article about it here (see Generator_(computer_science)), as well as specific language syntax and support (see [PEP 255]), including the name "Generator" itself. So I see no reason to remove this mention of generators. It is not incorrect, and it's a small amount of text. If you feel the text is somehow not worthy of this article, perhaps you'd instead like to add some additional description instead. [BTW, if you are removing entire paragraphs in the future, please don't mark your edit as being minor—thanks.] Dmeranda 17:49, 22 August 2005 (UTC)


 * Hey, I deleted it again, before reading this discussion. Sorry.  I deleted it because I don't see it as relevant.  Generators are not really related to  .  The purpose of this article isn't to list all the Python objects that can be used with function-call syntax (types, slot wrappers, bound methods...). Jorend 20:17, 10 January 2006 (UTC)

Functor out of favor
At least in the C++ community, the word "functor" has fallen out of favor somewhat because of the clash with the distinct meaning from mathematics. I think this article should use "function object" as a rule and only mention "functor." "Function object" is, after all, the title of the entry


 * I second that motion. Dcosborn (talk) 19:38, 13 December 2007 (UTC)


 * It is a function. I think there is a problem with calling it a Function object since "object" adds and implies nothing except that it is assumed the function is modelled in an object system such as an object oriented language. First class functions need not be objects as in functional programming languages where functions are a primary unit of synthesis and where most of the techniques for using them originated. —Preceding unsigned comment added by 59.167.164.33 (talk) 05:42, 20 July 2010 (UTC)


 * There is another problem, which is that the term "functor" is used in the article before explaining what it means in this context. I suppose the reader is just supposed to infer that it's an alternative name for "function object"... Crunch483 (talk) 13:59, 23 December 2015 (UTC)

Numbers in Python
>>> dir(1) ['__abs__', '__add__', '__and__', '__class__', '__cmp__', '__coerce__', (...)] >>> (1).__add__(3) 4 >>> isinstance(1, object) True >>> issubclass(int, object) True

Enough said. --Sam Pointon 17:05, 6 June 2006 (UTC)

Nothing special about Java example?
public class Functors { public static void main(String []args) { Predicate p = new EqualPredicate ("wikipedia"); if (p.evaluate (args[0])) System.err.println ("true; " +args[0]+ " is 'wikipedia'."); else System.err.println ("false;" +args[0]+ " is not."); } }

I don't see anything special about this example other than usage of a constructor and regular method calling. So where is the function object thingy in it? --Abdull 18:45, 17 April 2007 (UTC)


 * Agreed, this example is just showing simple polymorphism. Functor API's in Java seem to be a solution in search of a problem.
 * "When in Rome, do as the Romans"--meaning when coding in Java solve problems the Java way. The example either needs to show a problem that is better solved using a functor API or be removed. --Firefight (talk) 18:19, 5 December 2007 (UTC)


 * I've deleted the old example and replaced it with a new example using the Comparator interface to sort a list (much like the C/C++ example). I feel like it's a better example of how functors are typically used in Java. --Dlugar (talk) 00:45, 14 February 2008 (UTC)

In the introduction, it reads: Most modern object-oriented languages e.g. C++, Java, PHP, Python, Ruby and Lisp support the definition of function objects and may even make significant use of them. I think the above example as well as the one in the article shows clearly that Java does not offer first order function objects, and not even second order like in C++ (second order meaning that they are distinct from real functions, but syntactially exchangable). The use of interfaces is only a weak surrogate for function objects. Therefor, I think Java should be removed from that list. Maybe this applies to other languages, too, but most of them I don't know good enough to jugde on my own. A better solution might be: Other languages, such as Java (insert others here) don't offer real function objects, but allow constructs that can be used in patterns commomly applied to funtion objects. --Prauch (talk) 13:19, 23 March 2010 (UTC)

Functors and Higher-Order Functions
What is the relationship between functors and higher-order functions? I think it would be interesting if the article made this clear. --Antonielly (talk) 16:11, 12 October 2008 (UTC)

struct instantiate or call
is this struct instantiated or called here? speaking of function objects, this example should be more straightforward. sortInts(items, sizeof(items)/sizeof(items[0]), compareClass); — Preceding unsigned comment added by 195.228.189.97 (talk) 16:31, 7 September 2012 (UTC)

External links modified
Hello fellow Wikipedians,

I have just modified 6 external links on Function object. Please take a moment to review my edit. If you have any questions, or need the bot to ignore the links, or the page altogether, please visit this simple FaQ for additional information. I made the following changes:
 * Added archive https://web.archive.org/web/20060425104650/http://blogs.pragprog.com:80/cgi-bin/pragdave.cgi/Tech/Ruby/ToProc.rdoc to http://blogs.pragprog.com/cgi-bin/pragdave.cgi/Tech/Ruby/ToProc.rdoc
 * Added archive https://web.archive.org/web/20060820025032/http://redhanded.hobix.com:80/cult/symbolTo_procExonerated.html to http://redhanded.hobix.com/cult/symbolTo_procExonerated.html
 * Added archive https://web.archive.org/web/20070107205748/http://facets.rubyforge.org:80/ to http://facets.rubyforge.org
 * Added archive https://web.archive.org/web/20041009232434/http://www.cuj.com:80/documents/s=8464/cujcexp0308sutter/ to http://cuj.com/documents/s=8464/cujcexp0308sutter/
 * Added archive https://web.archive.org/web/20100330073950/http://www.amcgowan.ca:80/blog/computer-science/php-functors-function-objects-in-php/ to http://www.amcgowan.ca/blog/computer-science/php-functors-function-objects-in-php/
 * Added archive https://web.archive.org/web/20041013202445/http://www.parashift.com:80/c++-faq-lite/pointers-to-members.html to http://parashift.com/c%2B%2B-faq-lite/pointers-to-members.html#faq-33.10

When you have finished reviewing my changes, you may follow the instructions on the template below to fix any issues with the URLs.

Cheers.— InternetArchiveBot  (Report bug) 08:25, 6 January 2017 (UTC)