Let


Purpose

"Let" allows the programmer to define several variables, and initialize their values.

Usage

Let takes two arguments.

The first argument is a list of lists containing two elements. The first element is the name of a variable. The second element is the value of that variable.

The second argument "let" gets can be any expression. This expression is evaluated using the values of the newly created variables when appropriate.

Examples

Here are two ways of doing the same thing.

First the old way:

  ox --> (begin
           (define x 1)
           (define y 2)
           (+ x y)
          )
  3
Here's the same thing, using "let":
  ox --> (let (
               (x 1) 
               (y 2)
              ) 
            (+ x y)
           )
  3

Return to Scheme Introduction


mrl