+
1
|
list
|
skin
|
login
|
editor
α-wwwiki
::
function
user:none
(1887 bytes)
_h2 functions with :{br}{i define, defun, lambda, alpha} _p Defining a function in different languages, for instance the {b cubic function}. _h3 C {pre °° 1) float cubic = function (float x) { return x*x*x; }; 2) cubic(3) -> 27 °°} _h3 JavaScript {pre °° 1) function cubic (x) { return x*x*x; } 2) var cubic = function (x) { return x*x*x; }; // functions are datas 3) cubic(3) -> 27 4) using anonymous : (function(x) { return x*x*x; })(3); -> 27 °°} _h3 Lisp {pre °° 1) (define cubic (lambda (x) (* x x x))) // the basic way 2) (define cubic (x) (* x x x)) // sugar way 3) (cubic 3) -> 27 4) using lambda/anonymous : ((lambda (x) (* x x x)) 3) -> 27 °°} _h3 λ-talk {pre 1) using javascript expressions with the {u define operator} 11) defining : °°{define jscubic (x) return x*x*x; }°° // a Javascript expression > {define jscubic (x) return x*x*x; } 12) calling : °°{jscubic 12}°° > {jscubic 12} 2) using λ-talk expressions with the {u defun operator} (why not ?) 21) defining : °°{defun lspcubic (x) {* x x x} }°° // a λ-talk expression > {defun lspcubic (x) {* x x x} } 22) calling : °°{lspcubic 12}°° > {lspcubic 12} 3) using and calling the {u lambda operator} °°{{lambda (x) return x*x*x; } 12}°° // a Javascript expression > {{lambda (x) return x*x*x; } 12} 4) using and calling {u alpha operator} (why not ?) °°{{alpha (x) {* x x x} } 12}°° // a λ-talk expression > {{alpha (x) {* x x x} } 12} } _p {b Note} : The {b define, defun, lambda & alpha} operators are catched in a pre-process before the loop evaluation. So, contrary to the previous versions of {b λ-talk}, it is no more necessary to embed the bodies between couples of "{sup o}{sup o}" to delay the evaluation of the expressions containing parenthesis {b °°{}°°}.