racket - Scheme Lambda? What is it? -


what in scheme? how can use ?

scm> (define (x) 100) x scm> (x) 100 scm> x ; when "called" x, return (lambda () 100). ? (lambda () 100) 

(define (x) 100) same as:

(define x          ; define variable named x         (lambda () ; anoymous function 0 arguments           100))    ; returns 100  x   ; ==> #<function> (some representation of evaluated lambda object, there no standard way) (x) ; ==> 100 (the result of calling function) 

you might more in algol languages here same in javascript:

function x () { return 100; } same as:

var x =          // define variable named x   function () {  // anonymous function 0 arguments     return 100;  // returns 100   }; x;   // => function () { return 100; } (prints source) x(); // => 100 (the result of calling function) 

beginners add parentheses around variables ((x)) , equivalent writing x()() in algol languages. x must function of 0 arguments return function of 0 arguments in order work.


Comments