Talk:First-class functions: Difference between revisions

Content added Content deleted
(→‎Closures?: new section)
(→‎Even C could?: ~4 answers with 1 shot)
Line 1: Line 1:
==Even C could?==
==Even C could?==
::Hi, please read the Wikipedia entry linked to, especially [[wp:First-class_function#Availability]] which specifically rules out C. I tried to make that point with my points about eval etc. --[[User:Paddy3118|Paddy3118]] 18:15, 24 February 2009 (UTC)
::Hi, please read the Wikipedia entry linked to, especially [[wp:First-class_function#Availability]] which specifically rules out C. I tried to make that point with my points about eval etc. --[[User:Paddy3118|Paddy3118]] 18:15, 24 February 2009 (UTC)
:::Maybe I am dumb or my english's weak, but it seems to me that [[wp:First-class_function#Availability]] does not rule out C, it only says that it is ''impractical'' (hard? slow? hardware-dependent?) to make the whole thing working in plain C... Anyway don't worry, my doubts were not about the way the task is specified, but about the way the task can be accomplished even in a language like C! :D And I am also very blind about too much abstraction and disagree with ''it is not possible to create new functions at runtime'' from [[wp:First-class_object]]; a stupid proof: I can write a python interpreter in C... (it all depends on what ''definitions'' make possible) --[[User:ShinTakezou|ShinTakezou]] 21:33, 24 February 2009 (UTC)


::[[wp:First-class_object]] makes good reading too. --[[User:Paddy3118|Paddy3118]] 18:44, 24 February 2009 (UTC)
::[[wp:First-class_object]] makes good reading too. --[[User:Paddy3118|Paddy3118]] 18:44, 24 February 2009 (UTC)
Line 37: Line 38:
But this technique will only work for a fixed number of functions -- it is basically emulating closures by having a predefined table of closure entry points and data storage.
But this technique will only work for a fixed number of functions -- it is basically emulating closures by having a predefined table of closure entry points and data storage.
--[[User:Kevin Reid|Kevin Reid]] 17:54, 24 February 2009 (UTC)
--[[User:Kevin Reid|Kevin Reid]] 17:54, 24 February 2009 (UTC)
:: My bet was that writing codes, one can "simulate" it without the limit of fixed number of functions... but I am still thinking about it... --[[User:ShinTakezou|ShinTakezou]] 21:33, 24 February 2009 (UTC)


:No, pointer to a function is only a first-class pointer. Its "first-classness" alone does not make first-class the thing it points to. The rest of your argumentation is about Turing completeness. Yes, you can create an object that will act similar to a function. A pointer to function is a simplest example of. But this would not make that object a function in language terms.
:No, pointer to a function is only a first-class pointer. Its "first-classness" alone does not make first-class the thing it points to. The rest of your argumentation is about Turing completeness. Yes, you can create an object that will act similar to a function. A pointer to function is a simplest example of. But this would not make that object a function in language terms.


:Some notes to the list. The list rather refers to operations on functional types. Neither of is actually required to make functions first-class. What is required is that a function were a type and there existed objects of this type, with '''some''' operations defined on this type. Whether these operations include any concrete operation beyond "call me," is up to the language. Only "call me" is essential (that makes the object a function). Granted, almost certainly a reasonable implementation will provide operations from the list. --[[User:Dmitry-kazakov|Dmitry-kazakov]] 17:57, 24 February 2009 (UTC)
:Some notes to the list. The list rather refers to operations on functional types. Neither of is actually required to make functions first-class. What is required is that a function were a type and there existed objects of this type, with '''some''' operations defined on this type. Whether these operations include any concrete operation beyond "call me," is up to the language. Only "call me" is essential (that makes the object a function). Granted, almost certainly a reasonable implementation will provide operations from the list. --[[User:Dmitry-kazakov|Dmitry-kazakov]] 17:57, 24 February 2009 (UTC)
::: Chance there are that many languages at the end manipulate pointers to code; but this is hidden. In C, it is not so hidden, but I can feel it like a syntax oddness: a function ''is'' ''de facto'' a pointer to a function ---or the first-class implies also an uniform syntax to manipulate/use/refer to objects? If it is so, Python (and many more, and likely all!) could be out because e.g. <tt>sin</tt> means ''the function sin'', but to "use" it I need the syntax <tt>sin(x)</tt>... Compilers/interpreters of languages that have first-class functions, must implement it someway, e.g. having something like a hash-table that "links" between names and pointers to ''object'' (which could be directly code or more complex data structure, depending on the context the language need to make its thing works)... So again the question: first-class functions is not about what you can do with the language, but about the syntax and what is ''already'' implemented? --[[User:ShinTakezou|ShinTakezou]] 21:33, 24 February 2009 (UTC)


::Thanks Dmitry. That is a valid point. I guess if a language has problems with the example but can reason, (making a better case than C), why it has first class functions, then they should make their case too. Maybe they could cover the four points by other means. --[[User:Paddy3118|Paddy3118]] 18:25, 24 February 2009 (UTC)
::Thanks Dmitry. That is a valid point. I guess if a language has problems with the example but can reason, (making a better case than C), why it has first class functions, then they should make their case too. Maybe they could cover the four points by other means. --[[User:Paddy3118|Paddy3118]] 18:25, 24 February 2009 (UTC)
::: I will try to think about how it can be done... but of course I would stop before implementing a full too-complex too-long runtime or a VM :D --[[User:ShinTakezou|ShinTakezou]] 21:33, 24 February 2009 (UTC)


== Closures? ==
== Closures? ==