Introduction

I describe crass simplifications, which are not fully accurate, that I use to think about haughtier concepts, such as lambda calculus, free and bound variables.


Lambda Calculus

Lambda Calculus means "everything is an expression" (or, "everything is a function").


Example:

In Common Lisp and Scheme, every function is a function.  Every function  returns a value.


Counter-example:

In JavaScript, not everything is a function, for example


function fn (x, y) {

  42;

}


is different from


function fn (x, y) {

  return 42;

}


(One could say that the former is a procedure, not a function).


To make JavaScript work like Lisp, one would need to ensure that every function returns a 1st class value.  This can be done, but is boring to do, is error-prone, and results in unreadable (to humans) code.

Free Variables

A free variable can be thought of as being a global variable.

Bound Variables

A bound variable can be thought of as being


In fact, local variables are just syntactic sugar for nested lambdas, e.g.


function (x) {

  var y;

  y = 41;

  return x + y;

}


is really


function (x) {

  function (y) {

    return x + y;

  } (41);

}


Example Free and Bound Variables

function (x) {

  return x + y;

}


There are two variables in the above function, x and y.


Variable x is bound.


Variable y is free.  Variable y is unbound.



In the example below, both variables are bound, but y is uninitialized (undefined in JavaScript-speak).


function (x) {

  var y;

  return x + y;

}