[plt-scheme] Re: create a board with vector

From: Synx (plt at synx.us.to)
Date: Sun Dec 6 17:44:13 EST 2009

Mona wrote:

> build_vctor has 2 inputs, it seems one of the inputs is n and the
> other is (lamda (i) (f i j)). I cant understand what (lamda (i) (f i
> j))   will produce.

(lambda (i) (f i j)) will produce a procedure. When that procedure is
applied with a single argument, that procedure will then apply the
procedure 'f', with two arguments, the one passed, and whatever 'j' is
in the lexical scope.

So (define foo (lambda (i) (+ i 3)) will define foo to be a procedure,
such that nothing happens, but when you go (foo 2) it calls (+ 2 3) and
returns 5.

Similarly (define foo (let ((j 3)) (lambda (i) (+ i j)))) will do the
same thing. It defines foo to be a procedure, but while creating that
procedure it binds 'j' to the value 3 using the "let" syntax. The let
syntax just returns whatever's inside it, so it's just like (lambda (i)
(+ i 3)) except that inside the (let ...) lexical scope, j can be used
instead of 3.


Posted on the users mailing list.