5 ms·
Bill Clementson's Blog: JavaScript and Lisp
- TNO 17y agoUsing JavaScript 1.8 expression closures: function Y(X) (function(procedure) X(function(arg) procedure(procedure)(arg))) (function(procedure) X(function(arg) procedure(procedure)(arg)))
- jdeseno 17y agoNice but, anonymous recursion is possible with arguments.callee.
- benatkin 17y agoMore on arguments.callee: https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Functions_and_function_scope/arguments/callee https://developer.mozilla.org/En/Core_JavaScript_1.5_Referen...
- vlisivka 17y agoarguments.callee is deprecated in javascript 1.4. Use function name instead, so interpreter will have chance to perform tail recursion. Give names to your anonymous functions anyway: it will be much easier to trace them. Example of anonymous recursive function with arguments.callee: var factorial=function(n) { return (!(n>1))? 1 : arguments.callee(n-1)*n; } Example of anonymous recursive function without arguments.callee: var factorial=function factorial(n) { return (!(n>1))? 1 : factorial(n-1)*n; }
- andrewcooke 17y ago> will recognize that functions in JScript are fundamentally the Lambda Calculus i would have thought you could say that about functions in any language...
- mahmud 17y agoExcept languages where you can't pass functions as arguments or return them as results.
- swannodette 17y agoHorror! I didn't know such atrocities existed shudder ;)
- andrewcooke 17y agoyou're right. i should have said "first class functions" (which narrows the field somewhat).
- hypermatt 17y agoHelped me find a cool video from this Waldemar Horwat guy. http://www.youtube.com/watch?v=Kq4FpMe6cRs http://www.youtube.com/watch?v=Kq4FpMe6cRs
- owinebarger 17y agoTried Doug Crockford's little Javascripter: (define loop (lambda (x) (loop x))) (loop 1) Result in Firefox: "Too much recursion" I'm still surprised I didn't flunk B521 when Dan Friedman put something like this in my Java implementation of a Scheme interpreter and it blew up after some finite number of iterations. It might have worked if method calls were properly tail-recursive!
- vlisivka 17y agoJavaScript is implementation of Scheme (dialect of Lisp) with Java-like syntax.
- swannodette 17y agoOr as I like to say "JavaScript is Scheme in C drag".