Talk:First-class functions: Difference between revisions

 
(17 intermediate revisions by 6 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 90 ⟶ 92:
== 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)
 
==<math> and <big> tags in REXX contribution still need attention==
 
: A combination of <math> and <big> 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 <math> 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