Talk:First-class functions: Difference between revisions

 
(36 intermediate revisions by 10 users not shown)
Line 16:
 
Yes, it's that last point that is crucial. In standard portable C, you can get a pointer to any function that was written in the original source code (of your program or a library), but there's no way to construct an arbitrary number of new functions.
 
: Sure it is. All you need is a compiler and support for dynamic linking. Well, that and some way of generating the text of the functions you are creating. --[[User:Rdm|Rdm]] 11:17, 3 May 2011 (UTC)
 
You could simulate it by having a table and a set of functions referring to entries in it; but you would have to deal with allocating this limited resource. For example:
Line 60 ⟶ 62:
==Don't merge with functional composition==
functional composition is only part of the task. The idea is to show how well a language supports first-class functions with a task that needs more of the traits that the WP article says characterizes first class functions. --[[User:Paddy3118|Paddy3118]] 10:03, 28 March 2009 (UTC)
 
==Autohotkey problem==
The Autohotkey entry is unfinished. Does what is there actually help? I don't know the language, so may be wrong about this second sentence. --[[User:Paddy3118|Paddy3118]] 06:48, 4 June 2009 (UTC)
: Please Clarify. What part is unfinished? Did you try running the example? Help what? --[[User:Tinku99|Tinku99]] 21:02, 4 June 2009 (UTC)
Hi Tinku, Autohotkey doesn't seem to create two lists: one of functions, the other of their matching inverses like the Javascript, Perl, Python, Ruby,... examples do? --[[User:Paddy3118|Paddy3118]] 21:22, 4 June 2009 (UTC)
:: ok, thanks. it does now. --[[User:Tinku99|Tinku99]] 17:49, 5 June 2009 (UTC)
So Autohotkey is parsing a string representation of the functions and eval-ing the result? If so then it gets the answer, but like C, wouldn't 'normally' be considered as having first class functions. --[[User:Paddy3118|Paddy3118]] 18:10, 5 June 2009 (UTC)
:: AutoHotkey doesn't really support eval natively either. I just made a generic "compose" function, called map. It is overloaded to create a composition, and then funcall those compositions. AutoHotkey internal data structures include functions are documented in [http://www.autohotkey.com/forum/topic26300.html LowLevel] and can be created and manipulated as any other data. I think to do this in C, you just have to manipulate its internal data structures, which is machine code. See [[wp:Self-modifying_code]], Dynamic Machine Code Generation in [http://code.google.com/apis/v8/design.html v8 javascript] and AutoHotkey machine code functions [http://www.autohotkey.com/forum/topic21172.html script] --[[User:Tinku99|Tinku99]] 18:48, 5 June 2009 (UTC)
==Task Name==
I think the name of this task should be modified to: <br>
'''Apply the compose of a function and its inverse to a list'''
<br>or<br>
'''operate on a function''': change its name, parameter count or something, to demonstrate you can dissect it like any first class data object.
Namely, apply the concept of [[wp:Duck_typing]] to a function object.
<br>
Currently, its more like, "prove that this language has this property..."<br> which is not as constructive IMO. Lets change it to more like: <br> "Do this!"--[[User:Tinku99|Tinku99]] 19:13, 5 June 2009 (UTC)
 
:The task was written to introduce the concept of a language having first class functions and then to write a task that would show if the language had first class functions. Changing a functions name or parameter count are not normally taken as signs of functions being first class in a language. I took 'classic' traits then tried to create a task that would need them, but it is the idea of treating functions as any other datatype that I wanted to convey.
:Most languages would allow you to take integers from two lists in pairs and apply the addition function on them. The task asks you to put, and then take functions from lists in a similar way and apply the compose function between them. <br>Duck typing is a separate topic and should not be confused with this. --[[User:Paddy3118|Paddy3118]] 23:10, 5 June 2009 (UTC)
 
==Ursala example has no compose function==
The Ursala example seems to have missed out the creation of a compose function in its example.--[[User:Paddy3118|Paddy3118]] 19:17, 24 June 2009 (UTC)
:"make that a list of functions by composing each pair". Maybe this craziness does it: <tt>(+)*p\</tt>. That snippet comes after the gang command. --[[User:Mwn3d|Mwn3d]] 19:19, 24 June 2009 (UTC)
:Nope, check out [[Functional Composition#Ursala]]. --[[User:Mwn3d|Mwn3d]] 19:41, 24 June 2009 (UTC)
 
I've added some commentary on functional composition. The <code>+</code> operator used here is the idiomatic way of expressing composition, whereas the definition in [[Functional Composition#Ursala]] is written the way it is to comply with that task specification. The cube function is user-created and the cube root function is a library function, since this task specification says to use one of each. What's the problem? -- [[User:Sluggo|Sluggo]]
: ''"What's the problem?"'' ... My lack of knowledge of Ursala :-)<br>--[[User:Paddy3118|Paddy3118]] 01:26, 7 August 2010 (UTC)
 
== just changed the Javascript example ==
 
Hello, I changed the Javascript example (http://rosettacode.org/mw/index.php?title=First-class_functions&diff=97198&oldid=97008 ) because I think the old one is totally bogus - no semicolons, no "function" keyword, local var "fn" unintentionally overrides the "fn" array; doesn't work anywhere I tried (Firefox and jsdb). Is this perhaps some dialect I don't know of? UPD hmmm, just found out that jsdb uses the same Javascript engine as Firefox, namely SpiderMonkey... but anyway, my point stands:)[[Special:Contributions/92.226.26.38|92.226.26.38]] 16:28, 12 December 2010 (UTC)
 
:Looking at the older version: it needed the keyword 'function' in front of the definitions for compose and test. Also, 'print' did not do anything useful there, and a different mechanism should have been used. And, you are right that the scope rules conflict with the two instances of 'fn'. However, semicolons are not necessary in javascript since the language requires that line-ends be allowed to terminate statements, so that part was ok. --[[User:Rdm|Rdm]] 19:16, 11 December 2010 (UTC)
::what mechanism? as to line ends, I didn't know. though, anyway, if the author intended to use them instead of semicolons, they wouldn't have written the first three lines the way they did (there would have to be line breaks after each "return whatever;" at least) [[Special:Contributions/92.226.26.38|92.226.26.38]] 16:45, 12 December 2010 (UTC)
::I'll keep them, I think it's much cleaner this way. And it seems omittting semicolons [http://codeidol.com/javascript/learning-javascript/Operators-and-Statements/Format-of-a-JavaScript-Statement/ isn't] practical except for but the simplest statements (like "x=3")[[Special:Contributions/92.226.26.38|92.226.26.38]] 16:52, 12 December 2010 (UTC)
:::By "mechanism" I meant display mechanism (I was talking about the use of 'print' -- that command apparently tries to send the current page to the printer). And I am not happy with the blanket assertion that omitting semicolons causes problems -- flat assertions, by themselves are not very useful. At the very least, that page should have included a reference to a deeper discussion of the issue (with examples). Personally, I have been using a javascript compressor that uses newlines to separate statements, and it is very rare that I have encountered a file which has problems (and there, since I never isolated the problem, I do not know if that was because of a problem with line termination or a bug in the compressor). Meanwhile, compressed javascript with line-end line separators is much easier to debug (when you get bugs in production) than compressed javascript with semicolon line separators. --[[User:Rdm|Rdm]] 00:33, 13 December 2010 (UTC)
 
==Do we have permission for the Prolog?==
I got a 404 error on the link, and I am presuming that it is not the original work of the poster, TrapD.
--[[User:Paddy3118|Paddy3118]] 07:37, 3 May 2011 (UTC)
: I searched then fixed the link. It now seems OK as I presume the code on RC belongs to TrapD who used the linked-to library - which is not on RC. --[[User:Paddy3118|Paddy3118]] 07:48, 3 May 2011 (UTC)
 
I have permission to use the module lambda.pl from U. Neumerkel (see discussion for Y Combinator).
For the link I fix it.--[[User:Trap D|Trap D]] 10:00, 3 May 2011
 
== The C hack: pointer ==
 
Normally I don't mind small semantics, but for the C hack code, naming it "pointer" is unnecessary at best, and possibly misleading. The reasons:
# In C, a function is just a block of machine instruction. When calling it, you take the address and push it onto stack; a function pointer is... the address of that block of instructions, which when called gets pushed onto the stack. There isn't much of a distinction here.
# The hack code doesn't return existing function pointers. The function body, a blob of machine code, really gets duplicated and stored somewhere, with some key stack variables modified according to the need, and that's why it's nasty and unportable. Calling the hack "function pointer" does not help understanding the situation. --[[User:Ledrug|Ledrug]] 05:25, 15 July 2011 (UTC)
 
:In many discussions on first-class functions the line seems to be drawn to ''exclude'' the [[wp:Talk:First-class function|C language]] capabilities as being too "low-level". Other languages gain merit for hiding the underlying mechanisms a bit more. I have tried to highlight what makes a first-class function in many minds is that functions are used as naturally as other types in the language by also creating the task [[First-class functions/Use numbers analogously]], but I realise that it is only an attempt. (Someone could use a numbers in a convoluted way just to match what ''needs'' to to be done for functions for example). --[[User:Paddy3118|Paddy3118]] 06:02, 15 July 2011 (UTC)
 
:: Of course functions are not first class in C, hence the code being not portable, I'm not disputing that. But what the code does isn't what one'd normally call a "function pointer" either, that's what the other C code did. If you cared enough to correct the heading, might as well use a ''correct'' heading. "Non-portable function body duplication" or some such would be much more accurate. --[[User:Ledrug|Ledrug]] 06:57, 15 July 2011 (UTC)
 
::: I've changed it. --[[User:Paddy3118|Paddy3118]] 09:03, 15 July 2011 (UTC)
:::: Thanks. --[[User:Ledrug|Ledrug]] 00:08, 16 July 2011 (UTC)
:::::With the widespread availability of [https://en.wikipedia.org/wiki/W%5EX W^X], this dirty hack is not going to work on (m)any platform. [[User:Eoraptor|Eoraptor]] ([[User talk:Eoraptor|talk]]) 23:54, 17 February 2019 (UTC)
 
==&lt;math&gt; and &lt;big&gt; tags in REXX contribution still need attention==
 
: A combination of &lt;math&gt; and &lt;big&gt; tags in the Rexx contribution, formerly causing invisibility in most browsers, is still triggering a MediaWiki processing error and a syntactically ill-formed piece of HTML at one point, though the removal of superfluous space from &lt;math&gt; tag contents has now restored basic visibility.
: Please test in a majority-type browser (one like Chrome, Safari, IE/Edge which displays a graphic file for formulae, rather than the minority type like Firefox, which uses MathML processing when requisitte fonts are installed), and tidy up the formatting tags immediately after the phrase '''"Tangent begins its period at"'''. [[User:Hout|Hout]] ([[User talk:Hout|talk]]) 17:57, 24 September 2016 (UTC)
 
:: Repaired today [[User:Hout|Hout]] ([[User talk:Hout|talk]]) 20:17, 13 November 2016 (UTC)
1,336

edits